Skip to content

Commit 3c75f70

Browse files
authoredApr 30, 2020
Rollup merge of #71590 - RalfJung:mir-dump-pointers, r=oli-obk
MIR dump: print pointers consistently with Miri output This makes MIR allocation dump pointer printing consistent with Miri output: both use hexadecimal offsets with a `0x` prefix. To save some space, MIR dump replaces the `alloc` prefix by `a` when necessary. I also made AllocId/Pointer printing more consistent in their Debug/Display handling, and adjusted Display printing for Scalar a bit to avoid using decimal printing when we do not know the sign with which to interpret the value (IMO using decimal then is misleading).
2 parents 01fffff + b12faeb commit 3c75f70

22 files changed

+131
-97
lines changed
 

‎src/librustc_middle/mir/interpret/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,17 @@ pub enum LitToConstError {
168168
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
169169
pub struct AllocId(pub u64);
170170

171+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
172+
// all the Miri types.
171173
impl fmt::Debug for AllocId {
172-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
173-
fmt::Display::fmt(self, fmt)
174+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
175+
if f.alternate() { write!(f, "a{}", self.0) } else { write!(f, "alloc{}", self.0) }
174176
}
175177
}
176178

177179
impl fmt::Display for AllocId {
178180
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179-
write!(f, "alloc{}", self.0)
181+
fmt::Debug::fmt(self, f)
180182
}
181183
}
182184

‎src/librustc_middle/mir/interpret/pointer.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,33 @@ pub struct Pointer<Tag = (), Id = AllocId> {
119119

120120
static_assert_size!(Pointer, 16);
121121

122+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
123+
// all the Miri types.
124+
// We have to use `Debug` output for the tag, because `()` does not implement
125+
// `Display` so we cannot specialize that.
122126
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> {
123127
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124-
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
128+
if f.alternate() {
129+
write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
130+
} else {
131+
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
132+
}
125133
}
126134
}
127135
// Specialization for no tag
128136
impl<Id: fmt::Debug> fmt::Debug for Pointer<(), Id> {
129137
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130-
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
138+
if f.alternate() {
139+
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())
140+
} else {
141+
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
142+
}
143+
}
144+
}
145+
146+
impl<Tag: fmt::Debug> fmt::Display for Pointer<Tag> {
147+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148+
fmt::Debug::fmt(self, f)
131149
}
132150
}
133151

‎src/librustc_middle/mir/interpret/value.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub enum Scalar<Tag = (), Id = AllocId> {
107107
#[cfg(target_arch = "x86_64")]
108108
static_assert_size!(Scalar, 24);
109109

110+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
111+
// all the Miri types.
110112
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> {
111113
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112114
match self {
@@ -125,11 +127,11 @@ impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> {
125127
}
126128
}
127129

128-
impl<Tag> fmt::Display for Scalar<Tag> {
130+
impl<Tag: fmt::Debug> fmt::Display for Scalar<Tag> {
129131
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130132
match self {
131-
Scalar::Ptr(_) => write!(f, "a pointer"),
132-
Scalar::Raw { data, .. } => write!(f, "{}", data),
133+
Scalar::Ptr(ptr) => write!(f, "pointer to {}", ptr),
134+
Scalar::Raw { .. } => fmt::Debug::fmt(self, f),
133135
}
134136
}
135137
}
@@ -559,16 +561,18 @@ impl<Tag> From<Pointer<Tag>> for ScalarMaybeUndef<Tag> {
559561
}
560562
}
561563

564+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
565+
// all the Miri types.
562566
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag, Id> {
563567
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
564568
match self {
565-
ScalarMaybeUndef::Undef => write!(f, "Undef"),
569+
ScalarMaybeUndef::Undef => write!(f, "<uninitialized>"),
566570
ScalarMaybeUndef::Scalar(s) => write!(f, "{:?}", s),
567571
}
568572
}
569573
}
570574

