Skip to content

Compiler hang with recursive trait requirement and default impl #117909

Open
@jruderman

Description

@jruderman

Found by mutating tests/ui/traits/issue-18400.rs with my variant of fuzz-rustc

Code

#![allow(incomplete_features)]
#![feature(specialization)]

trait Set<T> {
    fn contains(&self, bit: T);
}

default impl<T, S> Set<&T> for S where
    S: Set<T>,
{
    fn contains(&self, _: &T) {}
}

fn main() {
    0.contains(());
}

Error output

With the default recursion limit (128), rustc effectively hangs without showing any output.

With #![recursion_limit = "8"], it exits with E0275:

error[E0275]: overflow evaluating the requirement `{integer}: Set<&&&&&&&&&_>`
  --> d2.rs:16:7
   |
16 |     0.contains(());
   |       ^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "16"]` attribute to your crate (`d2`)
note: required for `{integer}` to implement `Set<&&&&&&&&&_>`
  --> d2.rs:9:20
   |
9  | default impl<T, S> Set<&T> for S where
   |                    ^^^^^^^     ^
   = note: 8 redundant requirements hidden
   = note: required for `{integer}` to implement `Set<&&&&&&&&&_>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.

Where it's slow

-Z time-passes: type_check_crate

Sample head: trait selection and obligations

Not a recent regression

It's slow to the point of hanging at least as far back as nightly 2021-01-01

Version

rustc 1.76.0-nightly (ba7c7a301 2023-11-13)
binary: rustc
commit-hash: ba7c7a301984967c8c13adb580ef9b86ba706a83
commit-date: 2023-11-13
host: x86_64-apple-darwin
release: 1.76.0-nightly
LLVM version: 17.0.4

@rustbot label +I-compiletime +A-specialization +F-specialization +T-compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions