From d83f3ca8ca2d20eadf92a135a1a4b65ca91a24f6 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 23 May 2024 23:17:58 -0700 Subject: Validate the special layout restriction on DynMetadata --- compiler/rustc_const_eval/src/transform/validate.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'compiler/rustc_const_eval/src') 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 + 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); -- cgit 1.4.1-3-g733a5