571-
impl<Tag> fmt::Display for ScalarMaybeUndef<Tag> {
575+
impl<Tag: fmt::Debug> fmt::Display for ScalarMaybeUndef<Tag> {
572576
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
573577
match self {
574578
ScalarMaybeUndef::Undef => write!(f, "uninitialized bytes"),

‎src/librustc_mir/interpret/machine.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
8484
/// Tag tracked alongside every pointer. This is used to implement "Stacked Borrows"
8585
/// <https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html>.
8686
/// The `default()` is used for pointers to consts, statics, vtables and functions.
87+
/// The `Debug` formatting is used for displaying pointers; we cannot use `Display`
88+
/// as `()` does not implement that, but it should be "nice" output.
8789
type PointerTag: ::std::fmt::Debug + Copy + Eq + Hash + 'static;
8890

8991
/// Machines can define extra (non-instance) things that represent values of function pointers.

‎src/librustc_mir/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
674674
/// control for this.
675675
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
676676
// Cannot be a closure because it is generic in `Tag`, `Extra`.
677-
fn write_allocation_track_relocs<'tcx, Tag, Extra>(
677+
fn write_allocation_track_relocs<'tcx, Tag: Copy + fmt::Debug, Extra>(
678678
tcx: TyCtxtAt<'tcx>,
679679
allocs_to_print: &mut VecDeque<AllocId>,
680680
alloc: &Allocation<Tag, Extra>,

‎src/librustc_mir/interpret/operand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
122122
p(cx, s, ty)?;
123123
return Ok(());
124124
}
125-
write!(f, "{:?}: {}", s.erase_tag(), self.layout.ty)
125+
write!(f, "{}: {}", s.erase_tag(), self.layout.ty)
126126
}
127127
Immediate::ScalarPair(a, b) => {
128128
// FIXME(oli-obk): at least print tuples and slices nicely
129-
write!(f, "({:?}, {:?}): {}", a.erase_tag(), b.erase_tag(), self.layout.ty,)
129+
write!(f, "({}, {}): {}", a.erase_tag(), b.erase_tag(), self.layout.ty,)
130130
}
131131
}
132132
})

‎src/librustc_mir/util/pretty.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
use std::collections::BTreeSet;
2+
use std::fmt::Write as _;
3+
use std::fmt::{Debug, Display};
4+
use std::fs;
5+
use std::io::{self, Write};
6+
use std::path::{Path, PathBuf};
7+
18
use super::graphviz::write_mir_fn_graphviz;
29
use crate::transform::MirSource;
310
use either::Either;
411
use rustc_data_structures::fx::FxHashMap;
512
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
613
use rustc_index::vec::Idx;
714
use rustc_middle::mir::interpret::{
8-
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc,
15+
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer,
916
};
1017
use rustc_middle::mir::visit::Visitor;
1118
use rustc_middle::mir::*;
1219
use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
1320
use rustc_target::abi::Size;
14-
use std::collections::BTreeSet;
15-
use std::fmt::Display;
16-
use std::fmt::Write as _;
17-
use std::fs;
18-
use std::io::{self, Write};
19-
use std::path::{Path, PathBuf};
2021

