rust-lang / rust-lang/rust

Overflowing evaluation in a simple trait

Open
#119,370 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system A-type-system C-bug S-has-mcve T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I think it could be related to #113818

Code
use core::ops::Range;

pub trait MyTrait {
    type Iter<'a>: Iterator
    where
        <<Self as MyTrait>::Iter<'a> as Iterator>::Item: Clone,
        Self: 'a;
}

pub struct MyStruct;

impl MyTrait for MyStruct {
    type Iter<'a> = Range<usize>;
}

Playground link

Meta

The error is the same in rust 1.73, 1.74, nightly, and beta.

Error output
Compiling playground v0.0.1 (/playground)
error[E0275]: overflow evaluating the requirement `<MyStruct as MyTrait>::Iter<'a> == _`
  --> src/lib.rs:12:21
   |
12 |     type Iter<'a> = Range<usize>;
   |                     ^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0275`.
error: could not compile `playground` (lib) due to previous error

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 reproduction in src/lib.rs or the linked Rust Playground, and compare the stable, beta, and nightly behavior described in the issue. Read the E0275 explanation and investigate why evaluating the associated iterator requirement overflows; done should be behavior that handles this valid-looking trait implementation without the reported overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.