Skip to content

Commit 69195c0

Browse files
authored
Rollup merge of #98860 - RalfJung:dangling-int-ptr, r=davidtwco
adjust dangling-int-ptr error message based on suggestions by `@saethlin` in rust-lang/miri#2163 Fixes rust-lang/miri#2163 I also did a bit of refactoring on this, so we have a helper method to create a `Pointer` with `None` provenance.
2 parents 54f79ba + 46956f7 commit 69195c0

18 files changed

+60
-47
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
513513
_ecx: &InterpCx<$mir, $tcx, Self>,
514514
addr: u64,
515515
) -> Pointer<Option<AllocId>> {
516-
Pointer::new(None, Size::from_bytes(addr))
516+
Pointer::from_addr(addr)
517517
}
518518

519519
#[inline(always)]
@@ -523,7 +523,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
523523
) -> InterpResult<$tcx, Pointer<Option<AllocId>>> {
524524
// Allow these casts, but make the pointer not dereferenceable.
525525
// (I.e., they behave like transmutation.)
526-
Ok(Pointer::new(None, Size::from_bytes(addr)))
526+
Ok(Pointer::from_addr(addr))
527527
}
528528

529529
#[inline(always)]

compiler/rustc_const_eval/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<'tcx, Tag: Provenance> MPlaceTy<'tcx, Tag> {
188188
#[inline]
189189
pub fn dangling(layout: TyAndLayout<'tcx>) -> Self {
190190
let align = layout.align.abi;
191-
let ptr = Pointer::new(None, Size::from_bytes(align.bytes())); // no provenance, absolute address
191+
let ptr = Pointer::from_addr(align.bytes()); // no provenance, absolute address
192192
// `Poison` this to make sure that the pointer value `ptr` is never observable by the program.
193193
MPlaceTy { mplace: MemPlace { ptr, meta: MemPlaceMeta::Poison }, layout, align }
194194
}

compiler/rustc_middle/src/mir/interpret/error.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,17 @@ pub enum CheckInAllocMsg {
186186

187187
impl fmt::Display for CheckInAllocMsg {
188188
/// When this is printed as an error the context looks like this:
189-
/// "{msg}0x01 is not a valid pointer".
189+
/// "{msg}{pointer} is a dangling pointer".
190190
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
191191
write!(
192192
f,
193193
"{}",
194194
match *self {
195195
CheckInAllocMsg::DerefTest => "dereferencing pointer failed: ",
196196
CheckInAllocMsg::MemoryAccessTest => "memory access failed: ",
197-
CheckInAllocMsg::PointerArithmeticTest => "pointer arithmetic failed: ",
197+
CheckInAllocMsg::PointerArithmeticTest => "out-of-bounds pointer arithmetic: ",
198198
CheckInAllocMsg::OffsetFromTest => "out-of-bounds offset_from: ",
199-
CheckInAllocMsg::InboundsTest => "",
199+
CheckInAllocMsg::InboundsTest => "out-of-bounds pointer use: ",
200200
}
201201
)
202202
}
@@ -350,14 +350,12 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
350350
ptr_size = ptr_size.bytes(),
351351
ptr_size_p = pluralize!(ptr_size.bytes()),
352352
),
353-
DanglingIntPointer(0, CheckInAllocMsg::InboundsTest) => {
354-
write!(f, "null pointer is not a valid pointer for this operation")
355-
}
356-
DanglingIntPointer(0, msg) => {
357-
write!(f, "{msg}null pointer is not a valid pointer")
358-
}
359353
DanglingIntPointer(i, msg) => {
360-
write!(f, "{msg}{i:#x} is not a valid pointer")
354+
write!(
355+
f,
356+
"{msg}{pointer} is a dangling pointer (it has no provenance)",
357+
pointer = Pointer::<Option<AllocId>>::from_addr(*i),
358+
)
361359
}
362360
AlignmentCheckFailed { required, has } => write!(
363361
f,

compiler/rustc_middle/src/mir/interpret/pointer.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@ impl<Tag: Provenance> fmt::Debug for Pointer<Option<Tag>> {
181181
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
182182
match self.provenance {
183183
Some(tag) => Provenance::fmt(&Pointer::new(tag, self.offset), f),
184-
None => write!(f, "{:#x}", self.offset.bytes()),
184+
None => write!(f, "{:#x}[noalloc]", self.offset.bytes()),
185+
}
186+
}
187+
}
188+
189+
impl<Tag: Provenance> fmt::Display for Pointer<Option<Tag>> {
190+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
191+
if self.provenance.is_none() && self.offset.bytes() == 0 {
192+
write!(f, "null pointer")
193+
} else {
194+
fmt::Debug::fmt(self, f)
185195
}
186196
}
187197
}
@@ -226,9 +236,14 @@ impl<Tag> Pointer<Option<Tag>> {
226236
}
227237

