From acd3542b8d4cf9b4bc1cf6c99f76bb2fb938fe20 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 19 Aug 2023 18:47:08 +0000 Subject: [PATCH] Don't do intra-pass validation on MIR shims --- compiler/rustc_mir_transform/src/shim.rs | 6 +++++- .../auxiliary/drop-shim-relates-opaque-aux.rs | 21 +++++++++++++++++++ .../drop-shim-relates-opaque-issue-114375.rs | 10 +++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs create mode 100644 tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 5e8ba4f544c..603a829412b 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -90,7 +90,11 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<' }; debug!("make_shim({:?}) = untransformed {:?}", instance, result); - pm::run_passes( + // We don't validate MIR here because the shims may generate code that's + // only valid in a reveal-all param-env. However, since we do initial + // validation with the MirBuilt phase, which uses a user-facing param-env. + // This causes validation errors when TAITs are involved. + pm::run_passes_no_validate( tcx, &mut result, &[ diff --git a/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs new file mode 100644 index 00000000000..54a22510066 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs @@ -0,0 +1,21 @@ +// crate foo + +#![feature(type_alias_impl_trait)] + +type Tait = impl Sized; +fn _constrain() -> Tait {} + +struct WrapperWithDrop(T); +impl Drop for WrapperWithDrop { + fn drop(&mut self) {} +} + +pub struct Foo(WrapperWithDrop); + +trait Id { + type Id: ?Sized; +} +impl Id for T { + type Id = T; +} +pub struct Bar(WrapperWithDrop<::Id>); diff --git a/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs b/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs new file mode 100644 index 00000000000..51d28704972 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/drop-shim-relates-opaque-issue-114375.rs @@ -0,0 +1,10 @@ +// aux-build:drop-shim-relates-opaque-aux.rs +// compile-flags: -Zvalidate-mir --crate-type=lib +// build-pass + +extern crate drop_shim_relates_opaque_aux; + +pub fn drop_foo(_: drop_shim_relates_opaque_aux::Foo) {} +pub fn drop_bar(_: drop_shim_relates_opaque_aux::Bar) {} + +fn main() {}