Skip to content

Commit 2d7ac72

Browse files
committed
Stop using the const_eval query for initializers of statics
As a side effect, we now represent most promoteds as `ConstValue::Scalar` again. This is useful because all implict promoteds are just references anyway and most explicit promoteds are numeric arguments to `asm!` or SIMD instructions.
1 parent 083f1d7 commit 2d7ac72

File tree

17 files changed

+53
-108
lines changed

17 files changed

+53
-108
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId;
1212
use rustc_hir::Node;
1313
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1414
use rustc_middle::mir::interpret::{
15-
read_target_uint, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer,
15+
read_target_uint, Allocation, ErrorHandled, GlobalAlloc, Pointer,
1616
};
1717
use rustc_middle::mir::mono::MonoItem;
1818
use rustc_middle::ty::{self, Instance, Ty};
@@ -85,10 +85,7 @@ pub fn codegen_static_initializer(
8585
cx: &CodegenCx<'ll, 'tcx>,
8686
def_id: DefId,
8787
) -> Result<(&'ll Value, &'tcx Allocation), ErrorHandled> {
88-
let alloc = match cx.tcx.const_eval_poly(def_id)? {
89-
ConstValue::ByRef { alloc, offset } if offset.bytes() == 0 => alloc,
90-
val => bug!("static const eval returned {:#?}", val),
91-
};
88+
let alloc = cx.tcx.eval_static_initializer(def_id)?;
9289
Ok((const_alloc_to_llvm(cx, alloc), alloc))
9390
}
9491

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast as ast;
1313
use rustc_hir::lang_items::LangItem;
1414
use rustc_index::vec::Idx;
1515
use rustc_middle::mir;
16-
use rustc_middle::mir::interpret::{AllocId, ConstValue, Pointer, Scalar};
16+
use rustc_middle::mir::interpret::ConstValue;
1717
use rustc_middle::mir::AssertKind;
1818
use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
1919
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -867,24 +867,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
867867
let ty = constant.literal.ty;
868868
let size = bx.layout_of(ty).size;
869869
let scalar = match const_value {
870-
// Promoted constants are evaluated into a ByRef instead of a Scalar,
871-
// but we want the scalar value here.
872-
ConstValue::ByRef { alloc, offset } => {
873-
let ptr = Pointer::new(AllocId(0), offset);
874-
alloc
875-
.read_scalar(&bx, ptr, size)
876-
.and_then(|s| s.check_init())
877-
.unwrap_or_else(|e| {
878-
bx.tcx().sess.span_err(
879-
span,
880-
&format!("Could not evaluate asm const: {}", e),
881-
);
882-
883-
// We are erroring out, just emit a dummy constant.
884-
Scalar::from_u64(0)
885-
})
886-
}
887-
_ => span_bug!(span, "expected ByRef for promoted asm const"),
870+
ConstValue::Scalar(s) => s,
871+
_ => span_bug!(
872+
span,
873+
"expected Scalar for promoted asm const, but got {:#?}",
874+
const_value
875+
),
888876
};
889877
let value = scalar.assert_bits(size);
890878
let string = match ty.kind() {

compiler/rustc_lint/src/builtin.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,21 +1473,18 @@ declare_lint_pass!(
14731473
UnusedBrokenConst => []
14741474
);
14751475

1476-
fn check_const(cx: &LateContext<'_>, body_id: hir::BodyId) {
1477-
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
1478-
// trigger the query once for all constants since that will already report the errors
1479-
// FIXME: Use ensure here
1480-
let _ = cx.tcx.const_eval_poly(def_id);
1481-
}
1482-
14831476
impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst {
14841477
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
14851478
match it.kind {
14861479
hir::ItemKind::Const(_, body_id) => {
1487-
check_const(cx, body_id);
1480+
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
1481+
// trigger the query once for all constants since that will already report the errors
1482+
// FIXME: Use ensure here
1483+
let _ = cx.tcx.const_eval_poly(def_id);
14881484
}
14891485
hir::ItemKind::Static(_, _, body_id) => {
1490-
check_const(cx, body_id);
1486+
let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id();
1487+
let _ = cx.tcx.eval_static_initializer(def_id);
14911488
}
14921489
_ => {}
14931490
}

compiler/rustc_mir/src/const_eval/eval_queries.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub(super) fn op_to_const<'tcx>(
182182
}
183183
}
184184

