diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index b9e7830bf0792..a55ab2f54ad37 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -943,6 +943,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }); } else { debug_assert!(self.tcx.is_trait(trait_def_id)); + if self.tcx.trait_is_auto(trait_def_id) { + return; + } for item in self.impl_or_trait_item(trait_def_id) { // Check whether `trait_def_id` defines a method with suitable name. if !self.has_applicable_self(&item) { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 7c5a9a333feba..aa68929517842 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -2306,6 +2306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => false, } }) && (type_is_local || info.def_id.is_local()) + && !self.tcx.trait_is_auto(info.def_id) && self .associated_value(info.def_id, item_name) .filter(|item| { diff --git a/src/test/ui/methods/issues/issue-105732.rs b/src/test/ui/methods/issues/issue-105732.rs index 98b7a8d0d04eb..d7005065813a8 100644 --- a/src/test/ui/methods/issues/issue-105732.rs +++ b/src/test/ui/methods/issues/issue-105732.rs @@ -6,7 +6,8 @@ auto trait Foo { trait Bar { fn f(&self) { - self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied + // issue #105788 + self.g(); //~ ERROR no method named `g` found for reference `&Self` in the current scope } } diff --git a/src/test/ui/methods/issues/issue-105732.stderr b/src/test/ui/methods/issues/issue-105732.stderr index fb2bdf47de7e5..7696642548dfe 100644 --- a/src/test/ui/methods/issues/issue-105732.stderr +++ b/src/test/ui/methods/issues/issue-105732.stderr @@ -6,21 +6,11 @@ LL | auto trait Foo { LL | fn g(&self); | ---^-------- help: remove these associated items -error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied - --> $DIR/issue-105732.rs:9:14 +error[E0599]: no method named `g` found for reference `&Self` in the current scope + --> $DIR/issue-105732.rs:10:14 | LL | self.g(); - | ^ - | - = note: the following trait bounds were not satisfied: - `Self: Foo` - which is required by `&Self: Foo` - `&Self: Foo` - = help: items from traits can only be used if the type parameter is bounded by the trait -help: the following trait defines an item `g`, perhaps you need to add a supertrait for it: - | -LL | trait Bar: Foo { - | +++++ + | ^ help: there is a method with a similar name: `f` error: aborting due to 2 previous errors