Skip to content

Commit e495e73

Browse files
committed
Auto merge of #127068 - compiler-errors:stall-drop, r=<try>
Stall dropaStall computing instance for drop shim until it has no unsubstituted const params Stall resolving the drop shim instance for types that still have unsubstituted const params. ## Why? #127030 ICEs because it tries to inline the drop shim for a type with an unsubstituted const param. In order to generate this shim, this requires calling the drop shim builder, which invokes the trait solver to compute whether constituent types need drop (since we compute if a type is copy to disqualify any `Drop` behavior): https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_dataflow/src/elaborate_drops.rs#L378 However, since we don't keep the param-env of the instance we resolved the item for, we use the wrong param-env: https://github.com/rust-lang/rust/blob/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_mir_transform/src/shim.rs#L278 (which is the param-env of `std::ptr::drop_in_place`) This param-env is notably missing `ConstParamHasTy` predicates, and since we removed the type from consts in #125958, we literally cannot prove these predicates in this (relatively) empty param-env. This currently happens in places like the MIR inliner, but may happen elsewhere such as in lints that resolve terminators. ## What? We delay the resolution (`Instance::resolve`) of calls for `drop_in_place` for types that have unsubstituted const params. This should be OK, since all cases that deal with polymorphic code should handle `Instance::resolve` returning `None` gracefully.
2 parents 9c3bc80 + d62c70c commit e495e73

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

compiler/rustc_ty_utils/src/instance.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::query::Providers;
77
use rustc_middle::traits::{BuiltinImplSource, CodegenObligationError};
88
use rustc_middle::ty::util::AsyncDropGlueMorphology;
99
use rustc_middle::ty::GenericArgsRef;
10-
use rustc_middle::ty::{self, Instance, TyCtxt, TypeVisitableExt};
10+
use rustc_middle::ty::{self, Instance, TyCtxt, TypeFlags, TypeVisitableExt};
1111
use rustc_span::sym;
1212
use rustc_trait_selection::traits;
1313
use rustc_type_ir::ClosureKind;
@@ -53,6 +53,15 @@ fn resolve_instance<'tcx>(
5353
_ => return Ok(None),
5454
}
5555

56+
// FIXME(#127030): `ConstParamHasTy` has bad interactions with
57+
// the drop shim builder, which does not evaluate predicates in
58+
// the correct param-env for types being dropped. Stall resolving
59+
// the MIR for this instance until all of its const params are
60+
// substituted.
61+
if ty.has_type_flags(TypeFlags::HAS_CT_PARAM) {
62+
return Ok(None);
63+
}
64+
5665
ty::InstanceKind::DropGlue(def_id, Some(ty))
5766
} else {
5867
debug!(" => trivial drop glue");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: -Zinline-mir=yes --crate-type=lib
2+
//@ build-pass
3+
4+
use std::mem::ManuallyDrop;
5+
6+
pub struct Foo<T, const N: usize>([T; N]);
7+
8+
pub struct Dorp {}
9+
10+
impl Drop for Dorp {
11+
fn drop(&mut self) {}
12+
}
13+
14+
#[inline]
15+
// SAFETY: call this with a valid allocation idk
16+
pub unsafe fn drop<const M: usize>(x: *mut Foo<Dorp, M>) {
17+
std::ptr::drop_in_place(x);
18+
}

0 commit comments

Comments
 (0)