185-
fn validate_and_turn_into_const<'tcx>(
185+
fn turn_into_const<'tcx>(
186186
tcx: TyCtxt<'tcx>,
187187
constant: RawConst<'tcx>,
188188
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
@@ -191,30 +191,21 @@ fn validate_and_turn_into_const<'tcx>(
191191
let def_id = cid.instance.def.def_id();
192192
let is_static = tcx.is_static(def_id);
193193
let ecx = mk_eval_cx(tcx, tcx.def_span(key.value.instance.def_id()), key.param_env, is_static);
194-
let val = (|| {
195-
let mplace = ecx.raw_const_to_mplace(constant)?;
196-
// Turn this into a proper constant.
197-
// Statics/promoteds are always `ByRef`, for the rest `op_to_const` decides
198-
// whether they become immediates.
199-
if is_static || cid.promoted.is_some() {
200-
let ptr = mplace.ptr.assert_ptr();
201-
Ok(ConstValue::ByRef {
202-
alloc: ecx.tcx.global_alloc(ptr.alloc_id).unwrap_memory(),
203-
offset: ptr.offset,
204-
})
205-
} else {
206-
Ok(op_to_const(&ecx, mplace.into()))
207-
}
208-
})();
209194

210-
// FIXME: Can this ever be an error and not be a compiler bug or can we just ICE here?
211-
val.map_err(|error| {
195+
let mplace = ecx.raw_const_to_mplace(constant).map_err(|error| {
196+
// FIXME: Can the above ever error and not be a compiler bug or can we just ICE here?
212197
let err = ConstEvalErr::new(&ecx, error, None);
213198
err.struct_error(ecx.tcx, "it is undefined behavior to use this value", |mut diag| {
214199
diag.note(note_on_undefined_behavior_error());
215200
diag.emit();
216201
})
217-
})
202+
})?;
203+
assert!(
204+
!is_static || cid.promoted.is_some(),
205+
"the const eval query should not be used for statics, use `const_eval_raw` instead"
206+
);
207+
// Turn this into a proper constant.
208+
Ok(op_to_const(&ecx, mplace.into()))
218209
}
219210

220211
pub fn const_eval_validated_provider<'tcx>(
@@ -248,7 +239,7 @@ pub fn const_eval_validated_provider<'tcx>(
248239
});
249240
}
250241

251-
tcx.const_eval_raw(key).and_then(|val| validate_and_turn_into_const(tcx, val, key))
242+
tcx.const_eval_raw(key).and_then(|val| turn_into_const(tcx, val, key))
252243
}
253244

254245
pub fn const_eval_raw_provider<'tcx>(

compiler/rustc_mir/src/interpret/eval_context.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -914,13 +914,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
914914
} else {
915915
self.param_env
916916
};
917-
// We use `const_eval_raw` here, and get an unvalidated result. That is okay:
918-
// Our result will later be validated anyway, and there seems no good reason
919-
// to have to fail early here. This is also more consistent with
920-
// `Memory::get_static_alloc` which has to use `const_eval_raw` to avoid cycles.
921-
// FIXME: We can hit delay_span_bug if this is an invalid const, interning finds
922-
// that problem, but we never run validation to show an error. Can we ensure
923-
// this does not happen?
924917
let val = self.tcx.const_eval_raw(param_env.and(gid))?;
925918
self.raw_const_to_mplace(val)
926919
}

