Skip to content

Add code suggestion for RangeTo is not an iterator #147749

@camsteffen

Description

@camsteffen

Code

fn main() {
    for x in (..4).rev() {
        todo!();
    }
}

Current output

error[E0599]: `RangeTo<{integer}>` is not an iterator
   --> src/main.rs:2:20
    |
  2 |     for x in (..4).rev() {
    |                    ^^^ `RangeTo<{integer}>` is not an iterator
    |
   ::: /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/range.rs:271:1
    |
271 | pub struct RangeTo<Idx> {
    | ----------------------- doesn't satisfy `RangeTo<{integer}>: Iterator`
    |
    = note: the following trait bounds were not satisfied:
            `RangeTo<{integer}>: Iterator`
            which is required by `&mut RangeTo<{integer}>: Iterator`
    = note: you might have meant to use a bounded `Range`

Desired output

did you mean?

    for x in (0..4).rev() {

Rationale and extra context

The note "you might have meant to use a bounded Range" is decent but a code suggestion would be better.

Other cases

Also the error is not very helpful for (..4).iter().rev().

Rust Version

1.90.0

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions