4 #![warn(rust_2021_prelude_collisions)]
7 fn try_into(self) -> Result<u32, ()>;
10 impl TryIntoU32 for u8 {
11 fn try_into(self) -> Result<u32, ()> {
16 // needed for autoref test
17 impl TryIntoU32 for &f32 {
18 fn try_into(self) -> Result<u32, ()> {
23 trait TryFromU8: Sized {
24 fn try_from(x: u8) -> Result<Self, ()>;
27 impl TryFromU8 for u32 {
28 fn try_from(x: u8) -> Result<Self, ()> {
33 impl TryIntoU32 for *const u16 {
34 fn try_into(self) -> Result<u32, ()> {
35 Ok(unsafe { *self } as u32)
39 trait FromByteIterator {
40 fn from_iter<T>(iter: T) -> Self
42 T: Iterator<Item = u8>;
45 impl FromByteIterator for Vec<u8> {
46 fn from_iter<T>(iter: T) -> Self
48 T: Iterator<Item = u8>,
55 // test dot-call that will break in 2021 edition
56 let _: u32 = TryIntoU32::try_into(3u8).unwrap();
57 //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
58 //~^^ WARNING this is accepted in the current edition
60 // test associated function call that will break in 2021 edition
61 let _ = <u32 as TryFromU8>::try_from(3u8).unwrap();
62 //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
63 //~^^ WARNING this is accepted in the current edition
65 // test reverse turbofish too
66 let _ = <Vec<u8> as FromByteIterator>::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter());
67 //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
68 //~^^ WARNING this is accepted in the current edition
70 // negative testing lint (this line should *not* emit a warning)
71 let _: u32 = TryFromU8::try_from(3u8).unwrap();
74 let _: u32 = <_ as TryFromU8>::try_from(3u8).unwrap();
75 //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
76 //~^^ WARNING this is accepted in the current edition
79 let _: u32 = TryIntoU32::try_into(*(&3u8)).unwrap();
80 //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
81 //~^^ WARNING this is accepted in the current edition
84 let _: u32 = TryIntoU32::try_into(&3.0).unwrap();
85 //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
86 //~^^ WARNING this is accepted in the current edition
89 let mut_ptr = std::ptr::addr_of_mut!(data);
90 let _: u32 = TryIntoU32::try_into(mut_ptr as *const _).unwrap();
91 //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
92 //~^^ WARNING this is accepted in the current edition
95 let _ = <U32Alias as TryFromU8>::try_from(3u8).unwrap();
96 //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
97 //~^^ WARNING this is accepted in the current edition