228238
impl<Tag> Pointer<Option<Tag>> {
239+
#[inline(always)]
240+
pub fn from_addr(addr: u64) -> Self {
241+
Pointer { provenance: None, offset: Size::from_bytes(addr) }
242+
}
243+
229244
#[inline(always)]
230245
pub fn null() -> Self {
231-
Pointer { provenance: None, offset: Size::ZERO }
246+
Pointer::from_addr(0)
232247
}
233248
}
234249

src/test/ui/const-ptr/forbidden_slices.32bit.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0080]: could not evaluate static initializer
44
LL | &*ptr::slice_from_raw_parts(data, len)
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
| |
7-
| dereferencing pointer failed: null pointer is not a valid pointer
7+
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
88
| inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
99
|
1010
::: $DIR/forbidden_slices.rs:19:34
@@ -18,7 +18,7 @@ error[E0080]: could not evaluate static initializer
1818
LL | &*ptr::slice_from_raw_parts(data, len)
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
| |
21-
| dereferencing pointer failed: null pointer is not a valid pointer
21+
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
2222
| inside `std::slice::from_raw_parts::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
2323
|
2424
::: $DIR/forbidden_slices.rs:20:33
@@ -104,7 +104,7 @@ error[E0080]: could not evaluate static initializer
104104
LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
105105
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106106
| |
107-
| out-of-bounds offset_from: null pointer is not a valid pointer
107+
| out-of-bounds offset_from: null pointer is a dangling pointer (it has no provenance)
108108
| inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
109109
|
110110
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
@@ -144,7 +144,7 @@ error[E0080]: could not evaluate static initializer
144144
LL | unsafe { intrinsics::offset(self, count) }
145145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146146
| |
147-
| pointer arithmetic failed: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
147+
| out-of-bounds pointer arithmetic: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
148148
| inside `ptr::const_ptr::<impl *const u32>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
149149
...
150150
LL | unsafe { self.offset(count as isize) }
@@ -205,7 +205,7 @@ error[E0080]: could not evaluate static initializer
205205
LL | unsafe { intrinsics::offset(self, count) }
206206
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207207
| |
208-
| pointer arithmetic failed: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
208+
| out-of-bounds pointer arithmetic: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
209209
| inside `ptr::const_ptr::<impl *const u64>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
210210
...
211211
LL | unsafe { self.offset(count as isize) }

src/test/ui/const-ptr/forbidden_slices.64bit.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0080]: could not evaluate static initializer
44
LL | &*ptr::slice_from_raw_parts(data, len)
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
| |
7-
| dereferencing pointer failed: null pointer is not a valid pointer
7+
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
88
| inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
99
|
1010
::: $DIR/forbidden_slices.rs:19:34
@@ -18,7 +18,7 @@ error[E0080]: could not evaluate static initializer
1818
LL | &*ptr::slice_from_raw_parts(data, len)
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
| |
21-
| dereferencing pointer failed: null pointer is not a valid pointer
21+
| dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
2222
| inside `std::slice::from_raw_parts::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
2323
|
2424
::: $DIR/forbidden_slices.rs:20:33
@@ -104,7 +104,7 @@ error[E0080]: could not evaluate static initializer
104104
LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
105105
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106106
| |
107-
| out-of-bounds offset_from: null pointer is not a valid pointer
107+
| out-of-bounds offset_from: null pointer is a dangling pointer (it has no provenance)
108108
| inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
109109
|
110110
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
@@ -144,7 +144,7 @@ error[E0080]: could not evaluate static initializer
144144
LL | unsafe { intrinsics::offset(self, count) }
145145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146146
| |
147-
| pointer arithmetic failed: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
147+
| out-of-bounds pointer arithmetic: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
148148
| inside `ptr::const_ptr::<impl *const u32>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
149149
...
150150
LL | unsafe { self.offset(count as isize) }
@@ -205,7 +205,7 @@ error[E0080]: could not evaluate static initializer
205205
LL | unsafe { intrinsics::offset(self, count) }
206206
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207207
| |
208-
| pointer arithmetic failed: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
208+
| out-of-bounds pointer arithmetic: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
209209
| inside `ptr::const_ptr::<impl *const u64>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
210210
...
211211
LL | unsafe { self.offset(count as isize) }

src/test/ui/consts/const-deref-ptr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: could not evaluate static initializer
22
--> $DIR/const-deref-ptr.rs:4:29
33
|
44
LL | static C: u64 = unsafe {*(0xdeadbeef as *const u64)};
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0xdeadbeef is not a valid pointer
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0xdeadbeef[noalloc] is a dangling pointer (it has no provenance)
66

