rust-lang / rust-lang/rust

Compiler stack overflow when calling function on generic struct with TAIT resolving to lambda

Open
#136,390 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-type_alias_impl_trait I-crash S-has-bisection S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(type_alias_impl_trait)]

type X = impl FnOnce();

struct S<F>(F);

impl S<X> {
    fn new() -> Self {
        Self(|| {})
    }
}

fn main() {
    S::new();
}

I expected to see this happen: Compilation succeeds.

Instead, this happened: Compiler crashes with a stack overflow, although only in debug mode.

I ran this through cargo bisect-rustc and got the following:

Regression in https://github.com/rust-lang-ci/rust/commit/89bc42c8a857f495c042840ebe189480d70e3b24
The PR introducing the regression in this rollup is #134081: Try to evaluate constants in legacy mangling

searched nightlies: from nightly-2024-10-11 to nightly-2025-02-01
regressed nightly: nightly-2024-12-15
searched commit range: https://github.com/rust-lang/rust/compare/327c7ee4367ea587a49eff1d4715f462ab6db5f0...0aeaa5eb22180fdf12a8489e63c4daa18da6f236
regressed commit: https://github.com/rust-lang/rust/commit/f1ec5d64b301462323d7e1782551687cd3a351d0

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2024-10-11 

I am guessing that the TAIT being in the symbol path of new messes something up with creating the mangled symbol name.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (854f22563 2025-01-31)
binary: rustc
commit-hash: 854f22563c8daf92709fae18ee6aed52953835cd
commit-date: 2025-01-31
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
Backtrace

/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x37a6cc3) [0x705d645a6cc3]
/usr/lib/libc.so.6(+0x3d1d0) [0x705d60c4c1d0]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5521865) [0x705d66321865]

### cycle encountered after 3 frames with period 5
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5520108) [0x705d66320108]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x55228a1) [0x705d663228a1]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5521a2b) [0x705d66321a2b]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5521a2b) [0x705d66321a2b]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5522183) [0x705d66322183]
### recursed 50 times

/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5520108) [0x705d66320108]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x55228a1) [0x705d663228a1]
/home/elekrisk/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-8cb71fa651fbc0f4.so(+0x5521a2b) [0x705d66321a2b]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided generic-struct and TAIT reproducer, then use the reported cargo bisect-rustc range and regression in PR #134081 to investigate the compiler path involved. Compare debug and non-debug compilation and inspect the reported legacy mangling regression. Done means the reproducer compiles successfully without a stack overflow, with coverage for the regression.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.