Skip to content

Commit 3f6250a

Browse files
committed
Auto merge of #152738 - workingjubilee:revert-unsound-ice-patch, r=mati865
Revert "Fix an ICE in the vtable iteration for a trait reference" The ICE fix appears to be unsound, causing a miscompilation involving `dyn Trait` and `async {}` which induces segfaults in safe Rust code. As the patch only hid an ICE, it does not seem worth the risk. This addresses the problem in #152735 but it may still merit team discussion even if this PR is merged. This reverts commit 8afd636, reversing changes made to 19122c0.
2 parents 1210e9f + 18a707f commit 3f6250a

File tree

8 files changed

+35
-88
lines changed

8 files changed

+35
-88
lines changed

compiler/rustc_trait_selection/src/traits/vtable.rs

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

15-
use crate::traits::is_vtable_safe_method;
15+
use crate::traits::{impossible_predicates, is_vtable_safe_method};
1616

1717
#[derive(Clone, Debug)]
1818
pub enum VtblSegment<'tcx> {
@@ -276,7 +276,11 @@ 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-
if tcx.instantiate_and_check_impossible_predicates((def_id, args)) {
279+
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, args);
280+
if impossible_predicates(
281+
tcx,
282+
predicates.map(|(predicate, _)| predicate).collect(),
283+
) {
280284
debug!("vtable_entries: predicates do not hold");
281285
return VtblEntry::Vacant;
282286
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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
1+
//@ known-bug: #135470
62
//@ compile-flags: -Copt-level=0
73
//@ edition: 2021
84

tests/crashes/137190-2.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ known-bug: #137190
2+
trait Supertrait<T> {
3+
fn method(&self) {}
4+
}
5+
6+
trait Trait<P>: Supertrait<()> {}
7+
8+
impl<P> Trait<P> for () {}
9+
10+
const fn upcast<P>(x: &dyn Trait<P>) -> &dyn Supertrait<()> {
11+
x
12+
}
13+
14+
const fn foo() -> &'static dyn Supertrait<()> {
15+
upcast::<()>(&())
16+
}
17+
18+
const _: &'static dyn Supertrait<()> = foo();

tests/crashes/137190-3.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ known-bug: #137190
2+
trait Supertrait {
3+
fn method(&self) {}
4+
}
5+
6+
trait Trait: Supertrait {}
7+
8+
impl Trait for () {}
9+
10+
const _: &dyn Supertrait = &() as &dyn Trait as &dyn Supertrait;

tests/ui/coercion/vtable-unsatisfied-supertrait-generics.rs

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

tests/ui/coercion/vtable-unsatisfied-supertrait-generics.stderr

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

tests/ui/coercion/vtable-unsatisfied-supertrait.rs

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

tests/ui/coercion/vtable-unsatisfied-supertrait.stderr

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

0 commit comments

Comments
 (0)