Skip to content

Commit 605f77b

Browse files
committed
fix #105732, Fix ICE calling method on auto trait
1 parent 939a3dd commit 605f77b

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
@@ -688,6 +688,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
688688
let entry = spanned_predicates.entry(spans);
689689
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
690690
}
691+
Some(Node::Item(hir::Item {
692+
kind: hir::ItemKind::Trait(rustc_ast::ast::IsAuto::Yes, ..),
693+
span: item_span,
694+
..
695+
})) => {
696+
tcx.sess.delay_span_bug(
697+
*item_span,
698+
"auto trait is invoked with no method error, but no error reported?",
699+
);
700+
}
691701
Some(_) => unreachable!(),
692702
None => (),
693703
}
+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)