Skip to content

Commit 78a7d1c

Browse files
committed
Add and update tests.
1 parent e2abf06 commit 78a7d1c

6 files changed

+96
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// See https://github.com/rust-lang/rust/issues/88470
2+
// run-rustfix
3+
// edition:2018
4+
// check-pass
5+
#![warn(rust_2021_prelude_collisions)]
6+
#![allow(dead_code)]
7+
#![allow(unused_imports)]
8+
9+
pub trait PyTryFrom<'v, T>: Sized {
10+
fn try_from<V>(value: V) -> Result<&'v Self, T>;
11+
}
12+
13+
pub trait PyTryInto<T>: Sized {
14+
fn try_into(&self) -> Result<&T, i32>;
15+
}
16+
17+
struct Foo;
18+
19+
impl<U> PyTryInto<U> for Foo
20+
where
21+
U: for<'v> PyTryFrom<'v, i32>,
22+
{
23+
fn try_into(&self) -> Result<&U, i32> {
24+
<U as PyTryFrom<'_, _>>::try_from(self)
25+
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
26+
//~| this is accepted in the current edition (Rust 2018)
27+
}
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// See https://github.com/rust-lang/rust/issues/88470
2+
// run-rustfix
3+
// edition:2018
4+
// check-pass
5+
#![warn(rust_2021_prelude_collisions)]
6+
#![allow(dead_code)]
7+
#![allow(unused_imports)]
8+
9+
pub trait PyTryFrom<'v, T>: Sized {
10+
fn try_from<V>(value: V) -> Result<&'v Self, T>;
11+
}
12+
13+
pub trait PyTryInto<T>: Sized {
14+
fn try_into(&self) -> Result<&T, i32>;
15+
}
16+
17+
struct Foo;
18+
19+
impl<U> PyTryInto<U> for Foo
20+
where
21+
U: for<'v> PyTryFrom<'v, i32>,
22+
{
23+
fn try_into(&self) -> Result<&U, i32> {
24+
U::try_from(self)
25+
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
26+
//~| this is accepted in the current edition (Rust 2018)
27+
}
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
2+
--> $DIR/future-prelude-collision-generic-trait.rs:24:9
3+
|
4+
LL | U::try_from(self)
5+
| ^^^^^^^^^^^ help: disambiguate the associated function: `<U as PyTryFrom<'_, _>>::try_from`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/future-prelude-collision-generic-trait.rs:5:9
9+
|
10+
LL | #![warn(rust_2021_prelude_collisions)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
13+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
14+
15+
warning: 1 warning emitted
16+

src/test/ui/rust-2021/future-prelude-collision-generic.fixed

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66
#![allow(dead_code)]
77
#![allow(unused_imports)]
88

9-
struct Generic<T, U>(T, U);
9+
struct Generic<'a, U>(&'a U);
1010

1111
trait MyFromIter {
1212
fn from_iter(_: i32) -> Self;
1313
}
1414

15-
impl MyFromIter for Generic<i32, i32> {
16-
fn from_iter(x: i32) -> Self {
17-
Self(x, x)
15+
impl MyFromIter for Generic<'static, i32> {
16+
fn from_iter(_: i32) -> Self {
17+
todo!()
1818
}
1919
}
2020

21-
impl std::iter::FromIterator<i32> for Generic<i32, i32> {
21+
impl std::iter::FromIterator<i32> for Generic<'static, i32> {
2222
fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self {
2323
todo!()
2424
}
2525
}
2626

2727
fn main() {
28-
<Generic<_, _> as MyFromIter>::from_iter(1);
28+
<Generic<'_, _> as MyFromIter>::from_iter(1);
2929
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
3030
//~| this is accepted in the current edition (Rust 2018)
31-
<Generic::<i32, i32> as MyFromIter>::from_iter(1);
31+
<Generic::<'static, i32> as MyFromIter>::from_iter(1);
3232
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
3333
//~| this is accepted in the current edition (Rust 2018)
34-
<Generic::<_, _> as MyFromIter>::from_iter(1);
34+
<Generic::<'_, _> as MyFromIter>::from_iter(1);
3535
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
3636
//~| this is accepted in the current edition (Rust 2018)
3737
}

src/test/ui/rust-2021/future-prelude-collision-generic.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
#![allow(dead_code)]
77
#![allow(unused_imports)]
88

9-
struct Generic<T, U>(T, U);
9+
struct Generic<'a, U>(&'a U);
1010

1111
trait MyFromIter {
1212
fn from_iter(_: i32) -> Self;
1313
}
1414

15-
impl MyFromIter for Generic<i32, i32> {
16-
fn from_iter(x: i32) -> Self {
17-
Self(x, x)
15+
impl MyFromIter for Generic<'static, i32> {
16+
fn from_iter(_: i32) -> Self {
17+
todo!()
1818
}
1919
}
2020

21-
impl std::iter::FromIterator<i32> for Generic<i32, i32> {
21+
impl std::iter::FromIterator<i32> for Generic<'static, i32> {
2222
fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self {
2323
todo!()
2424
}
@@ -28,10 +28,10 @@ fn main() {
2828
Generic::from_iter(1);
2929
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
3030
//~| this is accepted in the current edition (Rust 2018)
31-
Generic::<i32, i32>::from_iter(1);
31+
Generic::<'static, i32>::from_iter(1);
3232
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
3333
//~| this is accepted in the current edition (Rust 2018)
34-
Generic::<_, _>::from_iter(1);
34+
Generic::<'_, _>::from_iter(1);
3535
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
3636
//~| this is accepted in the current edition (Rust 2018)
3737
}

src/test/ui/rust-2021/future-prelude-collision-generic.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: trait-associated function `from_iter` will become ambiguous in Rust 202
22
--> $DIR/future-prelude-collision-generic.rs:28:5
33
|
44
LL | Generic::from_iter(1);
5-
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic<_, _> as MyFromIter>::from_iter`
5+
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic<'_, _> as MyFromIter>::from_iter`
66
|
77
note: the lint level is defined here
88
--> $DIR/future-prelude-collision-generic.rs:5:9
@@ -15,17 +15,17 @@ LL | #![warn(rust_2021_prelude_collisions)]
1515
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
1616
--> $DIR/future-prelude-collision-generic.rs:31:5
1717
|
18-
LL | Generic::<i32, i32>::from_iter(1);
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<i32, i32> as MyFromIter>::from_iter`
18+
LL | Generic::<'static, i32>::from_iter(1);
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<'static, i32> as MyFromIter>::from_iter`
2020
|
2121
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
2222
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>
2323

2424
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
2525
--> $DIR/future-prelude-collision-generic.rs:34:5
2626
|
27-
LL | Generic::<_, _>::from_iter(1);
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<_, _> as MyFromIter>::from_iter`
27+
LL | Generic::<'_, _>::from_iter(1);
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<'_, _> as MyFromIter>::from_iter`
2929
|
3030
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
3131
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>

0 commit comments

Comments
 (0)