Skip to content

Suggest using ranges in loops on primitive types, instead of calling .iter() #34353

Closed
@alexandermerritt

Description

@alexandermerritt

The following code results in output that isn't specifically helpful:

fn main() {
    let max: usize = 10;
    for m in max { ; }
}

Compiler output:

error: the trait bound `usize: std::iter::Iterator` is not satisfied [--explain E0277]
 --> <anon>:3:5
3 |>     for m in max {
  |>     ^
note: `usize` is not an iterator; maybe try calling `.iter()` or a similar method
note: required by `std::iter::IntoIterator::into_iter`

Primitive types do not [currently] implement Iterator. Perhaps the output could see the type is primitive and suggest to create a type that implements Iterator, such as a range with 0..max?

Meta

rustc 1.11.0-nightly (bb4a79b08 2016-06-15)
binary: rustc
commit-hash: bb4a79b087158f396b984bdf552d2c90890b12a3
commit-date: 2016-06-15
host: x86_64-unknown-linux-gnu
release: 1.11.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions