Skip to content
New issue

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

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

Already on GitHub? # to your account

Compilation fails with "overflow evaluating the requirement" when an unrelated impl for a reference is present #83181

Open
koute opened this issue Mar 16, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. 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

@koute
Copy link
Member

koute commented Mar 16, 2021

Consider the following code:

struct Wrapper<T>(T);
impl<'a, T> IntoIterator for &'a Wrapper<T> where &'a T: IntoIterator {
    type Item = <&'a T as IntoIterator>::Item;
    type IntoIter = <&'a T as IntoIterator>::IntoIter;
    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}

pub fn foobar<'a, T>(it: &'a T) where &'a T: IntoIterator, T: 'a {}

fn main() {
    foobar(&vec![0_u8]);
}

Playground

Trying to compile it results in the following error:

error[E0275]: overflow evaluating the requirement `&_: IntoIterator`
  --> src/main.rs:13:5
   |
10 | pub fn foobar<'a, T>(it: &'a T) where &'a T: IntoIterator, T: 'a {}
   |                                              ------------ required by this bound in `foobar`
...
13 |     foobar(&vec![0_u8]);
   |     ^^^^^^
   |
   = help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`playground`)
   = note: required because of the requirements on the impl of `IntoIterator` for `&Wrapper<_>`
   = note: 127 redundant requirements hidden
   = note: required because of the requirements on the impl of `IntoIterator` for `&Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<_>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`

If you comment out the IntoIterator impl or the call to foobar then it compiles successfully.

Might be related to #80542, #78982 and possibly others.

Meta

Affected versions:

  • 1.52.0-nightly (2021-03-14 d6eaea1)
  • 1.50.0-stable
  • 1.0.0-stable
@koute koute added the C-bug Category: This is a bug. label Mar 16, 2021
@estebank
Copy link
Contributor

You can change the code to either not include the borrow in the trait bound or change foobar to not take a borrow.

The bug is valid as a bad diagnostic.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Mar 17, 2021
@fmease fmease added fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. A-trait-system Area: Trait system labels Dec 28, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-bug Category: This is a bug. D-confusing Diagnostics: Confusing error or lint that should be reworked. 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

3 participants