Confusing error message on using `step_by` and `take` on infinite iterator
Open
Nobody has claimed this yet.
A-diagnostics
A-trait-system
C-bug
D-confusing
D-verbose
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
I expected to see this happen:
Error message saying Range<Integer> is not ExactSizedIterator
Instead, this happened:
Current error message:
Compiling playground v0.0.1 (/playground)
error[E0599]: the method `len` exists for struct `StepBy<Take<RangeFrom<{integer}>>>`, but its trait bounds were not satisfied
--> src/main.rs:5:44
|
5 | println!("{}",(0..).take(2).step_by(2).len());
| ^^^ method cannot be called on `StepBy<Take<RangeFrom<{integer}>>>` due to unsatisfied trait bounds
|
::: /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/take.rs:19:1
|
19 | pub struct Take<I> {
| ------------------ doesn't satisfy `_: ExactSizeIterator`
|
::: /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/step_by.rs:18:1
|
18 | pub struct StepBy<I> {
| -------------------- doesn't satisfy `_: ExactSizeIterator`
|
= note: the following trait bounds were not satisfied:
`std::iter::Take<RangeFrom<{integer}>>: ExactSizeIterator`
which is required by `StepBy<std::iter::Take<RangeFrom<{integer}>>>: ExactSizeIterator`
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Meta
rustc --version --verbose:
Rust Playground (latest stable Rust release: v 1.77.1)
N/A
<backtrace>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Rust Playground example and examining the E0599 diagnostic for (0..).take(2).step_by(2).len(). Determine where the compiler formats the unsatisfied ExactSizeIterator bounds; done means the error clearly communicates the relevant iterator constraint and the behavior is covered by an appropriate compiler test.
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
- Needs clarification
- Newbie friendliness
- 35/100