Fix error with suggestion for how to disambiguate associated function when struct is generic
This commit is contained in:
parent
eba3228b2a
commit
578fcbdb3c
5 changed files with 126 additions and 3 deletions
37
src/test/ui/rust-2021/future-prelude-collision-generic.fixed
Normal file
37
src/test/ui/rust-2021/future-prelude-collision-generic.fixed
Normal file
|
|
@ -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)
|
||||
}
|
||||
37
src/test/ui/rust-2021/future-prelude-collision-generic.rs
Normal file
37
src/test/ui/rust-2021/future-prelude-collision-generic.rs
Normal file
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue