Skip to content

Remove unreasonable help message for auto trait #105817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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