Skip to content

Add a special case error for [Range<T>; 1] #23141

Closed
@reem

Description

@reem
Contributor

[Range<T>; 1] is usually a mistake and often the source of type errors where Range<T> was meant, since you get it with [a..b], which is tempting from the syntax.

Activity

Thiez

Thiez commented on Mar 7, 2015

@Thiez
Contributor

In theory &[0..10] could be correct in a for loop...

When using this program:

fn main() {
    for r in [0..10] {
        println!("{:?}", r);
    }
}

the current error message appears to be

error: the trait `core::iter::Iterator` is not implemented for the type `[core::ops::Range<_>; 1]
note: `[core::ops::Range<_>; 1]` is not an iterator; maybe try calling `.iter()` or a similar method

Surely that is understandable ("Why is the iterator in a length-1 array? Oh, better remove the []").
What bothers me more is that both messages show up three times, and count as 3 errors...

steveklabnik

steveklabnik commented on Jun 6, 2016

@steveklabnik
Member

Triage: Same error, but only one time. It could be a bit better, probably.

clarfonthey

clarfonthey commented on Dec 18, 2017

@clarfonthey
Contributor

Shouldn't this be a clippy issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @steveklabnik@Thiez@sfackler@reem@Mark-Simulacrum

      Issue actions

        Add a special case error for `[Range<T>; 1]` · Issue #23141 · rust-lang/rust