2122
const INDENT: &str = " ";
2223
/// Alignment for lining up comments following MIR statements
@@ -635,7 +636,7 @@ pub fn write_allocations<'tcx>(
635636
/// After the hex dump, an ascii dump follows, replacing all unprintable characters (control
636637
/// characters or characters whose value is larger than 127) with a `.`
637638
/// This also prints relocations adequately.
638-
pub fn write_allocation<Tag, Extra>(
639+
pub fn write_allocation<Tag: Copy + Debug, Extra>(
639640
tcx: TyCtxt<'tcx>,
640641
alloc: &Allocation<Tag, Extra>,
641642
w: &mut dyn Write,
@@ -679,7 +680,7 @@ fn write_allocation_newline(
679680
/// The `prefix` argument allows callers to add an arbitrary prefix before each line (even if there
680681
/// is only one line). Note that your prefix should contain a trailing space as the lines are
681682
/// printed directly after it.
682-
fn write_allocation_bytes<Tag, Extra>(
683+
fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
683684
tcx: TyCtxt<'tcx>,
684685
alloc: &Allocation<Tag, Extra>,
685686
w: &mut dyn Write,
@@ -715,14 +716,20 @@ fn write_allocation_bytes<Tag, Extra>(
715716
if i != line_start {
716717
write!(w, " ")?;
717718
}
718-
if let Some(&(_, target_id)) = alloc.relocations().get(&i) {
719+
if let Some(&(tag, target_id)) = alloc.relocations().get(&i) {
719720
// Memory with a relocation must be defined
720721
let j = i.bytes_usize();
721722
let offset =
722723
alloc.inspect_with_undef_and_ptr_outside_interpreter(j..j + ptr_size.bytes_usize());
723724
let offset = read_target_uint(tcx.data_layout.endian, offset).unwrap();
725+
let offset = Size::from_bytes(offset);
724726
let relocation_width = |bytes| bytes * 3;
725-
let mut target = format!("{}+{}", target_id, offset);
727+
let ptr = Pointer::new_with_tag(target_id, offset, tag);
728+
let mut target = format!("{:?}", ptr);
729+
if target.len() > relocation_width(ptr_size.bytes_usize() - 1) {
730+
// This is too long, try to save some space.
731+
target = format!("{:#?}", ptr);
732+
}
726733
if ((i - line_start) + ptr_size).bytes_usize() > BYTES_PER_LINE {
727734
// This branch handles the situation where a relocation starts in the current line
728735
// but ends in the next one.

‎src/test/mir-opt/const_allocation/32bit/rustc.main.ConstProp.after.mir

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 8, align: 4) {
33-
alloc17+0╼ 03 00 00 00 │ ╾──╼....
33+
─a17+0x0─╼ 03 00 00 00 │ ╾──╼....
3434
}
3535

3636
alloc17 (size: 48, align: 4) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾alloc4+0─╼ 00 00 00 00 │ ....░░░░╾──╼....
38-
0x10 │ 00 00 00 00 __ __ __ __ ╾alloc8+0─╼ 02 00 00 00 │ ....░░░░╾──╼....
39-
0x20 │ 01 00 00 00 2a 00 00 00 ╾alloc13+0╼ 03 00 00 00 │ ....*...╾──╼....
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾─a4+0x0──╼ 00 00 00 00 │ ....░░░░╾──╼....
38+
0x10 │ 00 00 00 00 __ __ __ __ ╾─a8+0x0──╼ 02 00 00 00 │ ....░░░░╾──╼....
39+
0x20 │ 01 00 00 00 2a 00 00 00 ╾─a13+0x0─╼ 03 00 00 00 │ ....*...╾──╼....
4040
}
4141

4242
alloc4 (size: 0, align: 4) {}
4343

4444
alloc8 (size: 16, align: 4) {
45-
alloc7+0─╼ 03 00 00 00 ╾alloc9+0─╼ 03 00 00 00 │ ╾──╼....╾──╼....
45+
─a7+0x0──╼ 03 00 00 00 ╾─a9+0x0──╼ 03 00 00 00 │ ╾──╼....╾──╼....
4646
}
4747

4848
alloc7 (size: 3, align: 1) {
@@ -54,8 +54,8 @@ alloc9 (size: 3, align: 1) {
5454
}
5555

5656
alloc13 (size: 24, align: 4) {
57-
0x00 │ ╾alloc12+0╼ 03 00 00 00 ╾alloc14+0╼ 03 00 00 00 │ ╾──╼....╾──╼....
58-
0x10 │ ╾alloc15+0╼ 04 00 00 00 │ ╾──╼....
57+
0x00 │ ╾─a12+0x0─╼ 03 00 00 00 ╾─a14+0x0─╼ 03 00 00 00 │ ╾──╼....╾──╼....
58+
0x10 │ ╾─a15+0x0─╼ 04 00 00 00 │ ╾──╼....
5959
}
6060

6161
alloc12 (size: 3, align: 1) {

‎src/test/mir-opt/const_allocation/64bit/rustc.main.ConstProp.after.mir

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 16, align: 8) {
33-
╾─────alloc17+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
33+
╾─────alloc17+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
3434
}
3535

3636
alloc17 (size: 72, align: 8) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0───────╼ │ ....░░░░╾──────╼
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0x0──────╼ │ ....░░░░╾──────╼
3838
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
39-
0x20 │ ╾─────alloc8+0───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40-
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc13+0──────╼ │ ....*...╾──────╼
39+
0x20 │ ╾─────alloc8+0x0──────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40+
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc13+0x0─────╼ │ ....*...╾──────╼
4141
0x40 │ 03 00 00 00 00 00 00 00 │ ........
4242
}
4343

4444
alloc4 (size: 0, align: 8) {}
4545

4646
alloc8 (size: 32, align: 8) {
47-
0x00 │ ╾─────alloc7+0───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
48-
0x10 │ ╾─────alloc9+0───────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
47+
0x00 │ ╾─────alloc7+0x0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
48+
0x10 │ ╾─────alloc9+0x0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
4949
}
5050

5151
alloc7 (size: 3, align: 1) {
@@ -57,9 +57,9 @@ alloc9 (size: 3, align: 1) {
5757
}
5858

5959
alloc13 (size: 48, align: 8) {
60-
0x00 │ ╾─────alloc12+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
61-
0x10 │ ╾─────alloc14+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
62-
0x20 │ ╾─────alloc15+0──────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
60+
0x00 │ ╾─────alloc12+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
61+
0x10 │ ╾─────alloc14+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
62+
0x20 │ ╾─────alloc15+0x0─────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
6363
}
6464

6565
alloc12 (size: 3, align: 1) {

‎src/test/mir-opt/const_allocation2/32bit/rustc.main.ConstProp.after.mir

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 8, align: 4) {
33-
alloc21+0╼ 03 00 00 00 │ ╾──╼....
33+
─a21+0x0─╼ 03 00 00 00 │ ╾──╼....
3434
}
3535

3636
alloc21 (size: 48, align: 4) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾alloc4+0─╼ 00 00 00 00 │ ....░░░░╾──╼....
38-
0x10 │ 00 00 00 00 __ __ __ __ ╾alloc9+0─╼ 02 00 00 00 │ ....░░░░╾──╼....
39-
0x20 │ 01 00 00 00 2a 00 00 00 ╾alloc19+0╼ 03 00 00 00 │ ....*...╾──╼....
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾─a4+0x0──╼ 00 00 00 00 │ ....░░░░╾──╼....
38+
0x10 │ 00 00 00 00 __ __ __ __ ╾─a9+0x0──╼ 02 00 00 00 │ ....░░░░╾──╼....
39+
0x20 │ 01 00 00 00 2a 00 00 00 ╾─a19+0x0─╼ 03 00 00 00 │ ....*...╾──╼....
4040
}
4141

4242
alloc4 (size: 0, align: 4) {}
4343

4444
alloc9 (size: 8, align: 4) {
45-
alloc7+0─╼ ╾alloc8+0─╼ │ ╾──╼╾──╼
45+
─a7+0x0──╼ ╾─a8+0x0──╼ │ ╾──╼╾──╼
4646
}
4747

4848
alloc7 (size: 1, align: 1) {
@@ -54,7 +54,7 @@ alloc8 (size: 1, align: 1) {
5454
}
5555

5656
alloc19 (size: 12, align: 4) {
57-
alloc15+3╼ ╾alloc16+0╼ ╾alloc18+2╼ │ ╾──╼╾──╼╾──╼
57+
─a15+0x3─╼ ╾─a16+0x0─╼ ╾─a18+0x2─╼ │ ╾──╼╾──╼╾──╼
5858
}
5959

6060
alloc15 (size: 4, align: 1) {

‎src/test/mir-opt/const_allocation2/64bit/rustc.main.ConstProp.after.mir

+7-7
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 16, align: 8) {
33-
╾─────alloc21+0──────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
33+
╾─────alloc21+0x0─────╼ 03 00 00 00 00 00 00 00 │ ╾──────╼........
3434
}
3535

3636
alloc21 (size: 72, align: 8) {
37-
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0───────╼ │ ....░░░░╾──────╼
37+
0x00 │ 00 00 00 00 __ __ __ __ ╾─────alloc4+0x0──────╼ │ ....░░░░╾──────╼
3838
0x10 │ 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ │ ............░░░░
39-
0x20 │ ╾─────alloc9+0───────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40-
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc19+0──────╼ │ ....*...╾──────╼
39+
0x20 │ ╾─────alloc9+0x0──────╼ 02 00 00 00 00 00 00 00 │ ╾──────╼........
40+
0x30 │ 01 00 00 00 2a 00 00 00 ╾─────alloc19+0x0─────╼ │ ....*...╾──────╼
4141
0x40 │ 03 00 00 00 00 00 00 00 │ ........
4242
}
4343

4444
alloc4 (size: 0, align: 8) {}
4545

4646
alloc9 (size: 16, align: 8) {
47-
╾─────alloc7+0──────╼ ╾─────alloc8+0───────╼ │ ╾──────╼╾──────╼
47+
╾─────alloc7+0x0──────╼ ╾─────alloc8+0x0──────╼ │ ╾──────╼╾──────╼
4848
}
4949

5050
alloc7 (size: 1, align: 1) {
@@ -56,8 +56,8 @@ alloc8 (size: 1, align: 1) {
5656
}
5757

5858
alloc19 (size: 24, align: 8) {
59-
0x00 │ ╾─────alloc15+3─────╼ ╾─────alloc16+0──────╼ │ ╾──────╼╾──────╼
60-
0x10 │ ╾─────alloc18+2──────╼ │ ╾──────╼
59+
0x00 │ ╾─────alloc15+0x3─────╼ ╾─────alloc16+0x0─────╼ │ ╾──────╼╾──────╼
60+
0x10 │ ╾─────alloc18+0x2─────╼ │ ╾──────╼
6161
}
6262

6363
alloc15 (size: 4, align: 1) {

‎src/test/mir-opt/const_allocation3/32bit/rustc.main.ConstProp.after.mir

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 4, align: 4) {
33-
alloc9+0─╼ │ ╾──╼
33+
─a9+0x0──╼ │ ╾──╼
3434
}
3535

3636
alloc9 (size: 168, align: 1) {
3737
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
38-
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0─╼ │ ............╾──╼
38+
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾─a4+0x0──╼ │ ............╾──╼
3939
0x20 │ 01 ef cd ab 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4040
0x30 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4141
0x40 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4242
0x50 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4343
0x60 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4444
0x70 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
45-
0x80 │ 00 00 00 00 00 00 00 00 00 00 ╾alloc6+0─╼ 00 00 │ ..........╾──╼..
46-
0x90 │ ╾alloc7+99╼ 00 00 00 00 00 00 00 00 00 00 00 00 │ ╾──╼............
45+
0x80 │ 00 00 00 00 00 00 00 00 00 00 ╾─a6+0x0──╼ 00 00 │ ..........╾──╼..
46+
0x90 │ ╾─a7+0x63─╼ 00 00 00 00 00 00 00 00 00 00 00 00 │ ╾──╼............
4747
0xa0 │ 00 00 00 00 00 00 00 00 │ ........
4848
}
4949

‎src/test/mir-opt/const_allocation3/64bit/rustc.main.ConstProp.after.mir

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ fn main() -> () {
3030
}
3131

3232
alloc0 (static: FOO, size: 8, align: 8) {
33-
╾─────alloc9+0───────╼ │ ╾──────╼
33+
╾─────alloc9+0x0──────╼ │ ╾──────╼
3434
}
3535

3636
alloc9 (size: 180, align: 1) {
3737
0x00 │ ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab │ ................
38-
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0─ │ ............╾───
38+
0x10 │ ab ab ab ab ab ab ab ab ab ab ab ab ╾alloc4+0x0 │ ............╾───
3939
0x20 │ ──────────╼ 01 ef cd ab 00 00 00 00 00 00 00 00 │ ───╼............
4040
0x30 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4141
0x40 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4242
0x50 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4343
0x60 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4444
0x70 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4545
0x80 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ╾──── │ ..............╾─
46-
0x90 │ ───alloc6+0───╼ 00 00 ╾─────alloc7+99──────╼ │ ─────╼..╾──────╼
46+
0x90 │ ───alloc6+0x0───╼ 00 00 ╾─────alloc7+0x63─────╼ │ ─────╼..╾──────╼
4747
0xa0 │ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 │ ................
4848
0xb0 │ 00 00 00 00 │ ....
4949
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
22
--> $DIR/const-pointer-values-in-various-types.rs:25:5
33
|
44
LL | const I32_REF_USIZE_UNION: usize = unsafe { Nonsense { int_32_ref: &3 }.u };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain (non-pointer) bytes
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc2+0x0, but expected initialized plain (non-pointer) bytes
66
|
77
= 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.
88

@@ -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 a pointer, but expected initialized plain (non-pointer) bytes
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc22+0x0, 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 a pointer, but expected initialized plain (non-pointer) bytes
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc47+0x0, 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 a pointer, but expected initialized plain (non-pointer) bytes
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc62+0x0, 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 a pointer, but expected initialized plain (non-pointer) bytes
151+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc86+0x0, 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 a pointer, but expected initialized plain (non-pointer) bytes
191+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc101+0x0, 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 a pointer, but expected initialized plain (non-pointer) bytes
215+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc110+0x0, 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/double_check2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | / static FOO: (&Foo, &Bar) = unsafe {(
55
LL | | Union { u8: &BAR }.foo,
66
LL | | Union { u8: &BAR }.bar,
77
LL | | )};
8-
| |___^ type validation failed: encountered 5 at .1.<deref>, but expected a valid enum discriminant
8+
| |___^ type validation failed: encountered 0x05 at .1.<deref>, but expected a valid enum discriminant
99
|
1010
= 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.
1111

‎src/test/ui/consts/const-eval/ref_to_int_match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
22
--> $DIR/ref_to_int_match.rs:25:1
33
|
44
LL | const BAR: Int = unsafe { Foo { r: &42 }.f };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain (non-pointer) bytes
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc2+0x0, but expected initialized plain (non-pointer) bytes
66
|
77
= 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.
88

‎src/test/ui/consts/const-eval/transmute-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
22
--> $DIR/transmute-const.rs:5:1
33
|
44
LL | static FOO: bool = unsafe { mem::transmute(3u8) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3, but expected a boolean
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03, but expected a boolean
66
|
77
= 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.
88

‎src/test/ui/consts/const-eval/ub-enum.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// normalize-stderr-64bit "0x0000000000" -> "0x00"
12
#![feature(const_transmute, never_type)]
23
#![allow(const_err)] // make sure we cannot allow away the errors tested here
34

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

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,101 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-enum.rs:23:1
2+
--> $DIR/ub-enum.rs:24:1
33
|
44
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 1, but expected a valid enum discriminant
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x00000001, but expected a valid enum discriminant
66
|
77
= 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.
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/ub-enum.rs:26:1
10+
--> $DIR/ub-enum.rs:27:1
1111
|
1212
LL | const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc8+0x0 at .<enum-tag>, but expected initialized plain (non-pointer) bytes
1414
|
1515
= 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.
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/ub-enum.rs:29:1
18+
--> $DIR/ub-enum.rs:30:1
1919
|
2020
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc13+0x0 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

2525
error[E0080]: it is undefined behavior to use this value
26-
--> $DIR/ub-enum.rs:41:1
26+
--> $DIR/ub-enum.rs:42:1
2727
|
2828
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected a valid enum discriminant
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x00000000, but expected a valid enum discriminant
3030
|
3131
= 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.
3232

3333
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/ub-enum.rs:43:1
34+
--> $DIR/ub-enum.rs:44:1
3535
|
3636
LL | const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc20+0x0 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
42-
--> $DIR/ub-enum.rs:46:1
42+
--> $DIR/ub-enum.rs:47:1
4343
|
4444
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer at .0.<enum-tag>, but expected initialized plain (non-pointer) bytes
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc25+0x0 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

4949
error[E0080]: it is undefined behavior to use this value
50-
--> $DIR/ub-enum.rs:55:1
50+
--> $DIR/ub-enum.rs:56:1
5151
|
5252
LL | const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes at .<enum-tag>, but expected initialized plain (non-pointer) bytes
5454
|
5555
= 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.
5656

5757
error[E0080]: it is undefined behavior to use this value
58-
--> $DIR/ub-enum.rs:59:1
58+
--> $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 a pointer at .<enum-tag>, but expected initialized plain (non-pointer) bytes
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc32+0x0 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

6565
error[E0080]: it is undefined behavior to use this value
66-
--> $DIR/ub-enum.rs:76:1
66+
--> $DIR/ub-enum.rs:77:1
6767
|
6868
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of the never type `!` at .<enum-variant(B)>.0
7070
|
7171
= 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.
7272

7373
error[E0080]: it is undefined behavior to use this value
74-
--> $DIR/ub-enum.rs:78:1
74+
--> $DIR/ub-enum.rs:79:1
7575
|
7676
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of uninhabited type Never at .<enum-variant(D)>.0
7878
|
7979
= 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.
8080

8181
error[E0080]: it is undefined behavior to use this value
82-
--> $DIR/ub-enum.rs:86:1
82+
--> $DIR/ub-enum.rs:87:1
8383
|
8484
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
85-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 4294967295 at .<enum-variant(Some)>.0.1, but expected a valid unicode codepoint
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0xffffffff at .<enum-variant(Some)>.0.1, but expected a valid unicode codepoint
8686
|
8787
= 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.
8888

8989
error[E0080]: it is undefined behavior to use this value
90-
--> $DIR/ub-enum.rs:90:1
90+
--> $DIR/ub-enum.rs:91:1
9191
|
9292
LL | const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(1u64) };
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of the never type `!` at .<enum-variant(Err)>.0.1
9494
|
9595
= 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.
9696

9797
error[E0080]: it is undefined behavior to use this value
98-
--> $DIR/ub-enum.rs:92:1
98+
--> $DIR/ub-enum.rs:93:1
9999
|
100100
LL | const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(1u64) };
101101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of uninhabited type Never at .<enum-variant(Err)>.0.1

‎src/test/ui/consts/const-eval/ub-ref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error[E0080]: it is undefined behavior to use this value
3434
--> $DIR/ub-ref.rs:24:1
3535
|
3636
LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected initialized plain (non-pointer) bytes
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered pointer to alloc16+0x0, 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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ error[E0080]: it is undefined behavior to use this value
102102
--> $DIR/ub-wide-ptr.rs:75:1
103103
|
104104
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
105-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>[0], but expected a boolean
105+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>[0], but expected a boolean
106106
|
107107
= 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.
108108

109109
error[E0080]: it is undefined behavior to use this value
110110
--> $DIR/ub-wide-ptr.rs:81:1
111111
|
112112
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
113-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.0, but expected a boolean
113+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>.0, but expected a boolean
114114
|
115115
= 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.
116116

117117
error[E0080]: it is undefined behavior to use this value
118118
--> $DIR/ub-wide-ptr.rs:84:1
119119
|
120120
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
121-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.1[0], but expected a boolean
121+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>.1[0], but expected a boolean
122122
|
123123
= 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.
124124

@@ -162,7 +162,7 @@ error[E0080]: it is undefined behavior to use this value
162162
--> $DIR/ub-wide-ptr.rs:109:1
163163
|
164164
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
165-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.<dyn-downcast>, but expected a boolean
165+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x03 at .<deref>.<dyn-downcast>, but expected a boolean
166166
|
167167
= 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.
168168

‎src/test/ui/consts/const-eval/union-ub.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
22
--> $DIR/union-ub.rs:31:1
33
|
44
LL | const BAD_BOOL: bool = unsafe { DummyUnion { u8: 42 }.bool};
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected a boolean
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x2a, but expected a boolean
66
|
77
= 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.
88

0 commit comments

Comments
 (0)
Please sign in to comment.