compiler/rustc_mir/src/interpret/operand.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
554554
ty::ConstKind::Unevaluated(def, substs, promoted) => {
555555
let instance = self.resolve(def.did, substs)?;
556556
// We use `const_eval` here and `const_eval_raw` elsewhere in mir interpretation.
557-
// The reason we use `const_eval_raw` everywhere else is to prevent cycles during
558-
// validation, because validation automatically reads through any references, thus
559-
// potentially requiring the current static to be evaluated again. This is not a
560-
// problem here, because we are building an operand which means an actual read is
561-
// happening.
557+
// The reason we use `const_eval` here is that there can never be a `ty::ConstKind`
558+
// that directly mentions the initializer of a static. Statics are always encoded
559+
// as constants with vaule `&STATIC`.
562560
return Ok(self.const_eval(GlobalId { instance, promoted }, val.ty)?);
563561
}
564562
ty::ConstKind::Infer(..)

compiler/rustc_mir/src/monomorphize/collector.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,10 @@ fn collect_items_rec<'tcx>(
364364

365365
recursion_depth_reset = None;
366366

367-
if let Ok(val) = tcx.const_eval_poly(def_id) {
368-
collect_const_value(tcx, val, &mut neighbors);
367+
if let Ok(alloc) = tcx.eval_static_initializer(def_id) {
368+
for &((), id) in alloc.relocations().values() {
369+
collect_miri(tcx, id, &mut neighbors);
370+
}
369371
}
370372
}
371373
MonoItem::Fn(instance) => {

compiler/rustc_mir/src/util/pretty.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,14 +631,11 @@ pub fn write_allocations<'tcx>(
631631
None => write!(w, " (deallocated)")?,
632632
Some(GlobalAlloc::Function(inst)) => write!(w, " (fn: {})", inst)?,
633633
Some(GlobalAlloc::Static(did)) if !tcx.is_foreign_item(did) => {
634-
match tcx.const_eval_poly(did) {
635-
Ok(ConstValue::ByRef { alloc, .. }) => {
634+
match tcx.eval_static_initializer(did) {
635+
Ok(alloc) => {
636636
write!(w, " (static: {}, ", tcx.def_path_str(did))?;
637637
write_allocation_track_relocs(w, alloc)?;
638638
}
639-
Ok(_) => {
640-
span_bug!(tcx.def_span(did), " static item without `ByRef` initializer")
641-
}
642639
Err(_) => write!(
643640
w,
644641
" (static: {}, error during initializer evaluation)",

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
111111
use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
112112
use rustc_infer::infer::{InferCtxt, InferOk, InferResult, RegionVariableOrigin, TyCtxtInferExt};
113113
use rustc_middle::hir::map::blocks::FnLikeNode;
114-
use rustc_middle::mir::interpret::ConstValue;
115114
use rustc_middle::ty::adjustment::{
116115
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
117116
};
@@ -2070,16 +2069,15 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: S
20702069
// `#[link_section]` may contain arbitrary, or even undefined bytes, but it is
20712070
// the consumer's responsibility to ensure all bytes that have been read
20722071
// have defined values.
2073-
match tcx.const_eval_poly(id.to_def_id()) {
2074-
Ok(ConstValue::ByRef { alloc, .. }) => {
2072+
match tcx.eval_static_initializer(id.to_def_id()) {
2073+
Ok(alloc) => {
20752074
if alloc.relocations().len() != 0 {
20762075
let msg = "statics with a custom `#[link_section]` must be a \
20772076
simple list of bytes on the wasm target with no \
20782077
extra levels of indirection such as references";
20792078
tcx.sess.span_err(span, msg);
20802079
}
20812080
}
2082-
Ok(_) => bug!("Matching on non-ByRef static"),
20832081
Err(_) => {}
20842082
}
20852083
}

src/test/ui/consts/const-eval/const-pointer-values-in-various-types.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ error[E0080]: it is undefined behavior to use this value
3636
--> $DIR/const-pointer-values-in-various-types.rs:37:5
3737
|
3838
LL | const I32_REF_U64_UNION: u64 = unsafe { Nonsense { int_32_ref: &3 }.uint_64 };
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc22, but expected initialized plain (non-pointer) bytes
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc18, but expected initialized plain (non-pointer) bytes
4040
|
4141
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
4242

@@ -76,7 +76,7 @@ error[E0080]: it is undefined behavior to use this value
7676
--> $DIR/const-pointer-values-in-various-types.rs:52:5
7777
|
7878
LL | const I32_REF_I64_UNION: i64 = unsafe { Nonsense { int_32_ref: &3 }.int_64 };
79-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc47, but expected initialized plain (non-pointer) bytes
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc38, but expected initialized plain (non-pointer) bytes
8080
|
8181
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8282

@@ -100,7 +100,7 @@ error[E0080]: it is undefined behavior to use this value
100100
--> $DIR/const-pointer-values-in-various-types.rs:61:5
101101
|
102102
LL | const I32_REF_F64_UNION: f64 = unsafe { Nonsense { int_32_ref: &3 }.float_64 };
103-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc62, but expected initialized plain (non-pointer) bytes
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc50, but expected initialized plain (non-pointer) bytes
104104
|
105105
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
106106

@@ -148,7 +148,7 @@ error[E0080]: it is undefined behavior to use this value
148148
--> $DIR/const-pointer-values-in-various-types.rs:79:5
149149
|
150150
LL | const STR_U64_UNION: u64 = unsafe { Nonsense { stringy: "3" }.uint_64 };
151-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc86, but expected initialized plain (non-pointer) bytes
151+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc71, but expected initialized plain (non-pointer) bytes
152152
|
153153
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
154154

@@ -188,7 +188,7 @@ error[E0080]: it is undefined behavior to use this value
188188
--> $DIR/const-pointer-values-in-various-types.rs:94:5
189189
|
190190
LL | const STR_I64_UNION: i64 = unsafe { Nonsense { stringy: "3" }.int_64 };
191-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc101, but expected initialized plain (non-pointer) bytes
191+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc86, but expected initialized plain (non-pointer) bytes
192192
|
193193
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
194194

@@ -212,7 +212,7 @@ error[E0080]: it is undefined behavior to use this value
212212
--> $DIR/const-pointer-values-in-various-types.rs:103:5
213213
|
214214
LL | const STR_F64_UNION: f64 = unsafe { Nonsense { stringy: "3" }.float_64 };
215-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc110, but expected initialized plain (non-pointer) bytes
215+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc95, but expected initialized plain (non-pointer) bytes
216216
|
217217
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
218218

src/test/ui/consts/const-eval/ub-enum.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error[E0080]: it is undefined behavior to use this value
1818
--> $DIR/ub-enum.rs:30:1
1919
|
2020
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc13 at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc12 at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
2222
|
2323
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
2424

@@ -34,15 +34,15 @@ error[E0080]: it is undefined behavior to use this value
3434
--> $DIR/ub-enum.rs:44:1
3535
|
3636
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc20 at .<enum-tag>, but expected initialized plain (non-pointer) bytes
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc18 at .<enum-tag>, but expected initialized plain (non-pointer) bytes
3838
|
3939
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
4040

4141
error[E0080]: it is undefined behavior to use this value
4242
--> $DIR/ub-enum.rs:47:1
4343
|
4444
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc25 at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc22 at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
4646
|
4747
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
4848

@@ -58,7 +58,7 @@ error[E0080]: it is undefined behavior to use this value
5858
--> $DIR/ub-enum.rs:60:1
5959
|
6060
LL | const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc32 at .<enum-tag>, but expected initialized plain (non-pointer) bytes
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc28 at .<enum-tag>, but expected initialized plain (non-pointer) bytes
6262
|
6363
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
6464

src/test/ui/consts/const-eval/ub-nonnull.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
1313
LL | | let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
1414
LL | | // Use address-of-element for pointer arithmetic. This could wrap around to NULL!
1515
LL | | let out_of_bounds_ptr = &ptr[255];
16-
| | ^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc11 which has size 1
16+
| | ^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
1717
LL | | mem::transmute(out_of_bounds_ptr)
1818
LL | | } };
1919
| |____-

0 commit comments

Comments
 (0)