]>
Commit | Line | Data |
---|---|---|
136023e0 XL |
1 | // run-rustfix |
2 | // edition:2018 | |
3 | // check-pass | |
4 | #![warn(rust_2021_prelude_collisions)] | |
5 | #![allow(dead_code)] | |
6 | #![allow(unused_imports)] | |
7 | ||
8 | mod m { | |
9 | pub trait TryIntoU32 { | |
10 | fn try_into(self) -> Result<u32, ()>; | |
11 | } | |
12 | ||
13 | impl TryIntoU32 for u8 { | |
14 | fn try_into(self) -> Result<u32, ()> { | |
15 | Ok(self as u32) | |
16 | } | |
17 | } | |
18 | ||
19 | pub trait AnotherTrick {} | |
20 | } | |
21 | ||
22 | mod a { | |
23 | use crate::m::TryIntoU32; | |
24 | ||
25 | fn main() { | |
26 | // In this case, we can just use `TryIntoU32` | |
27 | let _: u32 = 3u8.try_into().unwrap(); | |
28 | //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | |
29 | //~^^ WARNING this is accepted in the current edition | |
30 | } | |
31 | } | |
32 | ||
33 | mod b { | |
34 | use crate::m::AnotherTrick as TryIntoU32; | |
35 | use crate::m::TryIntoU32 as _; | |
36 | ||
37 | fn main() { | |
38 | // In this case, a `TryIntoU32::try_into` rewrite will not work, and we need to use | |
39 | // the path `crate::m::TryIntoU32` (with which it was imported). | |
40 | let _: u32 = 3u8.try_into().unwrap(); | |
41 | //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | |
42 | //~^^ WARNING this is accepted in the current edition | |
43 | } | |
44 | } | |
45 | ||
46 | mod c { | |
47 | use super::m::TryIntoU32 as _; | |
48 | use crate::m::AnotherTrick as TryIntoU32; | |
49 | ||
50 | fn main() { | |
51 | // In this case, a `TryIntoU32::try_into` rewrite will not work, and we need to use | |
52 | // the path `super::m::TryIntoU32` (with which it was imported). | |
53 | let _: u32 = 3u8.try_into().unwrap(); | |
54 | //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | |
55 | //~^^ WARNING this is accepted in the current edition | |
56 | } | |
57 | } | |
58 | ||
94222f64 XL |
59 | mod d { |
60 | use super::m::*; | |
61 | ||
62 | fn main() { | |
63 | // See https://github.com/rust-lang/rust/issues/88471 | |
64 | let _: u32 = 3u8.try_into().unwrap(); | |
65 | //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | |
66 | //~^^ WARNING this is accepted in the current edition | |
67 | } | |
68 | } | |
69 | ||
136023e0 | 70 | fn main() {} |