From bf0da4418f061b74b0f3f9e2a2b1310385896355 Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Sun, 27 Jun 2021 00:28:07 -0400 Subject: [PATCH] Fix `future_prelude_collision` false positive --- .../rustc_typeck/src/check/method/prelude2021.rs | 7 +++++++ .../future-prelude-collision-unneeded.rs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/test/ui/rust-2021/future-prelude-collision-unneeded.rs diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index 4c925a6f237..e8748dd062f 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -57,6 +57,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { return; } + + // if it's an inherent `self` method (not `&self` or `&mut self`), it will take + // precedence over the `TryInto` impl, and thus won't break in 2021 edition + if pick.autoderefs == 0 && pick.autoref_or_ptr_adjustment.is_none() { + return; + } + // Inherent impls only require not relying on autoref and autoderef in order to // ensure that the trait implementation won't be used self.tcx.struct_span_lint_hir( diff --git a/src/test/ui/rust-2021/future-prelude-collision-unneeded.rs b/src/test/ui/rust-2021/future-prelude-collision-unneeded.rs new file mode 100644 index 00000000000..a4a5b6667df --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-unneeded.rs @@ -0,0 +1,16 @@ +// edition:2018 +// check-pass +#![allow(unused)] +#![deny(future_prelude_collision)] + +struct S; + +impl S { + fn try_into(self) -> S { S } +} + +// See https://github.com/rust-lang/rust/issues/86633 +fn main() { + let s = S; + let s2 = s.try_into(); +}