Skip to content

Commit cfb6a1f

Browse files
committed
simplify how inline asm handles MaybeUninit
1 parent ce63e5d commit cfb6a1f

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -857,19 +857,9 @@ fn call_inline_asm<'tcx>(
857857

858858
fn asm_clif_type<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
859859
match ty.kind() {
860-
// Adapted from https://github.com/rust-lang/rust/blob/f3c66088610c1b80110297c2d9a8b5f9265b013f/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L136-L151
860+
// Adapted from https://github.com/rust-lang/rust/blob/df44a57fd29fca899ce473f85ed64efd0708dd7c/compiler/rustc_hir_typeck/src/inline_asm.rs#L180-L183
861861
ty::Adt(adt, args) if fx.tcx.is_lang_item(adt.did(), LangItem::MaybeUninit) => {
862-
let fields = &adt.non_enum_variant().fields;
863-
let ty = fields[FieldIdx::ONE].ty(fx.tcx, args);
864-
let ty::Adt(ty, args) = ty.kind() else {
865-
unreachable!("expected first field of `MaybeUninit` to be an ADT")
866-
};
867-
assert!(
868-
ty.is_manually_drop(),
869-
"expected first field of `MaybeUninit` to be `ManuallyDrop`"
870-
);
871-
let fields = &ty.non_enum_variant().fields;
872-
let ty = fields[FieldIdx::ZERO].ty(fx.tcx, args);
862+
let ty = args.type_at(0);
873863
fx.clif_type(ty)
874864
}
875865
_ => fx.clif_type(ty),

compiler/rustc_hir_typeck/src/inline_asm.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
178178
ty::Never if is_input => return None,
179179
_ if ty.references_error() => return None,
180180
ty::Adt(adt, args) if self.tcx().is_lang_item(adt.did(), LangItem::MaybeUninit) => {
181-
let fields = &adt.non_enum_variant().fields;
182-
let ty = fields[FieldIdx::ONE].ty(self.tcx(), args);
183-
// FIXME: Are we just trying to map to the `T` in `MaybeUninit<T>`?
184-
// If so, just get it from the args.
185-
let ty::Adt(ty, args) = ty.kind() else {
186-
unreachable!("expected first field of `MaybeUninit` to be an ADT")
187-
};
188-
assert!(
189-
ty.is_manually_drop(),
190-
"expected first field of `MaybeUninit` to be `ManuallyDrop`"
191-
);
192-
let fields = &ty.non_enum_variant().fields;
193-
let ty = fields[FieldIdx::ZERO].ty(self.tcx(), args);
181+
let ty = args.type_at(0);
194182
self.get_asm_ty(expr.span, ty)
195183
}
196184
_ => self.get_asm_ty(expr.span, ty),

0 commit comments

Comments
 (0)