about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-12 00:34:22 +0000
committerbors <bors@rust-lang.org>2024-02-12 00:34:22 +0000
commit084ce5bdb5f7dc1c725f6770a8de281165ba3b0a (patch)
tree19b02783a13bce0a281f7d29274a102afde2c629 /compiler/rustc_const_eval/src
parent520b0b20aa8c218f84cefc6260f52406b84fa55f (diff)
parent9bd630af97e609cd9579703777a2d8d67f8fc2da (diff)
downloadrust-084ce5bdb5f7dc1c725f6770a8de281165ba3b0a.tar.gz
rust-084ce5bdb5f7dc1c725f6770a8de281165ba3b0a.zip
Auto merge of #120951 - matthiaskrgr:rollup-0nnm7dv, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #110483 (Create try_new function for ThinBox)
 - #120740 (Make cmath.rs a single file)
 - #120872 (hir: Refactor getters for HIR parents)
 - #120880 (add note on comparing vtables / function pointers)
 - #120885 (interpret/visitor: ensure we only see normalized types)
 - #120888 (assert_unsafe_precondition cleanup)
 - #120897 (Encode `coroutine_for_closure` for foreign crates)
 - #120937 ([docs] Update armv6k-nintendo-3ds platform docs for outdated info)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/interpret/projection.rs2
-rw-r--r--compiler/rustc_const_eval/src/interpret/visitor.rs10
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/mod.rs7
3 files changed, 15 insertions, 4 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs
index 3a441c1d649..7b68a37fdf3 100644
--- a/compiler/rustc_const_eval/src/interpret/projection.rs
+++ b/compiler/rustc_const_eval/src/interpret/projection.rs
@@ -149,6 +149,8 @@ where
             "`field` projection called on a slice -- call `index` projection instead"
         );
         let offset = base.layout().fields.offset(field);
+        // Computing the layout does normalization, so we get a normalized type out of this
+        // even if the field type is non-normalized (possible e.g. via associated types).
         let field_layout = base.layout().field(self, field);
 
         // Offset may need adjustment for unsized fields.
diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs
index de0590a4b14..340a496a689 100644
--- a/compiler/rustc_const_eval/src/interpret/visitor.rs
+++ b/compiler/rustc_const_eval/src/interpret/visitor.rs
@@ -153,6 +153,16 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
                 // We visited all parts of this one.
                 return Ok(());
             }
+
+            // Non-normalized types should never show up here.
+            ty::Param(..)
+            | ty::Alias(..)
+            | ty::Bound(..)
+            | ty::Placeholder(..)
+            | ty::Infer(..)
+            | ty::Error(..) => throw_inval!(TooGeneric),
+
+            // The rest is handled below.
             _ => {}
         };
 
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs
index 98276ff2e68..1be2a2bc1f3 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/mod.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/mod.rs
@@ -131,11 +131,10 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
     let local_def_id = def_id.expect_local();
     let hir_id = tcx.local_def_id_to_hir_id(local_def_id);
 
-    let Some(parent) = tcx.hir().opt_parent_id(hir_id) else { return false };
-
-    if !tcx.is_const_trait_impl_raw(parent.owner.def_id.to_def_id()) {
+    let parent_owner_id = tcx.parent_hir_id(hir_id).owner;
+    if !tcx.is_const_trait_impl_raw(parent_owner_id.to_def_id()) {
         return false;
     }
 
-    tcx.lookup_const_stability(parent.owner).is_some_and(|stab| stab.is_const_stable())
+    tcx.lookup_const_stability(parent_owner_id).is_some_and(|stab| stab.is_const_stable())
 }