Skip to content

Commit f6ce957

Browse files
authored
Rollup merge of rust-lang#85689 - m-ou-se:array-intoiter-3, r=estebank
Remove Iterator #[rustc_on_unimplemented]s that no longer apply. Now that `IntoIterator` is implemented for arrays, all the `rustc_on_unimplemented` for arrays of ranges (e.g. `for _ in [1..3] {}`) no longer apply, since they are now valid Rust. Separated these from rust-lang#85670, because we should discuss a potential new (clippy?) lint for these. Until Rust 1.52, `for _ in [1..3] {}` produced: ``` error[E0277]: `[std::ops::Range<{integer}>; 1]` is not an iterator --> src/main.rs:2:14 | 2 | for _ in [1..3] {} | ^^^^^^ if you meant to iterate between two values, remove the square brackets | = help: the trait `std::iter::Iterator` is not implemented for `[std::ops::Range<{integer}>; 1]` = 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` ``` But in Rust 1.53 and later, it compiles fine. It iterates over the array by value, for one iteration with the element `1..3`. This is probably a mistake, which is no longer caught. Should we have a lint for it? Should Clippy have a lint for it? cc `@estebank` `@flip1995` cc rust-lang#84513
2 parents 3e2c8c5 + caf6faf commit f6ce957

File tree

1 file changed

+0
-34
lines changed

1 file changed

+0
-34
lines changed

library/core/src/iter/traits/iterator.rs

-34
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,6 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
2525
/// [impl]: crate::iter#implementing-iterator
2626
#[stable(feature = "rust1", since = "1.0.0")]
2727
#[rustc_on_unimplemented(
28-
on(
29-
_Self = "[std::ops::Range<Idx>; 1]",
30-
label = "if you meant to iterate between two values, remove the square brackets",
31-
note = "`[start..end]` is an array of one `Range`; you might have meant to have a `Range` \
32-
without the brackets: `start..end`"
33-
),
34-
on(
35-
_Self = "[std::ops::RangeFrom<Idx>; 1]",
36-
label = "if you meant to iterate from a value onwards, remove the square brackets",
37-
note = "`[start..]` is an array of one `RangeFrom`; you might have meant to have a \
38-
`RangeFrom` without the brackets: `start..`, keeping in mind that iterating over an \
39-
unbounded iterator will run forever unless you `break` or `return` from within the \
40-
loop"
41-
),
42-
on(
43-
_Self = "[std::ops::RangeTo<Idx>; 1]",
44-
label = "if you meant to iterate until a value, remove the square brackets and add a \
45-
starting value",
46-
note = "`[..end]` is an array of one `RangeTo`; you might have meant to have a bounded \
47-
`Range` without the brackets: `0..end`"
48-
),
49-
on(
50-
_Self = "[std::ops::RangeInclusive<Idx>; 1]",
51-
label = "if you meant to iterate between two values, remove the square brackets",
52-
note = "`[start..=end]` is an array of one `RangeInclusive`; you might have meant to have a \
53-
`RangeInclusive` without the brackets: `start..=end`"
54-
),
55-
on(
56-
_Self = "[std::ops::RangeToInclusive<Idx>; 1]",
57-
label = "if you meant to iterate until a value (including it), remove the square brackets \
58-
and add a starting value",
59-
note = "`[..=end]` is an array of one `RangeToInclusive`; you might have meant to have a \
60-
bounded `RangeInclusive` without the brackets: `0..=end`"
61-
),
6228
on(
6329
_Self = "std::ops::RangeTo<Idx>",
6430
label = "if you meant to iterate until a value, add a starting value",

0 commit comments

Comments
 (0)