Skip to content

Commit cc04e97

Browse files
authored
Rollup merge of #105747 - chenyukang:yukang/fix-105732-auto-trait, r=compiler-errors
Fix ICE calling method on auto trait Fixes #105732 r? `@compiler-errors`
2 parents 3b9aea9 + 605f77b commit cc04e97

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+10
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
689689
let entry = spanned_predicates.entry(spans);
690690
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
691691
}
692+
Some(Node::Item(hir::Item {
693+
kind: hir::ItemKind::Trait(rustc_ast::ast::IsAuto::Yes, ..),
694+
span: item_span,
695+
..
696+
})) => {
697+
tcx.sess.delay_span_bug(
698+
*item_span,
699+
"auto trait is invoked with no method error, but no error reported?",
700+
);
701+
}
692702
Some(_) => unreachable!(),
693703
None => (),
694704
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(auto_traits)]
2+
3+
auto trait Foo {
4+
fn g(&self); //~ ERROR auto traits cannot have associated items
5+
}
6+
7+
trait Bar {
8+
fn f(&self) {
9+
self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
10+
}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error[E0380]: auto traits cannot have associated items
2+
--> $DIR/issue-105732.rs:4:8
3+
|
4+
LL | auto trait Foo {
5+
| --- auto trait cannot have associated items
6+
LL | fn g(&self);
7+
| ---^-------- help: remove these associated items
8+
9+
error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
10+
--> $DIR/issue-105732.rs:9:14
11+
|
12+
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+
| +++++
24+
25+
error: aborting due to 2 previous errors
26+
27+
Some errors have detailed explanations: E0380, E0599.
28+
For more information about an error, try `rustc --explain E0380`.

0 commit comments

Comments
 (0)