about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret/projection.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-12-02 12:43:56 +0100
committerRalf Jung <post@ralfj.de>2023-12-12 08:15:17 +0100
commit9ef1e351665d9023483f4c281903848421319007 (patch)
tree9e29a7f50383ccdd94c8bc599bc560d439ba9615 /compiler/rustc_const_eval/src/interpret/projection.rs
parentb1613ebc432ae495ecfcfa822548390c250849a8 (diff)
downloadrust-9ef1e351665d9023483f4c281903848421319007.tar.gz
rust-9ef1e351665d9023483f4c281903848421319007.zip
reject projecting to fields whose offset we cannot compute
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/projection.rs')
-rw-r--r--compiler/rustc_const_eval/src/interpret/projection.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs
index 4d9e296d544..0f3b6b25c61 100644
--- a/compiler/rustc_const_eval/src/interpret/projection.rs
+++ b/compiler/rustc_const_eval/src/interpret/projection.rs
@@ -174,12 +174,15 @@ where
                     };
                     (base_meta, offset.align_to(align))
                 }
-                None => {
-                    // For unsized types with an extern type tail we perform no adjustments.
-                    // NOTE: keep this in sync with `PlaceRef::project_field` in the codegen backend.
-                    assert!(matches!(base_meta, MemPlaceMeta::None));
+                None if offset == Size::ZERO => {
+                    // If the offset is 0, then rounding it up to alignment wouldn't change anything,
+                    // so we can do this even for types where we cannot determine the alignment.
                     (base_meta, offset)
                 }
+                None => {
+                    // We don't know the alignment of this field, so we cannot adjust.
+                    throw_unsup_format!("`extern type` does not have a known offset")
+                }
             }
         } else {
             // base_meta could be present; we might be accessing a sized field of an unsized