rust-lang / rust-lang/rust

Overflow evaluating the requirement due to unrelated impl IntoIterator

Open
#136,856 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug fixed-by-next-solver T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

fn foo<'a, I: ?Sized>(_: &'a I)
where
    &'a I: IntoIterator<Item = &'a ()>,
{
}

pub fn bar() {
    foo(&[]);
}

pub struct StringInterner<B>(B);

impl<'a, B> IntoIterator for &'a StringInterner<B>
where
    &'a B: IntoIterator<Item = &'a ()>,
{
    type Item = <&'a B as IntoIterator>::Item;
    type IntoIter = <&'a B as IntoIterator>::IntoIter;

    fn into_iter(self) -> Self::IntoIter {
        todo!()
    }
}

I expected to see this happen: it compiles.

Instead, this happened:

error[E0275]: overflow evaluating the requirement `&_: IntoIterator`
  --> src/lib.rs:8:5
   |
8  |     foo(&[]);
   |     ^^^^^^^^
   |
   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`playground`)
note: required for `&StringInterner<_>` to implement `IntoIterator`
  --> src/lib.rs:13:13
   |
13 | impl<'a, B> IntoIterator for &'a StringInterner<B>
   |             ^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^^^
14 | where
15 |     &'a B: IntoIterator<Item = &'a ()>,
   |                         ------------- unsatisfied trait bound introduced here
   = note: 126 redundant requirements hidden
   = note: required for `&StringInterner<StringInterner<StringInterner<StringInterner<...>>>>` to implement `IntoIterator`
note: required by a bound in `foo`
  --> src/lib.rs:3:12
   |
1  | fn foo<'a, I: ?Sized>(_: &'a I)
   |    --- required by a bound in this function
2  | where
3  |     &'a I: IntoIterator<Item = &'a ()>,
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
   = note: the full name for the type has been written to '/playground/target/debug/deps/playground-13c85e6c72950c6d.long-type-17257908183752834728.txt'
   = note: consider using `--verbose` to print the full type name to the console

Interestingly, it compiles fine if foo(&[]) is changed to foo::<[_]>(&[]) or if the impl for StringInterner is removed.

Originally found in https://github.com/wasmi-labs/wasmi/issues/1366.

Meta

rustc --version --verbose:

1.86.0-nightly

(2025-02-10 6171d944aea415a3023d)

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 reproducer in src/lib.rs using the reported nightly compiler, then compare the failing call with the explicit type-argument version and with the impl removed. The fix is complete when the original example no longer overflows while retaining the relevant IntoIterator behavior.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.