diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-12-27 16:37:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-27 16:37:47 +0100 |
| commit | a0bf4f9b721d7f8cb30cda1bd69491c10a1054db (patch) | |
| tree | 03f1b337850d9ae0d72fc3827b39cd920304acb5 | |
| parent | a1fc71196a5554eafc5dd9a1b4e0c159717141e0 (diff) | |
| parent | 90753de099c2e3b2e7d2f84e7ca553a1e987d9ed (diff) | |
| download | rust-a0bf4f9b721d7f8cb30cda1bd69491c10a1054db.tar.gz rust-a0bf4f9b721d7f8cb30cda1bd69491c10a1054db.zip | |
Rollup merge of #105817 - chenyukang:yukang/fix-105788-sugg-for-auto-trait, r=TaKO8Ki
Remove unreasonable help message for auto trait Fixes #105788
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/probe.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/suggest.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/methods/issues/issue-105732.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/methods/issues/issue-105732.stderr | 16 |
4 files changed, 9 insertions, 14 deletions
diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 6b3fa664d9c..1afaae0e020 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -973,6 +973,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 7c5a9a333fe..aa689295178 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 98b7a8d0d04..d7005065813 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 fb2bdf47de7..7696642548d 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 |
