diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-06-05 18:21:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-05 18:21:12 +0200 |
| commit | 36cab1260d64d031d91c5b60bda5b4988f643166 (patch) | |
| tree | 89af2c5197833866bbed8d810f4ec81c32927977 /compiler | |
| parent | edba40122a464231cff74a3ac8beecaddaebce1f (diff) | |
| parent | b710404f3b3990af8eebe2e168f6465535dfcc82 (diff) | |
| download | rust-36cab1260d64d031d91c5b60bda5b4988f643166.tar.gz rust-36cab1260d64d031d91c5b60bda5b4988f643166.zip | |
Rollup merge of #125672 - Lokathor:update-miri-result-ffi, r=RalfJung
Add more ABI test cases to miri (RFC 3391) Part of https://github.com/rust-lang/rust/issues/110503 cc `@RalfJung`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/terminator.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index 0649bb5617c..cbfe25ca8df 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -294,17 +294,30 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// Unwrap types that are guaranteed a null-pointer-optimization fn unfold_npo(&self, layout: TyAndLayout<'tcx>) -> InterpResult<'tcx, TyAndLayout<'tcx>> { - // Check if this is `Option` wrapping some type. - let inner = match layout.ty.kind() { - ty::Adt(def, args) if self.tcx.is_diagnostic_item(sym::Option, def.did()) => { - args[0].as_type().unwrap() - } - _ => { - // Not an `Option`. - return Ok(layout); + // Check if this is `Option` wrapping some type or if this is `Result` wrapping a 1-ZST and + // another type. + let ty::Adt(def, args) = layout.ty.kind() else { + // Not an ADT, so definitely no NPO. + return Ok(layout); + }; + let inner = if self.tcx.is_diagnostic_item(sym::Option, def.did()) { + // The wrapped type is the only arg. + self.layout_of(args[0].as_type().unwrap())? + } else if self.tcx.is_diagnostic_item(sym::Result, def.did()) { + // We want to extract which (if any) of the args is not a 1-ZST. + let lhs = self.layout_of(args[0].as_type().unwrap())?; + let rhs = self.layout_of(args[1].as_type().unwrap())?; + if lhs.is_1zst() { + rhs + } else if rhs.is_1zst() { + lhs + } else { + return Ok(layout); // no NPO } + } else { + return Ok(layout); // no NPO }; - let inner = self.layout_of(inner)?; + // Check if the inner type is one of the NPO-guaranteed ones. // For that we first unpeel transparent *structs* (but not unions). let is_npo = |def: AdtDef<'tcx>| { |
