Skip to content
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

Fix ICE calling method on auto trait #105747

Merged
merged 1 commit into from
Dec 16, 2022
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
10 changes: 10 additions & 0 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let entry = spanned_predicates.entry(spans);
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
}
Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(rustc_ast::ast::IsAuto::Yes, ..),
span: item_span,
..
})) => {
tcx.sess.delay_span_bug(
*item_span,
"auto trait is invoked with no method error, but no error reported?",
);
}
Some(_) => unreachable!(),
None => (),
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/methods/issues/issue-105732.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(auto_traits)]

auto trait Foo {
fn g(&self); //~ ERROR auto traits cannot have associated items
}

trait Bar {
fn f(&self) {
self.g(); //~ ERROR the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
}
}

fn main() {}
28 changes: 28 additions & 0 deletions src/test/ui/methods/issues/issue-105732.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error[E0380]: auto traits cannot have associated items
--> $DIR/issue-105732.rs:4:8
|
LL | auto trait Foo {
| --- auto trait cannot have associated items
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
|
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 {
| +++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0380, E0599.
For more information about an error, try `rustc --explain E0380`.