2021-05-26 23:30:55 -05:00
|
|
|
// run-rustfix
|
|
|
|
// edition:2018
|
|
|
|
// check-pass
|
2021-07-01 06:35:33 -05:00
|
|
|
#![warn(rust_2021_prelude_collisions)]
|
2021-05-26 23:30:55 -05:00
|
|
|
|
|
|
|
trait TryIntoU32 {
|
|
|
|
fn try_into(self) -> Result<u32, ()>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryIntoU32 for u8 {
|
|
|
|
fn try_into(self) -> Result<u32, ()> {
|
|
|
|
Ok(self as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 12:38:06 -05:00
|
|
|
// needed for autoref test
|
|
|
|
impl TryIntoU32 for &f32 {
|
|
|
|
fn try_into(self) -> Result<u32, ()> {
|
|
|
|
Ok(*self as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:30:55 -05:00
|
|
|
trait TryFromU8: Sized {
|
|
|
|
fn try_from(x: u8) -> Result<Self, ()>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFromU8 for u32 {
|
|
|
|
fn try_from(x: u8) -> Result<Self, ()> {
|
|
|
|
Ok(x as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 21:29:22 -05:00
|
|
|
impl TryIntoU32 for *const u16 {
|
|
|
|
fn try_into(self) -> Result<u32, ()> {
|
|
|
|
Ok(unsafe { *self } as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 23:30:55 -05:00
|
|
|
trait FromByteIterator {
|
|
|
|
fn from_iter<T>(iter: T) -> Self
|
2021-06-24 09:45:19 -05:00
|
|
|
where
|
|
|
|
T: Iterator<Item = u8>;
|
2021-05-26 23:30:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FromByteIterator for Vec<u8> {
|
|
|
|
fn from_iter<T>(iter: T) -> Self
|
2021-06-24 09:45:19 -05:00
|
|
|
where
|
|
|
|
T: Iterator<Item = u8>,
|
2021-05-26 23:30:55 -05:00
|
|
|
{
|
|
|
|
iter.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// test dot-call that will break in 2021 edition
|
|
|
|
let _: u32 = TryIntoU32::try_into(3u8).unwrap();
|
|
|
|
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-26 23:30:55 -05:00
|
|
|
|
|
|
|
// test associated function call that will break in 2021 edition
|
|
|
|
let _ = <u32 as TryFromU8>::try_from(3u8).unwrap();
|
|
|
|
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-26 23:30:55 -05:00
|
|
|
|
|
|
|
// test reverse turbofish too
|
|
|
|
let _ = <Vec<u8> as FromByteIterator>::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter());
|
|
|
|
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-26 23:30:55 -05:00
|
|
|
|
|
|
|
// negative testing lint (this line should *not* emit a warning)
|
|
|
|
let _: u32 = TryFromU8::try_from(3u8).unwrap();
|
|
|
|
|
|
|
|
// test type omission
|
|
|
|
let _: u32 = <_ as TryFromU8>::try_from(3u8).unwrap();
|
|
|
|
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-27 12:38:06 -05:00
|
|
|
|
|
|
|
// test autoderef
|
|
|
|
let _: u32 = TryIntoU32::try_into(*(&3u8)).unwrap();
|
|
|
|
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-27 12:38:06 -05:00
|
|
|
|
|
|
|
// test autoref
|
|
|
|
let _: u32 = TryIntoU32::try_into(&3.0).unwrap();
|
|
|
|
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-27 21:29:22 -05:00
|
|
|
|
|
|
|
let mut data = 3u16;
|
|
|
|
let mut_ptr = std::ptr::addr_of_mut!(data);
|
|
|
|
let _: u32 = TryIntoU32::try_into(mut_ptr as *const _).unwrap();
|
|
|
|
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-27 22:39:07 -05:00
|
|
|
|
|
|
|
type U32Alias = u32;
|
|
|
|
let _ = <U32Alias as TryFromU8>::try_from(3u8).unwrap();
|
|
|
|
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
|
2021-06-24 09:45:19 -05:00
|
|
|
//~^^ WARNING this is accepted in the current edition
|
2021-05-26 23:30:55 -05:00
|
|
|
}
|