mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #152392 - TaKO8Ki:missing-generics-in-traits-used-in-const, r=jieyouxu
Fix ICE in supertrait_vtable_slot when supertrait has missing generics Fixes rust-lang/rust#151330
This commit is contained in:
@@ -430,7 +430,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) {
|
||||
|
||||
@@ -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`
|
||||
|
||||
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() {}
|
||||
@@ -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`.
|
||||
Reference in New Issue
Block a user