diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index c50a490a9dc0c..cc4f69744e57f 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -7,7 +7,7 @@ use rustc_middle::query::Providers; use rustc_middle::traits::{BuiltinImplSource, CodegenObligationError}; use rustc_middle::ty::util::AsyncDropGlueMorphology; use rustc_middle::ty::GenericArgsRef; -use rustc_middle::ty::{self, Instance, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, Instance, TyCtxt, TypeFlags, TypeVisitableExt}; use rustc_span::sym; use rustc_trait_selection::traits; use rustc_type_ir::ClosureKind; @@ -53,6 +53,15 @@ fn resolve_instance<'tcx>( _ => return Ok(None), } + // FIXME(#127030): `ConstParamHasTy` has bad interactions with + // the drop shim builder, which does not evaluate predicates in + // the correct param-env for types being dropped. Stall resolving + // the MIR for this instance until all of its const params are + // substituted. + if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) { + return Ok(None); + } + ty::InstanceKind::DropGlue(def_id, Some(ty)) } else { debug!(" => trivial drop glue"); diff --git a/tests/ui/const-generics/polymorphic-drop-shim.rs b/tests/ui/const-generics/polymorphic-drop-shim.rs new file mode 100644 index 0000000000000..4ca2e86cff915 --- /dev/null +++ b/tests/ui/const-generics/polymorphic-drop-shim.rs @@ -0,0 +1,18 @@ +//@ compile-flags: -Zinline-mir=yes --crate-type=lib +//@ build-pass + +use std::mem::ManuallyDrop; + +pub struct Foo([T; N]); + +pub struct Dorp {} + +impl Drop for Dorp { + fn drop(&mut self) {} +} + +#[inline] +// SAFETY: call this with a valid allocation idk +pub unsafe fn drop(x: *mut Foo) { + std::ptr::drop_in_place(x); +}