77
error: aborting due to previous error
88

src/test/ui/consts/const-eval/const_raw_ptr_ops2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const Z: i32 = unsafe { *(&1 as *const i32) };
55

66
// bad, will thus error in miri
77
const Z2: i32 = unsafe { *(42 as *const i32) }; //~ ERROR evaluation of constant value failed
8-
//~| is not a valid pointer
8+
//~| is a dangling pointer
99
const Z3: i32 = unsafe { *(44 as *const i32) }; //~ ERROR evaluation of constant value failed
10-
//~| is not a valid pointer
10+
//~| is a dangling pointer

src/test/ui/consts/const-eval/const_raw_ptr_ops2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/const_raw_ptr_ops2.rs:7:26
33
|
44
LL | const Z2: i32 = unsafe { *(42 as *const i32) };
5-
| ^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0x2a is not a valid pointer
5+
| ^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0x2a[noalloc] is a dangling pointer (it has no provenance)
66

77
error[E0080]: evaluation of constant value failed
88
--> $DIR/const_raw_ptr_ops2.rs:9:26
99
|
1010
LL | const Z3: i32 = unsafe { *(44 as *const i32) };
11-
| ^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0x2c is not a valid pointer
11+
| ^^^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0x2c[noalloc] is a dangling pointer (it has no provenance)
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/consts/const-eval/ub-wide-ptr.32bit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ error[E0080]: could not evaluate static initializer
319319
--> $DIR/ub-wide-ptr.rs:147:5
320320
|
321321
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
322-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is not a valid pointer
322+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is a dangling pointer (it has no provenance)
323323

324324
error[E0080]: could not evaluate static initializer
325325
--> $DIR/ub-wide-ptr.rs:151:5

src/test/ui/consts/const-eval/ub-wide-ptr.64bit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ error[E0080]: could not evaluate static initializer
319319
--> $DIR/ub-wide-ptr.rs:147:5
320320
|
321321
LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
322-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is not a valid pointer
322+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is a dangling pointer (it has no provenance)
323323

324324
error[E0080]: could not evaluate static initializer
325325
--> $DIR/ub-wide-ptr.rs:151:5

src/test/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const fn helper() -> Option<&'static mut i32> { unsafe {
1111
// Undefined behaviour (integer as pointer), who doesn't love tests like this.
1212
// This code never gets executed, because the static checks fail before that.
1313
Some(&mut *(42 as *mut i32)) //~ ERROR evaluation of constant value failed
14-
//~| 0x2a is not a valid pointer
14+
//~| 0x2a[noalloc] is a dangling pointer
1515
} }
1616
// The error is an evaluation error and not a validation error, so the error is reported
1717
// directly at the site where it occurs.

src/test/ui/consts/const-mut-refs/mut_ref_in_final_dynamic_check.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0080]: evaluation of constant value failed
44
LL | Some(&mut *(42 as *mut i32))
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
| |
7-
| dereferencing pointer failed: 0x2a is not a valid pointer
7+
| dereferencing pointer failed: 0x2a[noalloc] is a dangling pointer (it has no provenance)
88
| inside `helper` at $DIR/mut_ref_in_final_dynamic_check.rs:13:10
99
...
1010
LL | const A: Option<&mut i32> = helper();

