diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 825c06883a54..539c1d3a35ba 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -12,7 +12,7 @@ use rustc_span::DUMMY_SP; use smallvec::{SmallVec, smallvec}; use tracing::debug; -use crate::traits::is_vtable_safe_method; +use crate::traits::{impossible_predicates, is_vtable_safe_method}; #[derive(Clone, Debug)] pub enum VtblSegment<'tcx> { @@ -271,7 +271,11 @@ fn vtable_entries<'tcx>( // do not hold for this particular set of type parameters. // Note that this method could then never be called, so we // do not want to try and codegen it, in that case (see #23435). - if tcx.instantiate_and_check_impossible_predicates((def_id, args)) { + let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, args); + if impossible_predicates( + tcx, + predicates.map(|(predicate, _)| predicate).collect(), + ) { debug!("vtable_entries: predicates do not hold"); return VtblEntry::Vacant; } diff --git a/tests/ui/coercion/vtable-impossible-predicates-async.rs b/tests/crashes/135470.rs similarity index 79% rename from tests/ui/coercion/vtable-impossible-predicates-async.rs rename to tests/crashes/135470.rs index fe6aa9843fc6..efa017b5457c 100644 --- a/tests/ui/coercion/vtable-impossible-predicates-async.rs +++ b/tests/crashes/135470.rs @@ -1,8 +1,4 @@ -// Regression test for #135470. -// Verify that we don't ICE when building vtable entries -// for a blanket impl involving async and impossible predicates. - -//@ check-pass +//@ known-bug: #135470 //@ compile-flags: -Copt-level=0 //@ edition: 2021 diff --git a/tests/crashes/137190-2.rs b/tests/crashes/137190-2.rs new file mode 100644 index 000000000000..0c68b5aa4a51 --- /dev/null +++ b/tests/crashes/137190-2.rs @@ -0,0 +1,18 @@ +//@ known-bug: #137190 +trait Supertrait { + fn method(&self) {} +} + +trait Trait

: Supertrait<()> {} + +impl

Trait

for () {} + +const fn upcast

(x: &dyn Trait

) -> &dyn Supertrait<()> { + x +} + +const fn foo() -> &'static dyn Supertrait<()> { + upcast::<()>(&()) +} + +const _: &'static dyn Supertrait<()> = foo(); diff --git a/tests/crashes/137190-3.rs b/tests/crashes/137190-3.rs new file mode 100644 index 000000000000..88ae88e11bcd --- /dev/null +++ b/tests/crashes/137190-3.rs @@ -0,0 +1,10 @@ +//@ known-bug: #137190 +trait Supertrait { + fn method(&self) {} +} + +trait Trait: Supertrait {} + +impl Trait for () {} + +const _: &dyn Supertrait = &() as &dyn Trait as &dyn Supertrait; diff --git a/tests/ui/coercion/vtable-unsatisfied-supertrait-generics.rs b/tests/ui/coercion/vtable-unsatisfied-supertrait-generics.rs deleted file mode 100644 index 41e603fc0a0a..000000000000 --- a/tests/ui/coercion/vtable-unsatisfied-supertrait-generics.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Regression test for #137190. -// Variant of vtable-unsatisfied-supertrait.rs with generic traits. -// Verify that we don't ICE when building vtable entries -// for a generic trait whose supertrait is not implemented. - -//@ compile-flags: --crate-type lib - -trait Supertrait { - fn method(&self) {} -} - -trait Trait

: Supertrait<()> {} - -impl

Trait

for () {} -//~^ ERROR the trait bound `(): Supertrait<()>` is not satisfied - -const fn upcast

(x: &dyn Trait

) -> &dyn Supertrait<()> { - x -} - -const fn foo() -> &'static dyn Supertrait<()> { - upcast::<()>(&()) -} - -const _: &'static dyn Supertrait<()> = foo(); diff --git a/tests/ui/coercion/vtable-unsatisfied-supertrait-generics.stderr b/tests/ui/coercion/vtable-unsatisfied-supertrait-generics.stderr deleted file mode 100644 index a485d2d53953..000000000000 --- a/tests/ui/coercion/vtable-unsatisfied-supertrait-generics.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0277]: the trait bound `(): Supertrait<()>` is not satisfied - --> $DIR/vtable-unsatisfied-supertrait-generics.rs:14:22 - | -LL | impl

Trait

for () {} - | ^^ the trait `Supertrait<()>` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/vtable-unsatisfied-supertrait-generics.rs:8:1 - | -LL | trait Supertrait { - | ^^^^^^^^^^^^^^^^^^^ -note: required by a bound in `Trait` - --> $DIR/vtable-unsatisfied-supertrait-generics.rs:12:17 - | -LL | trait Trait

: Supertrait<()> {} - | ^^^^^^^^^^^^^^ required by this bound in `Trait` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/coercion/vtable-unsatisfied-supertrait.rs b/tests/ui/coercion/vtable-unsatisfied-supertrait.rs deleted file mode 100644 index 26a83d2fb066..000000000000 --- a/tests/ui/coercion/vtable-unsatisfied-supertrait.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Regression test for #137190. -// Verify that we don't ICE when building vtable entries -// for a trait whose supertrait is not implemented. - -//@ compile-flags: --crate-type lib - -trait Supertrait { - fn method(&self) {} -} - -trait Trait: Supertrait {} - -impl Trait for () {} -//~^ ERROR the trait bound `(): Supertrait` is not satisfied - -const _: &dyn Supertrait = &() as &dyn Trait as &dyn Supertrait; diff --git a/tests/ui/coercion/vtable-unsatisfied-supertrait.stderr b/tests/ui/coercion/vtable-unsatisfied-supertrait.stderr deleted file mode 100644 index 7df2c95c7fac..000000000000 --- a/tests/ui/coercion/vtable-unsatisfied-supertrait.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0277]: the trait bound `(): Supertrait` is not satisfied - --> $DIR/vtable-unsatisfied-supertrait.rs:13:16 - | -LL | impl Trait for () {} - | ^^ the trait `Supertrait` is not implemented for `()` - | -help: this trait has no implementations, consider adding one - --> $DIR/vtable-unsatisfied-supertrait.rs:7:1 - | -LL | trait Supertrait { - | ^^^^^^^^^^^^^^^^ -note: required by a bound in `Trait` - --> $DIR/vtable-unsatisfied-supertrait.rs:11:14 - | -LL | trait Trait: Supertrait {} - | ^^^^^^^^^^ required by this bound in `Trait` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`.