Skip to content

Commit ad6fb06

Browse files
authored
Rollup merge of rust-lang#141296 - azhogin:azhogin/async-drop-broken-mir-place-deref-fix, r=oli-obk
Async drop fix for 'broken mir, place has deref as later projection' fixes rust-lang#140975 Problem in codegen fixed with an additional temporary local.
2 parents 7a53ef7 + 7c38b6f commit ad6fb06

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

compiler/rustc_mir_transform/src/elaborate_drop.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,20 @@ where
318318
bug!();
319319
};
320320
let obj_ptr_ty = Ty::new_mut_ptr(tcx, drop_ty);
321-
let obj_ptr_place = Place::from(self.new_temp(obj_ptr_ty));
322321
let unwrap_ty = adt_def.non_enum_variant().fields[FieldIdx::ZERO].ty(tcx, adt_args);
323-
let addr = Rvalue::RawPtr(
324-
RawPtrKind::Mut,
325-
pin_obj_place.project_deeper(
326-
&[ProjectionElem::Field(FieldIdx::ZERO, unwrap_ty), ProjectionElem::Deref],
327-
tcx,
328-
),
329-
);
322+
let obj_ref_place = Place::from(self.new_temp(unwrap_ty));
323+
call_statements.push(self.assign(
324+
obj_ref_place,
325+
Rvalue::Use(Operand::Copy(tcx.mk_place_field(
326+
pin_obj_place,
327+
FieldIdx::ZERO,
328+
unwrap_ty,
329+
))),
330+
));
331+
332+
let obj_ptr_place = Place::from(self.new_temp(obj_ptr_ty));
333+
334+
let addr = Rvalue::RawPtr(RawPtrKind::Mut, tcx.mk_place_deref(obj_ref_place));
330335
call_statements.push(self.assign(obj_ptr_place, addr));
331336
obj_ptr_place
332337
};

tests/crashes/140975.rs renamed to tests/ui/async-await/async-drop/deref-later-projection.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
//@ known-bug: #140975
2-
//@ compile-flags: --crate-type lib -Zvalidate-mir
3-
//@ edition: 2021
1+
// Ex-ICE: #140975
2+
//@ compile-flags: -Zvalidate-mir
3+
//@ build-pass
4+
//@ edition:2021
5+
#![crate_type = "lib"]
46
#![feature(async_drop)]
7+
#![allow(incomplete_features)]
8+
59
use std::{future::AsyncDrop, pin::Pin};
610

711
struct HasAsyncDrop ;

0 commit comments

Comments
 (0)