Skip to content

Commit 730bc39

Browse files
Rollup merge of #156417 - jakubadamw:issue-137190-reapplied, r=lcnr
Fix an ICE in the vtable iteration for a trait reference in const eval when a supertrait is not implemented This is a second incarnation of #152287, which was reverted in #152738 as it had exposed another underlying unsoundness (#153596, exhibited indirectly in #152735), which was recently fixed in #155749. It’s the same fix and the same set of tests. Regression tests for the unsoundness itself were already added in #155749. Closes #137190. Closes #135470.
2 parents b97c8ef + 3541645 commit 730bc39

8 files changed

Lines changed: 88 additions & 35 deletions

compiler/rustc_trait_selection/src/traits/vtable.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::DUMMY_SP;
1313
use smallvec::{SmallVec, smallvec};
1414
use tracing::debug;
1515

16-
use crate::traits::{impossible_predicates, is_vtable_safe_method};
16+
use crate::traits::is_vtable_safe_method;
1717

1818
#[derive(Clone, Debug)]
1919
pub enum VtblSegment<'tcx> {
@@ -276,11 +276,7 @@ fn vtable_entries<'tcx>(
276276
// do not hold for this particular set of type parameters.
277277
// Note that this method could then never be called, so we
278278
// do not want to try and codegen it, in that case (see #23435).
279-
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, args);
280-
if impossible_predicates(
281-
tcx,
282-
predicates.map(|(predicate, _)| predicate.skip_norm_wip()).collect(),
283-
) {
279+
if tcx.instantiate_and_check_impossible_predicates((def_id, args)) {
284280
debug!("vtable_entries: predicates do not hold");
285281
return VtblEntry::Vacant;
286282
}

tests/crashes/137190-2.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/crashes/137190-3.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/crashes/135470.rs renamed to tests/ui/coercion/vtable-impossible-predicates-async.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
//@ known-bug: #135470
1+
// Regression test for #135470.
2+
// Verify that we don't ICE when building vtable entries
3+
// for a blanket impl involving async and impossible predicates.
4+
5+
//@ check-pass
26
//@ compile-flags: -Copt-level=0
37
//@ edition: 2021
48

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Regression test for #137190.
2+
// Variant of vtable-unsatisfied-supertrait.rs with generic traits.
3+
// Verify that we don't ICE when building vtable entries
4+
// for a generic trait whose supertrait is not implemented.
5+
6+
//@ compile-flags: --crate-type lib
7+
8+
trait Supertrait<T> {
9+
fn method(&self) {}
10+
}
11+
12+
trait Trait<P>: Supertrait<()> {}
13+
14+
impl<P> Trait<P> for () {}
15+
//~^ ERROR the trait bound `(): Supertrait<()>` is not satisfied
16+
17+
const fn upcast<P>(x: &dyn Trait<P>) -> &dyn Supertrait<()> {
18+
x
19+
}
20+
21+
const fn foo() -> &'static dyn Supertrait<()> {
22+
upcast::<()>(&())
23+
}
24+
25+
const _: &'static dyn Supertrait<()> = foo();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `(): Supertrait<()>` is not satisfied
2+
--> $DIR/vtable-unsatisfied-supertrait-generics.rs:14:22
3+
|
4+
LL | impl<P> Trait<P> for () {}
5+
| ^^ the trait `Supertrait<()>` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/vtable-unsatisfied-supertrait-generics.rs:8:1
9+
|
10+
LL | trait Supertrait<T> {
11+
| ^^^^^^^^^^^^^^^^^^^
12+
note: required by a bound in `Trait`
13+
--> $DIR/vtable-unsatisfied-supertrait-generics.rs:12:17
14+
|
15+
LL | trait Trait<P>: Supertrait<()> {}
16+
| ^^^^^^^^^^^^^^ required by this bound in `Trait`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for #137190.
2+
// Verify that we don't ICE when building vtable entries
3+
// for a trait whose supertrait is not implemented.
4+
5+
//@ compile-flags: --crate-type lib
6+
7+
trait Supertrait {
8+
fn method(&self) {}
9+
}
10+
11+
trait Trait: Supertrait {}
12+
13+
impl Trait for () {}
14+
//~^ ERROR the trait bound `(): Supertrait` is not satisfied
15+
16+
const _: &dyn Supertrait = &() as &dyn Trait as &dyn Supertrait;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `(): Supertrait` is not satisfied
2+
--> $DIR/vtable-unsatisfied-supertrait.rs:13:16
3+
|
4+
LL | impl Trait for () {}
5+
| ^^ the trait `Supertrait` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/vtable-unsatisfied-supertrait.rs:7:1
9+
|
10+
LL | trait Supertrait {
11+
| ^^^^^^^^^^^^^^^^
12+
note: required by a bound in `Trait`
13+
--> $DIR/vtable-unsatisfied-supertrait.rs:11:14
14+
|
15+
LL | trait Trait: Supertrait {}
16+
| ^^^^^^^^^^ required by this bound in `Trait`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)