Skip to content

Overflow evaluating the requirement when using GATs #112097

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

Open
momvart opened this issue May 30, 2023 · 2 comments
Open

Overflow evaluating the requirement when using GATs #112097

momvart opened this issue May 30, 2023 · 2 comments
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@momvart
Copy link
Contributor

momvart commented May 30, 2023

While #39959 and #111313 are discussing the same issue, in this case, it looks like there's a problem with GATs (generic associated types) or probably HRTBs (higher-rank trait bounds). Try removing the generic lifetime 'a and the problem will be solved.

Code

trait Foo {
    type A<'a>;
}

trait Alias
where
    for<'a> Self: Foo<A<'a> = <Self as Alias>::AliasA<'a>>,
{
    type AliasA<'a>: From<u8>;
}

impl<T> Alias for T
where
    T: Foo,
    for<'a> <T as Foo>::A<'a>: From<u8>,
{
    type AliasA<'a> = <T as Foo>::A<'a>;
}

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (e77366b57 2023-05-16)
binary: rustc
commit-hash: e77366b57b799dfa3ce1fcb850c068723a3213ee
commit-date: 2023-05-16
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Error output

error[E0275]: overflow evaluating the requirement `Self: Alias`
  --> examples/generic_error2.rs:5:1
   |
5  | trait Alias
   | ^^^^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`generic_error2`)
note: required for `Self` to implement `Alias`
  --> examples/generic_error2.rs:12:9
   |
12 | impl<T> Alias for T
   |         ^^^^^     ^
...
15 |     for<'a> <T as Foo>::A<'a>: From<u8>,
   |                                -------- unsatisfied trait bound introduced here
   = note: 63 redundant requirements hidden
   = note: required for `Self` to implement `Alias`
@momvart momvart added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 30, 2023
@fmease
Copy link
Member

fmease commented May 30, 2023

@rustbot label -I-ICE

@rustbot rustbot removed the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 30, 2023
@npuichigo
Copy link

npuichigo commented Jul 19, 2023

When built with rustc +nightly -Ztrait-solver=next, the error becomes

error[E0271]: type mismatch resolving `<T as Foo>::A<'a> == <T as Alias>::AliasA<'a>`
  --> main.rs:17:23
   |
17 |     type AliasA<'a> = <T as Foo>::A<'a>;
   |                       ^^^^^^^^^^^^^^^^^ types differ
   |
note: required by a bound in `Alias`
  --> main.rs:7:23
   |
5  | trait Alias
   |       ----- required by a bound in this trait
6  | where
7  |     for<'a> Self: Foo<A<'a> = <Self as Alias>::AliasA<'a>>,
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Alias`

error: aborting due to previous error

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

@Enselic Enselic added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Jul 29, 2024
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-GATs Area: Generic associated types (GATs) C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants