about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-19 07:44:43 +0000
committerbors <bors@rust-lang.org>2023-11-19 07:44:43 +0000
commitd0474fba92d2629e6a18a7e5fc93c32ad8b37b66 (patch)
treef6c5d0991a5ca0ffb69c49b16895a6b6814c153e /compiler
parent7d0e1bca0fd1cf26cb71a1271a782cd66ea1d9a9 (diff)
parentf6a49ba416aee1f57426c80a96f79287f6dec9d3 (diff)
downloadrust-d0474fba92d2629e6a18a7e5fc93c32ad8b37b66.tar.gz
rust-d0474fba92d2629e6a18a7e5fc93c32ad8b37b66.zip
Auto merge of #117807 - RalfJung:raw-str-slice, r=davidtwco
patterns: don't ice when encountering a raw str slice

Fixes https://github.com/rust-lang/rust/issues/117806
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/valtrees.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
index ed2d81727f7..2bee4b45ad0 100644
--- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs
+++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
@@ -11,7 +11,7 @@ use rustc_middle::mir;
 use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
 use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
 use rustc_span::DUMMY_SP;
-use rustc_target::abi::VariantIdx;
+use rustc_target::abi::{Abi, VariantIdx};
 
 #[instrument(skip(ecx), level = "debug")]
 fn branches<'tcx>(
@@ -101,11 +101,16 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
             // Not all raw pointers are allowed, as we cannot properly test them for
             // equality at compile-time (see `ptr_guaranteed_cmp`).
             // However we allow those that are just integers in disguise.
-            // (We could allow wide raw pointers where both sides are integers in the future,
-            // but for now we reject them.)
-            let Ok(val) = ecx.read_scalar(place) else {
+            // First, get the pointer. Remember it might be wide!
+            let Ok(val) = ecx.read_immediate(place) else {
                 return Err(ValTreeCreationError::Other);
             };
+            // We could allow wide raw pointers where both sides are integers in the future,
+            // but for now we reject them.
+            if matches!(val.layout.abi, Abi::ScalarPair(..)) {
+                return Err(ValTreeCreationError::Other);
+            }
+            let val = val.to_scalar();
             // We are in the CTFE machine, so ptr-to-int casts will fail.
             // This can only be `Ok` if `val` already is an integer.
             let Ok(val) = val.try_to_int() else {