Skip to content

Commit

Permalink
fix #105788, Remove unreasonable help message for auto trait
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Dec 27, 2022
1 parent 58f5a01 commit 90753de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/methods/issues/issue-105732.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
16 changes: 3 additions & 13 deletions src/test/ui/methods/issues/issue-105732.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 90753de

Please sign in to comment.