From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/rust-2021/future-prelude-collision.fixed | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/test/ui/rust-2021/future-prelude-collision.fixed (limited to 'src/test/ui/rust-2021/future-prelude-collision.fixed') diff --git a/src/test/ui/rust-2021/future-prelude-collision.fixed b/src/test/ui/rust-2021/future-prelude-collision.fixed new file mode 100644 index 000000000..43b0ec1c3 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision.fixed @@ -0,0 +1,98 @@ +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] + +trait TryIntoU32 { + fn try_into(self) -> Result; +} + +impl TryIntoU32 for u8 { + fn try_into(self) -> Result { + Ok(self as u32) + } +} + +// needed for autoref test +impl TryIntoU32 for &f32 { + fn try_into(self) -> Result { + Ok(*self as u32) + } +} + +trait TryFromU8: Sized { + fn try_from(x: u8) -> Result; +} + +impl TryFromU8 for u32 { + fn try_from(x: u8) -> Result { + Ok(x as u32) + } +} + +impl TryIntoU32 for *const u16 { + fn try_into(self) -> Result { + Ok(unsafe { *self } as u32) + } +} + +trait FromByteIterator { + fn from_iter(iter: T) -> Self + where + T: Iterator; +} + +impl FromByteIterator for Vec { + fn from_iter(iter: T) -> Self + where + T: Iterator, + { + 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 + //~^^ WARNING this is accepted in the current edition + + // test associated function call that will break in 2021 edition + let _ = ::try_from(3u8).unwrap(); + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + + // test reverse turbofish too + let _ = 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 + //~^^ WARNING this is accepted in the current edition + + // 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 + //~^^ WARNING this is accepted in the current edition + + // test autoderef + let _: u32 = TryIntoU32::try_into(*(&3u8)).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + + // test autoref + let _: u32 = TryIntoU32::try_into(&3.0).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + + 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 + //~^^ WARNING this is accepted in the current edition + + type U32Alias = u32; + let _ = ::try_from(3u8).unwrap(); + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition +} -- cgit v1.2.3