Skip to content

Commit 7e5d477

Browse files
author
Yuki Okushi
authored
Rollup merge of #106740 - petar-dambovaliev:float-iterator-hint, r=Nilstrieb
Adding a hint on iterator type errors Issue reference #106728 - [x] add a case in the attribute - [x] add a test closes #106728
2 parents 19ba430 + bdf9900 commit 7e5d477

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
5858
note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
5959
syntax `start..end` or the inclusive range syntax `start..=end`"
6060
),
61+
on(
62+
_Self = "{float}",
63+
note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
64+
syntax `start..end` or the inclusive range syntax `start..=end`"
65+
),
6166
label = "`{Self}` is not an iterator",
6267
message = "`{Self}` is not an iterator"
6368
)]
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// #106728
2+
3+
fn main() {
4+
for i in 0.2 {
5+
//~^ ERROR `{float}` is not an iterator
6+
//~| `{float}` is not an iterator
7+
//~| NOTE in this expansion of desugaring of `for` loop
8+
//~| NOTE in this expansion of desugaring of `for` loop
9+
//~| NOTE in this expansion of desugaring of `for` loop
10+
//~| NOTE in this expansion of desugaring of `for` loop
11+
//~| NOTE if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
12+
//~| NOTE required for `{float}` to implement `IntoIterator`
13+
println!();
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0277]: `{float}` is not an iterator
2+
--> $DIR/float_iterator_hint.rs:4:14
3+
|
4+
LL | for i in 0.2 {
5+
| ^^^ `{float}` is not an iterator
6+
|
7+
= help: the trait `Iterator` is not implemented for `{float}`
8+
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
9+
= note: required for `{float}` to implement `IntoIterator`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0277`.

tests/ui/iterators/integral.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ LL | for _ in 42.0 {}
115115
| ^^^^ `{float}` is not an iterator
116116
|
117117
= help: the trait `Iterator` is not implemented for `{float}`
118+
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
118119
= note: required for `{float}` to implement `IntoIterator`
119120

120121
error: aborting due to 12 previous errors

0 commit comments

Comments
 (0)