forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#87557 - rylev:fix-invalid-prelude-collision…
…-error, r=nikomatsakis Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic Fixes rust-lang#86940 The test cases and associated issue should make it clear what specifically this is meant to fix. The fix is slightly hacky in that we check against the literal source code of the call site for the presence of `<` in order to determine if the user has included the generics for the struct (meaning we don't need to include them for them). r? `@nikomatsakis`
- Loading branch information
Showing
5 changed files
with
126 additions
and
3 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
37 changes: 37 additions & 0 deletions
37
src/test/ui/rust-2021/future-prelude-collision-generic.fixed
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,37 @@ | ||
// test for /~https://github.com/rust-lang/rust/issues/86940 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![warn(rust_2021_prelude_collisions)] | ||
#![allow(dead_code)] | ||
#![allow(unused_imports)] | ||
|
||
struct Generic<T, U>(T, U); | ||
|
||
trait MyFromIter { | ||
fn from_iter(_: i32) -> Self; | ||
} | ||
|
||
impl MyFromIter for Generic<i32, i32> { | ||
fn from_iter(x: i32) -> Self { | ||
Self(x, x) | ||
} | ||
} | ||
|
||
impl std::iter::FromIterator<i32> for Generic<i32, i32> { | ||
fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self { | ||
todo!() | ||
} | ||
} | ||
|
||
fn main() { | ||
<Generic<_, _> as MyFromIter>::from_iter(1); | ||
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
<Generic::<i32, i32> as MyFromIter>::from_iter(1); | ||
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
<Generic::<_, _> as MyFromIter>::from_iter(1); | ||
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
} |
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,37 @@ | ||
// test for /~https://github.com/rust-lang/rust/issues/86940 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![warn(rust_2021_prelude_collisions)] | ||
#![allow(dead_code)] | ||
#![allow(unused_imports)] | ||
|
||
struct Generic<T, U>(T, U); | ||
|
||
trait MyFromIter { | ||
fn from_iter(_: i32) -> Self; | ||
} | ||
|
||
impl MyFromIter for Generic<i32, i32> { | ||
fn from_iter(x: i32) -> Self { | ||
Self(x, x) | ||
} | ||
} | ||
|
||
impl std::iter::FromIterator<i32> for Generic<i32, i32> { | ||
fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self { | ||
todo!() | ||
} | ||
} | ||
|
||
fn main() { | ||
Generic::from_iter(1); | ||
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
Generic::<i32, i32>::from_iter(1); | ||
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
Generic::<_, _>::from_iter(1); | ||
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
} |
34 changes: 34 additions & 0 deletions
34
src/test/ui/rust-2021/future-prelude-collision-generic.stderr
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,34 @@ | ||
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
--> $DIR/future-prelude-collision-generic.rs:28:5 | ||
| | ||
LL | Generic::from_iter(1); | ||
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic<_, _> as MyFromIter>::from_iter` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/future-prelude-collision-generic.rs:5:9 | ||
| | ||
LL | #![warn(rust_2021_prelude_collisions)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
= note: for more information, see issue #85684 </~https://github.com/rust-lang/rust/issues/85684> | ||
|
||
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
--> $DIR/future-prelude-collision-generic.rs:31:5 | ||
| | ||
LL | Generic::<i32, i32>::from_iter(1); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<i32, i32> as MyFromIter>::from_iter` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
= note: for more information, see issue #85684 </~https://github.com/rust-lang/rust/issues/85684> | ||
|
||
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 | ||
--> $DIR/future-prelude-collision-generic.rs:34:5 | ||
| | ||
LL | Generic::<_, _>::from_iter(1); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<_, _> as MyFromIter>::from_iter` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
= note: for more information, see issue #85684 </~https://github.com/rust-lang/rust/issues/85684> | ||
|
||
warning: 3 warnings emitted | ||
|
File renamed without changes.