Skip to content

Commit a0bf4f9

Browse files
authored
Rollup merge of #105817 - chenyukang:yukang/fix-105788-sugg-for-auto-trait, r=TaKO8Ki
Remove unreasonable help message for auto trait Fixes #105788
2 parents a1fc711 + 90753de commit a0bf4f9

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+3
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
973973
});
974974
} else {
975975
debug_assert!(self.tcx.is_trait(trait_def_id));
976+
if self.tcx.trait_is_auto(trait_def_id) {
977+
return;
978+
}
976979
for item in self.impl_or_trait_item(trait_def_id) {
977980
// Check whether `trait_def_id` defines a method with suitable name.
978981
if !self.has_applicable_self(&item) {

compiler/rustc_hir_typeck/src/method/suggest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23062306
_ => false,
23072307
}
23082308
}) && (type_is_local || info.def_id.is_local())
2309+
&& !self.tcx.trait_is_auto(info.def_id)
23092310
&& self
23102311
.associated_value(info.def_id, item_name)
23112312
.filter(|item| {

src/test/ui/methods/issues/issue-105732.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ auto trait Foo {
66

77
trait Bar {
88
fn f(&self) {
9-
self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
9+
// issue #105788
10+
self.g(); //~ ERROR no method named `g` found for reference `&Self` in the current scope
1011
}
1112
}
1213

src/test/ui/methods/issues/issue-105732.stderr

+3-13
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,11 @@ LL | auto trait Foo {
66
LL | fn g(&self);
77
| ---^-------- help: remove these associated items
88

9-
error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
10-
--> $DIR/issue-105732.rs:9:14
9+
error[E0599]: no method named `g` found for reference `&Self` in the current scope
10+
--> $DIR/issue-105732.rs:10:14
1111
|
1212
LL | self.g();
13-
| ^
14-
|
15-
= note: the following trait bounds were not satisfied:
16-
`Self: Foo`
17-
which is required by `&Self: Foo`
18-
`&Self: Foo`
19-
= help: items from traits can only be used if the type parameter is bounded by the trait
20-
help: the following trait defines an item `g`, perhaps you need to add a supertrait for it:
21-
|
22-
LL | trait Bar: Foo {
23-
| +++++
13+
| ^ help: there is a method with a similar name: `f`
2414

2515
error: aborting due to 2 previous errors
2616

0 commit comments

Comments
 (0)