Skip to content

Commit bb45867

Browse files
compiler-errorscuviper
authored andcommitted
Don't inline drop shims with unsubstituted generic consts in MIR inliner
(cherry picked from commit f17b27b)
1 parent e1f26a6 commit bb45867

File tree

3 files changed

+12
-262
lines changed

3 files changed

+12
-262
lines changed

compiler/rustc_mir_transform/src/inline.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
1010
use rustc_middle::mir::visit::*;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::ty::TypeVisitableExt;
13-
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
13+
use rustc_middle::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFlags};
1414
use rustc_session::config::{DebugInfo, OptLevel};
1515
use rustc_span::source_map::Spanned;
1616
use rustc_span::sym;
@@ -320,6 +320,16 @@ impl<'tcx> Inliner<'tcx> {
320320
InstanceDef::Intrinsic(_) | InstanceDef::Virtual(..) => {
321321
return Err("instance without MIR (intrinsic / virtual)");
322322
}
323+
324+
// FIXME(#127030): `ConstParamHasTy` has bad interactions with
325+
// the drop shim builder, which does not evaluate predicates in
326+
// the correct param-env for types being dropped. Stall resolving
327+
// the MIR for this instance until all of its const params are
328+
// substituted.
329+
InstanceDef::DropGlue(_, Some(ty)) if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) => {
330+
return Err("still needs substitution");
331+
}
332+
323333
// This cannot result in an immediate cycle since the callee MIR is a shim, which does
324334
// not get any optimizations run on it. Any subsequent inlining may cause cycles, but we
325335
// do not need to catch this here, we can wait until the inliner decides to continue

tests/ui/const-generics/polymorphic-drop-shim.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//@ compile-flags: -Zinline-mir=yes --crate-type=lib
2-
3-
//@ known-bug: unknown
4-
//@ build-fail
5-
//@ failure-status: 101
2+
//@ build-pass
63

74
use std::mem::ManuallyDrop;
85

0 commit comments

Comments
 (0)