From eb5e0af3a990747174fb8ee84fbfe52e57f00ecf Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Thu, 27 May 2021 13:38:06 -0400 Subject: [PATCH] Add autoderef and autoref tests for `future_prelude_collision` lint --- .../ui/lint/future-prelude-collision.fixed | 15 +++++++++++++ src/test/ui/lint/future-prelude-collision.rs | 15 +++++++++++++ .../ui/lint/future-prelude-collision.stderr | 22 ++++++++++++++----- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/test/ui/lint/future-prelude-collision.fixed b/src/test/ui/lint/future-prelude-collision.fixed index 06d0bb01538..6858616adde 100644 --- a/src/test/ui/lint/future-prelude-collision.fixed +++ b/src/test/ui/lint/future-prelude-collision.fixed @@ -12,6 +12,13 @@ impl TryIntoU32 for u8 { } } +// 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; } @@ -54,4 +61,12 @@ fn main() { // test type omission let _: u32 = <_ as TryFromU8>::try_from(3u8).unwrap(); //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + + // test autoderef + let _: u32 = TryIntoU32::try_into(*(&3u8)).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + + // test autoref + let _: u32 = TryIntoU32::try_into(&3.0).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 } diff --git a/src/test/ui/lint/future-prelude-collision.rs b/src/test/ui/lint/future-prelude-collision.rs index 61658ac2725..ba02757ab32 100644 --- a/src/test/ui/lint/future-prelude-collision.rs +++ b/src/test/ui/lint/future-prelude-collision.rs @@ -12,6 +12,13 @@ impl TryIntoU32 for u8 { } } +// 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; } @@ -54,4 +61,12 @@ fn main() { // test type omission let _: u32 = <_>::try_from(3u8).unwrap(); //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + + // test autoderef + let _: u32 = (&3u8).try_into().unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + + // test autoref + let _: u32 = 3.0.try_into().unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 } diff --git a/src/test/ui/lint/future-prelude-collision.stderr b/src/test/ui/lint/future-prelude-collision.stderr index 79f4f1412d2..3a3c04a093d 100644 --- a/src/test/ui/lint/future-prelude-collision.stderr +++ b/src/test/ui/lint/future-prelude-collision.stderr @@ -1,5 +1,5 @@ warning: trait method `try_into` will become ambiguous in Rust 2021 - --> $DIR/future-prelude-collision.rs:40:18 + --> $DIR/future-prelude-collision.rs:47:18 | LL | let _: u32 = 3u8.try_into().unwrap(); | ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)` @@ -7,22 +7,34 @@ LL | let _: u32 = 3u8.try_into().unwrap(); = note: `#[warn(future_prelude_collision)]` on by default warning: trait-associated function `try_from` will become ambiguous in Rust 2021 - --> $DIR/future-prelude-collision.rs:44:13 + --> $DIR/future-prelude-collision.rs:51:13 | LL | let _ = u32::try_from(3u8).unwrap(); | ^^^^^^^^^^^^^ help: disambiguate the associated function: `::try_from` warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 - --> $DIR/future-prelude-collision.rs:48:13 + --> $DIR/future-prelude-collision.rs:55:13 | LL | let _ = >::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter()); | ^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: ` as FromByteIterator>::from_iter` warning: trait-associated function `try_from` will become ambiguous in Rust 2021 - --> $DIR/future-prelude-collision.rs:55:18 + --> $DIR/future-prelude-collision.rs:62:18 | LL | let _: u32 = <_>::try_from(3u8).unwrap(); | ^^^^^^^^^^^^^ help: disambiguate the associated function: `<_ as TryFromU8>::try_from` -warning: 4 warnings emitted +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision.rs:66:18 + | +LL | let _: u32 = (&3u8).try_into().unwrap(); + | ^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(*(&3u8))` + +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision.rs:70:18 + | +LL | let _: u32 = 3.0.try_into().unwrap(); + | ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(&3.0)` + +warning: 6 warnings emitted