Skip to content

Commit 8863327

Browse files
authored
Unrolled build for rust-lang#120801
Rollup merge of rust-lang#120801 - oli-obk:drop_recursion_ice, r=Nilstrieb Avoid ICE in drop recursion check in case of invalid drop impls fixes rust-lang#120787
2 parents c29082f + ad511ef commit 8863327

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

compiler/rustc_middle/src/ty/sty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,7 @@ impl<'tcx> PolyFnSig<'tcx> {
13131313
self.map_bound_ref_unchecked(|fn_sig| fn_sig.inputs())
13141314
}
13151315
#[inline]
1316+
#[track_caller]
13161317
pub fn input(&self, index: usize) -> ty::Binder<'tcx, Ty<'tcx>> {
13171318
self.map_bound_ref(|fn_sig| fn_sig.inputs()[index])
13181319
}

compiler/rustc_mir_build/src/lints.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ pub fn check_drop_recursion<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
7272
tcx.impl_of_method(def_id.to_def_id()).and_then(|def_id| tcx.impl_trait_ref(def_id))
7373
&& let Some(drop_trait) = tcx.lang_items().drop_trait()
7474
&& drop_trait == trait_ref.instantiate_identity().def_id
75+
// avoid erroneous `Drop` impls from causing ICEs below
76+
&& let sig = tcx.fn_sig(def_id).instantiate_identity()
77+
&& sig.inputs().skip_binder().len() == 1
7578
{
7679
// It was. Now figure out for what type `Drop` is implemented and then
7780
// check for recursion.
78-
if let ty::Ref(_, dropped_ty, _) = tcx
79-
.liberate_late_bound_regions(
80-
def_id.to_def_id(),
81-
tcx.fn_sig(def_id).instantiate_identity().input(0),
82-
)
83-
.kind()
81+
if let ty::Ref(_, dropped_ty, _) =
82+
tcx.liberate_late_bound_regions(def_id.to_def_id(), sig.input(0)).kind()
8483
{
8584
check_recursion(tcx, body, RecursiveDrop { drop_for: *dropped_ty });
8685
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// can't use build-fail, because this also fails check-fail, but
2+
// the ICE from #120787 only reproduces on build-fail.
3+
// compile-flags: --emit=mir
4+
5+
struct PrintOnDrop<'a>(&'a str);
6+
7+
impl Drop for PrintOnDrop<'_> {
8+
fn drop() {} //~ ERROR method `drop` has a `&mut self` declaration in the trait
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0186]: method `drop` has a `&mut self` declaration in the trait, but not in the impl
2+
--> $DIR/recursion-check-on-erroneous-impl.rs:8:5
3+
|
4+
LL | fn drop() {}
5+
| ^^^^^^^^^ expected `&mut self` in impl
6+
|
7+
= note: `drop` from trait: `fn(&mut Self)`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0186`.

0 commit comments

Comments
 (0)