Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler hangs; doesn't detect "overflow evaluating the requirement" in case of dyn closure #113359

Open
JanBeh opened this issue Jul 5, 2023 · 1 comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@JanBeh
Copy link
Contributor

JanBeh commented Jul 5, 2023

Problem

I tried this code:

pub trait Trait1<T> {
    type Assoc;
}

impl<T, U> Trait1<U> for T {
    type Assoc = U;
}

pub type Alias<A, B> =
    &'static dyn FnMut(A) -> B; // hangs
    //&'static fn(A) -> B; // gives error

pub trait Trait2<T> {}

impl<T, U> Trait2<U> for T
where
    T: Trait1<Alias<T, U>>,
    <T as Trait1<Alias<T, U>>>::Assoc: Trait2<U>,
{
}

(Playground)

I expect to get some sort of error at least, but instead the compiler hangs.

If I use &'static fn(A) -> B instead of &'static dyn FnMut(A) -> B, an error will be reported instead:

error[E0275]: overflow evaluating the requirement `&'static fn(&'static fn(&'static fn(&'static ...) -> ...) -> ...) -> ...: Trait1<...>`
  --> src/main.rs:18:40
   |
18 |     <T as Trait1<Alias<T, U>>>::Assoc: Trait2<U>,
   |                                        ^^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`hang`)
note: required for `&fn(&fn(&fn(&...) -> ...) -> ...) -> ...` to implement `Trait2<U>`
  --> src/main.rs:15:12
   |
15 | impl<T, U> Trait2<U> for T
   |            ^^^^^^^^^     ^
16 | where
17 |     T: Trait1<Alias<T, U>>,
   |        ------------------- unsatisfied trait bound introduced here
   = note: the full type name has been written to '/usr/home/jbe/rust-experiment/hang/target/debug/deps/hang-26babc5805012eba.long-type-4138312560499222288.txt'
   = note: 126 redundant requirements hidden
   = note: required for `<T as Trait1<&'static fn(T) -> U>>::Assoc` to implement `Trait2<U>`

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

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (f20afcc45 2023-07-04)
binary: rustc
commit-hash: f20afcc455bbcc5c0f7679450fb35fd0c9668880
commit-date: 2023-07-04
host: x86_64-unknown-freebsd
release: 1.72.0-nightly
LLVM version: 16.0.5

Possibly related

@JanBeh JanBeh added the C-bug Category: This is a bug. label Jul 5, 2023
@Noratrieb Noratrieb added A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. and removed needs-triage-legacy labels Jul 17, 2023
@teofr
Copy link

teofr commented Dec 9, 2024

Been playing around a little bit with this, and it seems that it's not a cycle detection problem or anything like that, rather a slower grow rate of the stack. Decreasing the recursion limit fixes the issue, still worth a look.
Also simplified the example a bit:

// #![recursion_limit = "8"]

pub trait Trait2<T> {}

impl<T, U> Trait2<U> for T
where
    &'static dyn FnOnce(T) -> U: Trait2<U>,
    // &'static fn(T) -> U: Trait2<U>,
{
}

Playground

@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants