Skip to content

Commit c469197

Browse files
committed
Auto merge of #115005 - compiler-errors:passes, r=cjgillot
Don't do intra-pass validation on MIR shims Fixes #114375 In the test that was committed, we end up generating the drop shim for `struct Foo` that looks like: ``` fn std::ptr::drop_in_place(_1: *mut Foo) -> () { let mut _0: (); bb0: { goto -> bb5; } bb1: { return; } bb2 (cleanup): { resume; } bb3: { goto -> bb1; } bb4 (cleanup): { drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb2, unwind terminate]; } bb5: { drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb3, unwind: bb2]; } } ``` In `bb4` and `bb5`, we assert that `(*_1).0` has type `WrapperWithDrop<()>`. However, In a user-facing param env, the type is actually `WrapperWithDrop<Tait>`. These types are not equal in a user-facing param-env (and can't be made equal even if we use `DefiningAnchor::Bubble`, since it's a non-local TAIT).
2 parents 154ae32 + acd3542 commit c469197

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

compiler/rustc_mir_transform/src/shim.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
9999
};
100100
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
101101

102-
pm::run_passes(
102+
// We don't validate MIR here because the shims may generate code that's
103+
// only valid in a reveal-all param-env. However, since we do initial
104+
// validation with the MirBuilt phase, which uses a user-facing param-env.
105+
// This causes validation errors when TAITs are involved.
106+
pm::run_passes_no_validate(
103107
tcx,
104108
&mut result,
105109
&[
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// crate foo
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
type Tait = impl Sized;
6+
fn _constrain() -> Tait {}
7+
8+
struct WrapperWithDrop<T>(T);
9+
impl<T> Drop for WrapperWithDrop<T> {
10+
fn drop(&mut self) {}
11+
}
12+
13+
pub struct Foo(WrapperWithDrop<Tait>);
14+
15+
trait Id {
16+
type Id: ?Sized;
17+
}
18+
impl<T: ?Sized> Id for T {
19+
type Id = T;
20+
}
21+
pub struct Bar(WrapperWithDrop<<Tait as Id>::Id>);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:drop-shim-relates-opaque-aux.rs
2+
// compile-flags: -Zvalidate-mir --crate-type=lib
3+
// build-pass
4+
5+
extern crate drop_shim_relates_opaque_aux;
6+
7+
pub fn drop_foo(_: drop_shim_relates_opaque_aux::Foo) {}
8+
pub fn drop_bar(_: drop_shim_relates_opaque_aux::Bar) {}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)