Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit eb5e0af

Browse files
jam1garnernikomatsakis
authored andcommitted
Add autoderef and autoref tests for future_prelude_collision lint
1 parent 327697a commit eb5e0af

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

src/test/ui/lint/future-prelude-collision.fixed

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ impl TryIntoU32 for u8 {
1212
}
1313
}
1414

15+
// needed for autoref test
16+
impl TryIntoU32 for &f32 {
17+
fn try_into(self) -> Result<u32, ()> {
18+
Ok(*self as u32)
19+
}
20+
}
21+
1522
trait TryFromU8: Sized {
1623
fn try_from(x: u8) -> Result<Self, ()>;
1724
}
@@ -54,4 +61,12 @@ fn main() {
5461
// test type omission
5562
let _: u32 = <_ as TryFromU8>::try_from(3u8).unwrap();
5663
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
64+
65+
// test autoderef
66+
let _: u32 = TryIntoU32::try_into(*(&3u8)).unwrap();
67+
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
68+
69+
// test autoref
70+
let _: u32 = TryIntoU32::try_into(&3.0).unwrap();
71+
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
5772
}

src/test/ui/lint/future-prelude-collision.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ impl TryIntoU32 for u8 {
1212
}
1313
}
1414

15+
// needed for autoref test
16+
impl TryIntoU32 for &f32 {
17+
fn try_into(self) -> Result<u32, ()> {
18+
Ok(*self as u32)
19+
}
20+
}
21+
1522
trait TryFromU8: Sized {
1623
fn try_from(x: u8) -> Result<Self, ()>;
1724
}
@@ -54,4 +61,12 @@ fn main() {
5461
// test type omission
5562
let _: u32 = <_>::try_from(3u8).unwrap();
5663
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
64+
65+
// test autoderef
66+
let _: u32 = (&3u8).try_into().unwrap();
67+
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
68+
69+
// test autoref
70+
let _: u32 = 3.0.try_into().unwrap();
71+
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
5772
}
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
warning: trait method `try_into` will become ambiguous in Rust 2021
2-
--> $DIR/future-prelude-collision.rs:40:18
2+
--> $DIR/future-prelude-collision.rs:47:18
33
|
44
LL | let _: u32 = 3u8.try_into().unwrap();
55
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)`
66
|
77
= note: `#[warn(future_prelude_collision)]` on by default
88

99
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
10-
--> $DIR/future-prelude-collision.rs:44:13
10+
--> $DIR/future-prelude-collision.rs:51:13
1111
|
1212
LL | let _ = u32::try_from(3u8).unwrap();
1313
| ^^^^^^^^^^^^^ help: disambiguate the associated function: `<u32 as TryFromU8>::try_from`
1414

1515
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
16-
--> $DIR/future-prelude-collision.rs:48:13
16+
--> $DIR/future-prelude-collision.rs:55:13
1717
|
1818
LL | let _ = <Vec<u8>>::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter());
1919
| ^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Vec<u8> as FromByteIterator>::from_iter`
2020

2121
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
22-
--> $DIR/future-prelude-collision.rs:55:18
22+
--> $DIR/future-prelude-collision.rs:62:18
2323
|
2424
LL | let _: u32 = <_>::try_from(3u8).unwrap();
2525
| ^^^^^^^^^^^^^ help: disambiguate the associated function: `<_ as TryFromU8>::try_from`
2626

27-
warning: 4 warnings emitted
27+
warning: trait method `try_into` will become ambiguous in Rust 2021
28+
--> $DIR/future-prelude-collision.rs:66:18
29+
|
30+
LL | let _: u32 = (&3u8).try_into().unwrap();
31+
| ^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(*(&3u8))`
32+
33+
warning: trait method `try_into` will become ambiguous in Rust 2021
34+
--> $DIR/future-prelude-collision.rs:70:18
35+
|
36+
LL | let _: u32 = 3.0.try_into().unwrap();
37+
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(&3.0)`
38+
39+
warning: 6 warnings emitted
2840

0 commit comments

Comments
 (0)