fix #105788, Remove unreasonable help message for auto trait

This commit is contained in:
yukang 2022-12-17 08:20:46 +08:00
parent 58f5a0180c
commit 90753de099
4 changed files with 9 additions and 14 deletions

View File

@ -943,6 +943,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}); });
} else { } else {
debug_assert!(self.tcx.is_trait(trait_def_id)); 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) { for item in self.impl_or_trait_item(trait_def_id) {
// Check whether `trait_def_id` defines a method with suitable name. // Check whether `trait_def_id` defines a method with suitable name.
if !self.has_applicable_self(&item) { if !self.has_applicable_self(&item) {

View File

@ -2306,6 +2306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => false, _ => false,
} }
}) && (type_is_local || info.def_id.is_local()) }) && (type_is_local || info.def_id.is_local())
&& !self.tcx.trait_is_auto(info.def_id)
&& self && self
.associated_value(info.def_id, item_name) .associated_value(info.def_id, item_name)
.filter(|item| { .filter(|item| {

View File

@ -6,7 +6,8 @@ auto trait Foo {
trait Bar { trait Bar {
fn f(&self) { 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
} }
} }

View File

@ -6,21 +6,11 @@ LL | auto trait Foo {
LL | fn g(&self); LL | fn g(&self);
| ---^-------- help: remove these associated items | ---^-------- help: remove these associated items
error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied error[E0599]: no method named `g` found for reference `&Self` in the current scope
--> $DIR/issue-105732.rs:9:14 --> $DIR/issue-105732.rs:10:14
| |
LL | self.g(); LL | self.g();
| ^ | ^ help: there is a method with a similar name: `f`
|
= 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 {
| +++++
error: aborting due to 2 previous errors error: aborting due to 2 previous errors