src/test/ui/consts/offset_from_ub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ pub const NOT_MULTIPLE_OF_SIZE: isize = {
3434
pub const OFFSET_FROM_NULL: isize = {
3535
let ptr = 0 as *const u8;
3636
unsafe { ptr_offset_from(ptr, ptr) } //~ERROR evaluation of constant value failed
37-
//~| null pointer is not a valid pointer
37+
//~| null pointer is a dangling pointer
3838
};
3939

4040
pub const DIFFERENT_INT: isize = { // offset_from with two different integers: like DIFFERENT_ALLOC
4141
let ptr1 = 8 as *const u8;
4242
let ptr2 = 16 as *const u8;
4343
unsafe { ptr_offset_from(ptr2, ptr1) } //~ERROR evaluation of constant value failed
44-
//~| 0x8 is not a valid pointer
44+
//~| 0x8[noalloc] is a dangling pointer
4545
};
4646

4747
const OUT_OF_BOUNDS_1: isize = {

src/test/ui/consts/offset_from_ub.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ error[E0080]: evaluation of constant value failed
2828
--> $DIR/offset_from_ub.rs:36:14
2929
|
3030
LL | unsafe { ptr_offset_from(ptr, ptr) }
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds offset_from: null pointer is not a valid pointer
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds offset_from: null pointer is a dangling pointer (it has no provenance)
3232

3333
error[E0080]: evaluation of constant value failed
3434
--> $DIR/offset_from_ub.rs:43:14
3535
|
3636
LL | unsafe { ptr_offset_from(ptr2, ptr1) }
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds offset_from: 0x8 is not a valid pointer
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds offset_from: 0x8[noalloc] is a dangling pointer (it has no provenance)
3838

3939
error[E0080]: evaluation of constant value failed
4040
--> $DIR/offset_from_ub.rs:52:14

src/test/ui/consts/offset_ub.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error[E0080]: evaluation of constant value failed
1818
LL | unsafe { intrinsics::offset(self, count) }
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
| |
21-
| pointer arithmetic failed: allocN has size 1, so pointer to 2 bytes starting at offset 0 is out-of-bounds
21+
| out-of-bounds pointer arithmetic: allocN has size 1, so pointer to 2 bytes starting at offset 0 is out-of-bounds
2222
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
2323
|
2424
::: $DIR/offset_ub.rs:8:43
@@ -32,7 +32,7 @@ error[E0080]: evaluation of constant value failed
3232
LL | unsafe { intrinsics::offset(self, count) }
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3434
| |
35-
| pointer arithmetic failed: allocN has size 100, so pointer to 101 bytes starting at offset 0 is out-of-bounds
35+
| out-of-bounds pointer arithmetic: allocN has size 100, so pointer to 101 bytes starting at offset 0 is out-of-bounds
3636
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
3737
|
3838
::: $DIR/offset_ub.rs:9:45
@@ -102,7 +102,7 @@ error[E0080]: evaluation of constant value failed
102102
LL | unsafe { intrinsics::offset(self, count) }
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104104
| |
105-
| pointer arithmetic failed: allocN has size 1, so pointer to 2 bytes starting at offset -4 is out-of-bounds
105+
| out-of-bounds pointer arithmetic: allocN has size 1, so pointer to 2 bytes starting at offset -4 is out-of-bounds
106106
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
107107
|
108108
::: $DIR/offset_ub.rs:15:49
@@ -116,7 +116,7 @@ error[E0080]: evaluation of constant value failed
116116
LL | unsafe { intrinsics::offset(self, count) }
117117
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118118
| |
119-
| pointer arithmetic failed: allocN has size 0, so pointer to 1 byte starting at offset 0 is out-of-bounds
119+
| out-of-bounds pointer arithmetic: allocN has size 0, so pointer to 1 byte starting at offset 0 is out-of-bounds
120120
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
121121
|
122122
::: $DIR/offset_ub.rs:17:50
@@ -130,7 +130,7 @@ error[E0080]: evaluation of constant value failed
130130
LL | unsafe { intrinsics::offset(self, count) as *mut T }
131131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132132
| |
133-
| pointer arithmetic failed: 0x1 is not a valid pointer
133+
| out-of-bounds pointer arithmetic: 0x1[noalloc] is a dangling pointer (it has no provenance)
134134
| inside `ptr::mut_ptr::<impl *mut u8>::offset` at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
135135
|
136136
::: $DIR/offset_ub.rs:18:42
@@ -144,7 +144,7 @@ error[E0080]: evaluation of constant value failed
144144
LL | unsafe { intrinsics::offset(self, count) }
145145
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146146
| |
147-
| pointer arithmetic failed: null pointer is not a valid pointer
147+
| out-of-bounds pointer arithmetic: null pointer is a dangling pointer (it has no provenance)
148148
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
149149
|
150150
::: $DIR/offset_ub.rs:21:50
@@ -158,7 +158,7 @@ error[E0080]: evaluation of constant value failed
158158
LL | unsafe { intrinsics::offset(self, count) }
159159
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
160160
| |
161-
| pointer arithmetic failed: 0x7f..f is not a valid pointer
161+
| out-of-bounds pointer arithmetic: 0x7f..f[noalloc] is a dangling pointer (it has no provenance)
162162
| inside `ptr::const_ptr::<impl *const u8>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
163163
|
164164
::: $DIR/offset_ub.rs:24:47

src/test/ui/consts/ptr_comparisons.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0080]: evaluation of constant value failed
44
LL | unsafe { intrinsics::offset(self, count) }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
| |
7-
| pointer arithmetic failed: alloc3 has size $WORD, so pointer to $TWO_WORDS bytes starting at offset 0 is out-of-bounds
7+
| out-of-bounds pointer arithmetic: alloc3 has size $WORD, so pointer to $TWO_WORDS bytes starting at offset 0 is out-of-bounds
88
| inside `ptr::const_ptr::<impl *const usize>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
99
|
1010
::: $DIR/ptr_comparisons.rs:58:34

0 commit comments

Comments
 (0)