-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #88503 - m-ou-se:array-into-inter-ambiguous, r=cjgillot
Warn when [T; N].into_iter() is ambiguous in the new edition. Fixes #88475 In #88475, a situation was found where `[T; N].into_iter()` becomes *ambiguous* in the new edition. This is different than the case where `(&[T; N]).into_iter()` resolves differently, which was the only case handled by the `array_into_iter` lint. This is almost identical to the new-traits-in-the-prelude problem. Effectively, due to the array-into-iter hack disappearing in Rust 2021, we effectively added `IntoIterator` to the 'prelude' in Rust 2021 specifically for arrays. This modifies the prelude collisions lint to detect that case and emit a `array_into_iter` lint in that case.
- Loading branch information
Showing
7 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// See https://github.com/rust-lang/rust/issues/88475 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![warn(array_into_iter)] | ||
#![allow(unused)] | ||
|
||
struct FooIter; | ||
|
||
trait MyIntoIter { | ||
fn into_iter(self) -> FooIter; | ||
} | ||
|
||
impl<T, const N: usize> MyIntoIter for [T; N] { | ||
fn into_iter(self) -> FooIter { | ||
FooIter | ||
} | ||
} | ||
|
||
struct Point; | ||
|
||
pub fn main() { | ||
let points: [Point; 1] = [Point]; | ||
let y = MyIntoIter::into_iter(points); | ||
//~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021 | ||
//~| WARNING this changes meaning in Rust 2021 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// See https://github.com/rust-lang/rust/issues/88475 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![warn(array_into_iter)] | ||
#![allow(unused)] | ||
|
||
struct FooIter; | ||
|
||
trait MyIntoIter { | ||
fn into_iter(self) -> FooIter; | ||
} | ||
|
||
impl<T, const N: usize> MyIntoIter for [T; N] { | ||
fn into_iter(self) -> FooIter { | ||
FooIter | ||
} | ||
} | ||
|
||
struct Point; | ||
|
||
pub fn main() { | ||
let points: [Point; 1] = [Point]; | ||
let y = points.into_iter(); | ||
//~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021 | ||
//~| WARNING this changes meaning in Rust 2021 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: trait method `into_iter` will become ambiguous in Rust 2021 | ||
--> $DIR/array-into-iter-ambiguous.rs:24:13 | ||
| | ||
LL | let y = points.into_iter(); | ||
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyIntoIter::into_iter(points)` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/array-into-iter-ambiguous.rs:5:9 | ||
| | ||
LL | #![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> | ||
|
||
warning: 1 warning emitted | ||
|