Reword Range*/[Range*]: Iterator E0277 messages
This commit is contained in:
parent
c71228e2f4
commit
5beeb535e1
5 changed files with 113 additions and 10 deletions
|
@ -40,13 +40,16 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {}
|
||||||
_Self="[std::ops::RangeFrom<Idx>; 1]",
|
_Self="[std::ops::RangeFrom<Idx>; 1]",
|
||||||
label="if you meant to iterate from a value onwards, remove the square brackets",
|
label="if you meant to iterate from a value onwards, remove the square brackets",
|
||||||
note="`[start..]` is an array of one `RangeFrom`; you might have meant to have a \
|
note="`[start..]` is an array of one `RangeFrom`; you might have meant to have a \
|
||||||
`RangeFrom` without the brackets: `start..`"
|
`RangeFrom` without the brackets: `start..`, keeping in mind that iterating over an \
|
||||||
|
unbounded iterator will run forever unless you `break` or `return` from within the \
|
||||||
|
loop"
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
_Self="[std::ops::RangeTo<Idx>; 1]",
|
_Self="[std::ops::RangeTo<Idx>; 1]",
|
||||||
label="if you meant to iterate until a value, remove the square brackets",
|
label="if you meant to iterate until a value, remove the square brackets and add a \
|
||||||
note="`[..end]` is an array of one `RangeTo`; you might have meant to have a \
|
starting value",
|
||||||
`RangeTo` without the brackets: `..end`"
|
note="`[..end]` is an array of one `RangeTo`; you might have meant to have a bounded \
|
||||||
|
`Range` without the brackets: `0..end`"
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
_Self="[std::ops::RangeInclusive<Idx>; 1]",
|
_Self="[std::ops::RangeInclusive<Idx>; 1]",
|
||||||
|
@ -56,9 +59,22 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {}
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
_Self="[std::ops::RangeToInclusive<Idx>; 1]",
|
_Self="[std::ops::RangeToInclusive<Idx>; 1]",
|
||||||
label="if you meant to iterate until a value, remove the square brackets",
|
label="if you meant to iterate until a value (including it), remove the square brackets \
|
||||||
|
and add a starting value",
|
||||||
note="`[..=end]` is an array of one `RangeToInclusive`; you might have meant to have a \
|
note="`[..=end]` is an array of one `RangeToInclusive`; you might have meant to have a \
|
||||||
`RangeToInclusive` without the brackets: `..=end`"
|
bounded `RangeInclusive` without the brackets: `0..=end`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
_Self="std::ops::RangeTo<Idx>",
|
||||||
|
label="if you meant to iterate until a value, add a starting value",
|
||||||
|
note="`..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a \
|
||||||
|
bounded `Range`: `0..end`"
|
||||||
|
),
|
||||||
|
on(
|
||||||
|
_Self="std::ops::RangeToInclusive<Idx>",
|
||||||
|
label="if you meant to iterate until a value (including it), add a starting value",
|
||||||
|
note="`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \
|
||||||
|
to have a bounded `RangeInclusive`: `0..=end`"
|
||||||
),
|
),
|
||||||
on(
|
on(
|
||||||
_Self="&str",
|
_Self="&str",
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
for _ in [0..1] {}
|
for _ in [0..1] {}
|
||||||
|
for _ in [0..=1] {}
|
||||||
|
for _ in [0..] {}
|
||||||
|
for _ in [..1] {}
|
||||||
|
for _ in [..=1] {}
|
||||||
let start = 0;
|
let start = 0;
|
||||||
let end = 0;
|
let end = 0;
|
||||||
for _ in [start..end] {}
|
for _ in [start..end] {}
|
||||||
let array_of_range = [start..end];
|
let array_of_range = [start..end];
|
||||||
for _ in array_of_range {}
|
for _ in array_of_range {}
|
||||||
for _ in [0..1, 2..3] {}
|
for _ in [0..1, 2..3] {}
|
||||||
|
for _ in [0..=1] {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,49 @@ LL | for _ in [0..1] {}
|
||||||
= note: `[start..end]` is an array of one `Range`; you might have meant to have a `Range` without the brackets: `start..end`
|
= note: `[start..end]` is an array of one `Range`; you might have meant to have a `Range` without the brackets: `start..end`
|
||||||
= note: required by `std::iter::IntoIterator::into_iter`
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
|
error[E0277]: `[std::ops::RangeInclusive<{integer}>; 1]` is not an iterator
|
||||||
|
--> $DIR/array-of-ranges.rs:3:14
|
||||||
|
|
|
||||||
|
LL | for _ in [0..=1] {}
|
||||||
|
| ^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::RangeInclusive<{integer}>; 1]`
|
||||||
|
= note: `[start..=end]` is an array of one `RangeInclusive`; you might have meant to have a `RangeInclusive` without the brackets: `start..=end`
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error[E0277]: `[std::ops::RangeFrom<{integer}>; 1]` is not an iterator
|
||||||
|
--> $DIR/array-of-ranges.rs:4:14
|
||||||
|
|
|
||||||
|
LL | for _ in [0..] {}
|
||||||
|
| ^^^^^ if you meant to iterate from a value onwards, remove the square brackets
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::RangeFrom<{integer}>; 1]`
|
||||||
|
= note: `[start..]` is an array of one `RangeFrom`; you might have meant to have a `RangeFrom` without the brackets: `start..`, keeping in mind that iterating over an unbounded iterator will run forever unless you `break` or `return` from within the loop
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error[E0277]: `[std::ops::RangeTo<{integer}>; 1]` is not an iterator
|
||||||
--> $DIR/array-of-ranges.rs:5:14
|
--> $DIR/array-of-ranges.rs:5:14
|
||||||
|
|
|
|
||||||
|
LL | for _ in [..1] {}
|
||||||
|
| ^^^^^ if you meant to iterate until a value, remove the square brackets and add a starting value
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::RangeTo<{integer}>; 1]`
|
||||||
|
= note: `[..end]` is an array of one `RangeTo`; you might have meant to have a bounded `Range` without the brackets: `0..end`
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error[E0277]: `[std::ops::RangeToInclusive<{integer}>; 1]` is not an iterator
|
||||||
|
--> $DIR/array-of-ranges.rs:6:14
|
||||||
|
|
|
||||||
|
LL | for _ in [..=1] {}
|
||||||
|
| ^^^^^^ if you meant to iterate until a value (including it), remove the square brackets and add a starting value
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::RangeToInclusive<{integer}>; 1]`
|
||||||
|
= note: `[..=end]` is an array of one `RangeToInclusive`; you might have meant to have a bounded `RangeInclusive` without the brackets: `0..=end`
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
|
||||||
|
--> $DIR/array-of-ranges.rs:9:14
|
||||||
|
|
|
||||||
LL | for _ in [start..end] {}
|
LL | for _ in [start..end] {}
|
||||||
| ^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
| ^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
||||||
|
|
|
|
||||||
|
@ -19,7 +59,7 @@ LL | for _ in [start..end] {}
|
||||||
= note: required by `std::iter::IntoIterator::into_iter`
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
|
error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator
|
||||||
--> $DIR/array-of-ranges.rs:7:14
|
--> $DIR/array-of-ranges.rs:11:14
|
||||||
|
|
|
|
||||||
LL | for _ in array_of_range {}
|
LL | for _ in array_of_range {}
|
||||||
| ^^^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
| ^^^^^^^^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
||||||
|
@ -29,7 +69,7 @@ LL | for _ in array_of_range {}
|
||||||
= note: required by `std::iter::IntoIterator::into_iter`
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
error[E0277]: `[std::ops::Range<{integer}>; 2]` is not an iterator
|
error[E0277]: `[std::ops::Range<{integer}>; 2]` is not an iterator
|
||||||
--> $DIR/array-of-ranges.rs:8:14
|
--> $DIR/array-of-ranges.rs:12:14
|
||||||
|
|
|
|
||||||
LL | for _ in [0..1, 2..3] {}
|
LL | for _ in [0..1, 2..3] {}
|
||||||
| ^^^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
|
| ^^^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
|
||||||
|
@ -38,6 +78,16 @@ LL | for _ in [0..1, 2..3] {}
|
||||||
= note: arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`
|
= note: arrays are not an iterators, but slices like the following are: `&[1, 2, 3]`
|
||||||
= note: required by `std::iter::IntoIterator::into_iter`
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error[E0277]: `[std::ops::RangeInclusive<{integer}>; 1]` is not an iterator
|
||||||
|
--> $DIR/array-of-ranges.rs:13:14
|
||||||
|
|
|
||||||
|
LL | for _ in [0..=1] {}
|
||||||
|
| ^^^^^^^ if you meant to iterate between two values, remove the square brackets
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `[std::ops::RangeInclusive<{integer}>; 1]`
|
||||||
|
= note: `[start..=end]` is an array of one `RangeInclusive`; you might have meant to have a `RangeInclusive` without the brackets: `start..=end`
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error: aborting due to 9 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
|
9
src/test/ui/iterators/ranges.rs
Normal file
9
src/test/ui/iterators/ranges.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
fn main() {
|
||||||
|
for _ in ..10 {}
|
||||||
|
//~^ ERROR E0277
|
||||||
|
for _ in ..=10 {}
|
||||||
|
//~^ ERROR E0277
|
||||||
|
for _ in 0..10 {}
|
||||||
|
for _ in 0..=10 {}
|
||||||
|
for _ in 0.. {}
|
||||||
|
}
|
23
src/test/ui/iterators/ranges.stderr
Normal file
23
src/test/ui/iterators/ranges.stderr
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
error[E0277]: `std::ops::RangeTo<{integer}>` is not an iterator
|
||||||
|
--> $DIR/ranges.rs:2:14
|
||||||
|
|
|
||||||
|
LL | for _ in ..10 {}
|
||||||
|
| ^^^^ if you meant to iterate until a value, add a starting value
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `std::ops::RangeTo<{integer}>`
|
||||||
|
= note: `..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a bounded `Range`: `0..end`
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error[E0277]: `std::ops::RangeToInclusive<{integer}>` is not an iterator
|
||||||
|
--> $DIR/ranges.rs:4:14
|
||||||
|
|
|
||||||
|
LL | for _ in ..=10 {}
|
||||||
|
| ^^^^^ if you meant to iterate until a value (including it), add a starting value
|
||||||
|
|
|
||||||
|
= help: the trait `std::iter::Iterator` is not implemented for `std::ops::RangeToInclusive<{integer}>`
|
||||||
|
= note: `..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant to have a bounded `RangeInclusive`: `0..=end`
|
||||||
|
= note: required by `std::iter::IntoIterator::into_iter`
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Add table
Add a link
Reference in a new issue