Skip to content
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
11 changes: 10 additions & 1 deletion compiler/rustc_trait_selection/src/traits/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,16 @@ pub(crate) fn supertrait_vtable_slot<'tcx>(
}
};

prepare_vtable_segments(tcx, source_principal, vtable_segment_callback).unwrap()
prepare_vtable_segments(tcx, source_principal, vtable_segment_callback).unwrap_or_else(|| {
// This can happen if the trait hierarchy is malformed (e.g., due to
// missing generics on a supertrait bound). There should already be an error
// emitted for this, so we just delay the ICE.
tcx.dcx().delayed_bug(format!(
"could not find the supertrait vtable slot for `{}` -> `{}`",
source, target
));
None
})
}

pub(super) fn provide(providers: &mut Providers) {
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/traits/vtable/missing-generics-issue-151330.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ compile-flags: -Znext-solver=globally
// Regression test for issue https://github.com/rust-lang/rust/issues/151330

trait Supertrait<T> {}

trait Trait<P>: Supertrait {}
//~^ ERROR missing generics for trait `Supertrait`
//~| ERROR missing generics for trait `Supertrait`
//~| ERROR missing generics for trait `Supertrait`
Comment on lines +6 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: hm, emitting this multiple times is curious (I'm aware ui tests use -Zdeduplicate-diagnostics=no)


impl<P> Trait<P> for () {}

const fn upcast<P>(x: &dyn Trait<P>) -> &dyn Trait<P> {
x
}

const fn foo() -> &'static dyn Supertrait<()> {
upcast::<()>(&())
}

const _: &'static dyn Supertrait<()> = foo();

fn main() {}
53 changes: 53 additions & 0 deletions tests/ui/traits/vtable/missing-generics-issue-151330.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
error[E0107]: missing generics for trait `Supertrait`
--> $DIR/missing-generics-issue-151330.rs:6:17
|
LL | trait Trait<P>: Supertrait {}
| ^^^^^^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/missing-generics-issue-151330.rs:4:7
|
LL | trait Supertrait<T> {}
| ^^^^^^^^^^ -
help: add missing generic argument
|
LL | trait Trait<P>: Supertrait<T> {}
| +++

error[E0107]: missing generics for trait `Supertrait`
--> $DIR/missing-generics-issue-151330.rs:6:17
|
LL | trait Trait<P>: Supertrait {}
| ^^^^^^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/missing-generics-issue-151330.rs:4:7
|
LL | trait Supertrait<T> {}
| ^^^^^^^^^^ -
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: add missing generic argument
|
LL | trait Trait<P>: Supertrait<T> {}
| +++

error[E0107]: missing generics for trait `Supertrait`
--> $DIR/missing-generics-issue-151330.rs:6:17
|
LL | trait Trait<P>: Supertrait {}
| ^^^^^^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/missing-generics-issue-151330.rs:4:7
|
LL | trait Supertrait<T> {}
| ^^^^^^^^^^ -
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: add missing generic argument
|
LL | trait Trait<P>: Supertrait<T> {}
| +++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0107`.
Loading