Skip to content

Commit

Permalink
Rollup merge of #106740 - petar-dambovaliev:float-iterator-hint, r=Ni…
Browse files Browse the repository at this point in the history
…lstrieb

Adding a hint on iterator type errors

Issue reference #106728

- [x] add a case in the attribute
- [x] add a test

closes #106728
  • Loading branch information
Yuki Okushi authored Jan 12, 2023
2 parents 19ba430 + bdf9900 commit 7e5d477
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
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`"
),
on(
_Self = "{float}",
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`"
),
label = "`{Self}` is not an iterator",
message = "`{Self}` is not an iterator"
)]
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/iterators/float_iterator_hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// #106728

fn main() {
for i in 0.2 {
//~^ ERROR `{float}` is not an iterator
//~| `{float}` is not an iterator
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| 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`
//~| NOTE required for `{float}` to implement `IntoIterator`
println!();
}
}
13 changes: 13 additions & 0 deletions tests/ui/iterators/float_iterator_hint.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0277]: `{float}` is not an iterator
--> $DIR/float_iterator_hint.rs:4:14
|
LL | for i in 0.2 {
| ^^^ `{float}` is not an iterator
|
= help: the trait `Iterator` is not implemented for `{float}`
= 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`
= note: required for `{float}` to implement `IntoIterator`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions tests/ui/iterators/integral.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ LL | for _ in 42.0 {}
| ^^^^ `{float}` is not an iterator
|
= help: the trait `Iterator` is not implemented for `{float}`
= 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`
= note: required for `{float}` to implement `IntoIterator`

error: aborting due to 12 previous errors
Expand Down

0 comments on commit 7e5d477

Please sign in to comment.