You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
array_into_iter does not trigger for existing trait impl #88475
This code will not emit the array_into_iter lint. When updating to the 2021 edition, the code fails to compile:
error[E0034]: multiple applicable items in scope
--> src/lib.rs:19:20
|
19 | let y = points.into_iter();
| ^^^^^^^^^ multiple `into_iter` found
|
note: candidate #1 is defined in an impl of the trait `MyIntoIter` for the type `[T; N]`
--> src/lib.rs:10:5
|
10 | fn into_iter(self: Self) -> FooIter {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: candidate #2 is defined in an impl of the trait `IntoIterator` for the type `[T; N]`
help: disambiguate the associated function for candidate #1
|
19 | let y = MyIntoIter::into_iter(points);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
|
19 | let y = IntoIterator::into_iter(points);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I would expect the array_into_iter lint to give the appropriate suggestion.
Changing some of the checks to include this situation for that lint would result in a completely wrong diagnostic:
warning: this method call resolves to `<&[T; N] as IntoIterator>::into_iter` (due to backwards compatibility), but will resolve to <[T; N] as IntoIterator>::into_iter in Rust 2021.
--> src/main.rs:20:20
|
20 | let y = points.into_iter();
| ^^^^^^^^^
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(array_into_iter)]
| ^^^^^^^^^^^^^^^
= warning: this changes meaning in Rust 2021
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html>
help: use `.iter()` instead of `.into_iter()` to avoid ambiguity
|
20 | let y = points.iter();
| ~~~~
help: or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value
|
20 | let y = IntoIterator::into_iter(points);
| ++++++++++++++++++++++++ ~
Instead, it'd have to do something more like the prelude collision lint. It'd have to generate the right fully explicit call syntax and some message about it becoming ambiguous in the new edition.
Activity
m-ou-se commentedon Aug 30, 2021
The lint specifically checks if it is libcore's IntoIterator::into_iter before producing the lint:
rust/compiler/rustc_lint/src/array_into_iter.rs
Lines 69 to 75 in 6cfa773
Maybe the check shouldn't be there. Maybe it should only check if the receiver is an array.
m-ou-se commentedon Aug 30, 2021
Changing some of the checks to include this situation for that lint would result in a completely wrong diagnostic:
Instead, it'd have to do something more like the prelude collision lint. It'd have to generate the right fully explicit call syntax and some message about it becoming ambiguous in the new edition.
Rollup merge of rust-lang#88503 - m-ou-se:array-into-inter-ambiguous,…