Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c5b76e5

Browse files
committedJan 20, 2025
Reapply "Auto merge of rust-lang#133734 - scottmcm:lower-indexing-to-ptrmetadata, r=davidtwco,RalfJung"
This reverts commit 122a55b.
1 parent 9a1d156 commit c5b76e5

File tree

100 files changed

+1451
-1663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1451
-1663
lines changed
 

‎compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,27 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
586586
) => {}
587587
Rvalue::ShallowInitBox(_, _) => {}
588588

589-
Rvalue::UnaryOp(_, operand) => {
589+
Rvalue::UnaryOp(op, operand) => {
590590
let ty = operand.ty(self.body, self.tcx);
591-
if is_int_bool_float_or_char(ty) {
592-
// Int, bool, float, and char operations are fine.
593-
} else {
594-
span_bug!(self.span, "non-primitive type in `Rvalue::UnaryOp`: {:?}", ty);
591+
match op {
592+
UnOp::Not | UnOp::Neg => {
593+
if is_int_bool_float_or_char(ty) {
594+
// Int, bool, float, and char operations are fine.
595+
} else {
596+
span_bug!(
597+
self.span,
598+
"non-primitive type in `Rvalue::UnaryOp{op:?}`: {ty:?}",
599+
);
600+
}
601+
}
602+
UnOp::PtrMetadata => {
603+
if !ty.is_ref() && !ty.is_unsafe_ptr() {
604+
span_bug!(
605+
self.span,
606+
"non-pointer type in `Rvalue::UnaryOp({op:?})`: {ty:?}",
607+
);
608+
}
609+
}
595610
}
596611
}
597612

‎compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::ty::layout::FnAbiOf;
99
use rustc_middle::ty::{self, Instance, Ty};
1010
use rustc_middle::{bug, mir, span_bug};
1111
use rustc_span::source_map::Spanned;
12+
use rustc_span::{DesugaringKind, Span};
1213
use rustc_target::callconv::FnAbi;
1314
use tracing::{info, instrument, trace};
1415

@@ -80,7 +81,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
8081
use rustc_middle::mir::StatementKind::*;
8182

8283
match &stmt.kind {
83-
Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?,
84+
Assign(box (place, rvalue)) => {
85+
self.eval_rvalue_into_place(rvalue, *place, stmt.source_info.span)?
86+
}
8487

8588
SetDiscriminant { place, variant_index } => {
8689
let dest = self.eval_place(**place)?;
@@ -159,6 +162,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
159162
&mut self,
160163
rvalue: &mir::Rvalue<'tcx>,
161164
place: mir::Place<'tcx>,
165+
span: Span,
162166
) -> InterpResult<'tcx> {
163167
let dest = self.eval_place(place)?;
164168
// FIXME: ensure some kind of non-aliasing between LHS and RHS?
@@ -250,8 +254,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
250254
let src = self.eval_place(place)?;
251255
let place = self.force_allocation(&src)?;
252256
let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
253-
if !place_base_raw {
257+
if !place_base_raw
258+
&& span.desugaring_kind() != Some(DesugaringKind::IndexBoundsCheckReborrow)
259+
{
254260
// If this was not already raw, it needs retagging.
261+
// As a special hack, we exclude the desugared `PtrMetadata(&raw const *_n)`
262+
// from indexing. (Really we should not do any retag on `&raw` but that does not
263+
// currently work with Stacked Borrows.)
255264
val = M::retag_ptr_value(self, mir::RetagKind::Raw, &val)?;
256265
}
257266
self.write_immediate(*val, &dest)?;

0 commit comments

Comments
 (0)
Please sign in to comment.