Skip to content

Commit 918d0ee

Browse files
authored
Rollup merge of rust-lang#94746 - notriddle:notriddle/method-rustc-on-unimplemented, r=davidtwco
diagnostics: use rustc_on_unimplemented to recommend `[].iter()` To make this work, the `#[rustc_on_unimplemented]` data needs to be used to report method resolution errors, which is most of what this commit does. Fixes rust-lang#94581
2 parents 0215813 + 131470f commit 918d0ee

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

core/src/iter/traits/iterator.rs

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
3434
note = "`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \
3535
to have a bounded `RangeInclusive`: `0..=end`"
3636
),
37+
on(
38+
_Self = "[]",
39+
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
40+
),
41+
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
3742
on(
3843
_Self = "&str",
3944
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"

0 commit comments

Comments
 (0)