diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index fb59955849057..ace114f1ffa01 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1329,6 +1329,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { mutbl: hir::Mutability, track_unstable_candidates: bool, ) -> Result<(), MethodError<'tcx>> { + // The errors emitted by this function are part of + // the arbitrary self types work, and should not impact + // other users. + if !self.tcx.features().arbitrary_self_types() + && !self.tcx.features().arbitrary_self_types_pointers() + { + return Ok(()); + } + // We don't want to remember any of the diagnostic hints from this // shadow search, but we do need to provide Some/None for the // unstable_candidates in order to reflect the behavior of the diff --git a/tests/ui/self/arbitrary_self_types_pin_getref.feature.stderr b/tests/ui/self/arbitrary_self_types_pin_getref.feature.stderr new file mode 100644 index 0000000000000..52cf69f33a54b --- /dev/null +++ b/tests/ui/self/arbitrary_self_types_pin_getref.feature.stderr @@ -0,0 +1,16 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/arbitrary_self_types_pin_getref.rs:23:22 + | +LL | let _ = pinned_a.get_ref(); + | ^^^^^^^ multiple `get_ref` found + | +note: candidate #1 is defined in an impl for the type `A` + --> $DIR/arbitrary_self_types_pin_getref.rs:17:5 + | +LL | fn get_ref(self: &Pin<&A>) {} // note &Pin + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: candidate #2 is defined in an impl for the type `Pin<&'a T>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/self/arbitrary_self_types_pin_getref.rs b/tests/ui/self/arbitrary_self_types_pin_getref.rs new file mode 100644 index 0000000000000..29dd907f7ff00 --- /dev/null +++ b/tests/ui/self/arbitrary_self_types_pin_getref.rs @@ -0,0 +1,25 @@ +// Confirms that Pin::get_ref can no longer shadow methods in pointees +// once arbitrary_self_types is enabled. +// +//@ revisions: default feature +#![cfg_attr(feature, feature(arbitrary_self_types))] + +//@[default] check-pass + +#![allow(dead_code)] + +use std::pin::Pin; +use std::pin::pin; + +struct A; + +impl A { + fn get_ref(self: &Pin<&A>) {} // note &Pin +} + +fn main() { + let pinned_a: Pin<&mut A> = pin!(A); + let pinned_a: Pin<&A> = pinned_a.as_ref(); + let _ = pinned_a.get_ref(); + //[feature]~^ ERROR: multiple applicable items +}