diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2023-01-13 05:47:23 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-13 05:47:23 +0900 |
| commit | 7e5d477ac555d145ad4dcabd78ef8900f377a017 (patch) | |
| tree | 7eab697656390189b88d8cb6f0439104568da261 | |
| parent | 19ba4305b9b4dd1bdfa025f974338f6172cd1e12 (diff) | |
| parent | bdf990022a0eadede1831b8523d77adf36811823 (diff) | |
| download | rust-7e5d477ac555d145ad4dcabd78ef8900f377a017.tar.gz rust-7e5d477ac555d145ad4dcabd78ef8900f377a017.zip | |
Rollup merge of #106740 - petar-dambovaliev:float-iterator-hint, r=Nilstrieb
Adding a hint on iterator type errors Issue reference https://github.com/rust-lang/rust/issues/106728 - [x] add a case in the attribute - [x] add a test closes #106728
| -rw-r--r-- | library/core/src/iter/traits/iterator.rs | 5 | ||||
| -rw-r--r-- | tests/ui/iterators/float_iterator_hint.rs | 15 | ||||
| -rw-r--r-- | tests/ui/iterators/float_iterator_hint.stderr | 13 | ||||
| -rw-r--r-- | tests/ui/iterators/integral.stderr | 1 |
4 files changed, 34 insertions, 0 deletions
diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 99aaf798e41..a4a665d48d5 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -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" )] diff --git a/tests/ui/iterators/float_iterator_hint.rs b/tests/ui/iterators/float_iterator_hint.rs new file mode 100644 index 00000000000..a3335ca41f7 --- /dev/null +++ b/tests/ui/iterators/float_iterator_hint.rs @@ -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!(); + } +} diff --git a/tests/ui/iterators/float_iterator_hint.stderr b/tests/ui/iterators/float_iterator_hint.stderr new file mode 100644 index 00000000000..bae23a1f8ff --- /dev/null +++ b/tests/ui/iterators/float_iterator_hint.stderr @@ -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`. diff --git a/tests/ui/iterators/integral.stderr b/tests/ui/iterators/integral.stderr index 047a71f98d9..c142fec8da0 100644 --- a/tests/ui/iterators/integral.stderr +++ b/tests/ui/iterators/integral.stderr @@ -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 |
