about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/util/alignment.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-09-05 22:29:51 +0200
committerRalf Jung <post@ralfj.de>2023-09-05 22:29:51 +0200
commit8b3435c10f458b840d9cba31f2f35586e9b31189 (patch)
tree11da976f8650955137a958ce4aa0d7ad453bd319 /compiler/rustc_const_eval/src/util/alignment.rs
parentab45885dec2a6552cb060a5b7183653baaecd580 (diff)
downloadrust-8b3435c10f458b840d9cba31f2f35586e9b31189.tar.gz
rust-8b3435c10f458b840d9cba31f2f35586e9b31189.zip
fix detecting references to packed unsized fields
Diffstat (limited to 'compiler/rustc_const_eval/src/util/alignment.rs')
-rw-r--r--compiler/rustc_const_eval/src/util/alignment.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/util/alignment.rs b/compiler/rustc_const_eval/src/util/alignment.rs
index 2e0643afb39..bdb08a9828e 100644
--- a/compiler/rustc_const_eval/src/util/alignment.rs
+++ b/compiler/rustc_const_eval/src/util/alignment.rs
@@ -22,9 +22,11 @@ where
 
     let ty = place.ty(local_decls, tcx).ty;
     match tcx.layout_of(param_env.and(ty)) {
-        Ok(layout) if layout.align.abi <= pack => {
+        Ok(layout) if layout.align.abi <= pack && layout.is_sized() => {
             // If the packed alignment is greater or equal to the field alignment, the type won't be
             // further disaligned.
+            // However we need to ensure the field is sized; for unsized fields, `layout.align` is
+            // just an approximation.
             debug!(
                 "is_disaligned({:?}) - align = {}, packed = {}; not disaligned",
                 place,