about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/transform
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-05-23 23:17:58 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2024-05-23 23:38:44 -0700
commitd83f3ca8ca2d20eadf92a135a1a4b65ca91a24f6 (patch)
tree9e8e3c2d1fda3846a2717118941c93d0a97945f4 /compiler/rustc_const_eval/src/transform
parent5baee04b6349d176440cb1fcd5424a89f67b9f7b (diff)
downloadrust-d83f3ca8ca2d20eadf92a135a1a4b65ca91a24f6.tar.gz
rust-d83f3ca8ca2d20eadf92a135a1a4b65ca91a24f6.zip
Validate the special layout restriction on DynMetadata
Diffstat (limited to 'compiler/rustc_const_eval/src/transform')
-rw-r--r--compiler/rustc_const_eval/src/transform/validate.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs
index 3a2b2c5f300..66cc65de647 100644
--- a/compiler/rustc_const_eval/src/transform/validate.rs
+++ b/compiler/rustc_const_eval/src/transform/validate.rs
@@ -685,6 +685,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
                         check_equal(self, location, *f_ty);
                     }
                     ty::Adt(adt_def, args) => {
+                        // see <https://github.com/rust-lang/rust/blob/7601adcc764d42c9f2984082b49948af652df986/compiler/rustc_middle/src/ty/layout.rs#L861-L864>
+                        if Some(adt_def.did()) == self.tcx.lang_items().dyn_metadata() {
+                            self.fail(
+                                location,
+                                format!("You can't project to field {f:?} of `DynMetadata` because \
+                                         layout is weird and thinks it doesn't have fields."),
+                            );
+                        }
+
                         let var = parent_ty.variant_index.unwrap_or(FIRST_VARIANT);
                         let Some(field) = adt_def.variant(var).fields.get(f) else {
                             fail_out_of_bounds(self, location);