Skip to content

Commit 9ee4d1a

Browse files
committed
reword Miri validity errors: undefined -> uninitialized
1 parent 351eefe commit 9ee4d1a

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/librustc_mir/interpret/validity.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
322322
let value = self.ecx.read_immediate(value)?;
323323
// Handle wide pointers.
324324
// Check metadata early, for better diagnostics
325-
let place = try_validation!(self.ecx.ref_to_mplace(value), "undefined pointer", self.path);
325+
let place = try_validation!(
326+
self.ecx.ref_to_mplace(value),
327+
format_args!("uninitialized {}", kind),
328+
self.path
329+
);
326330
if place.layout.is_unsized() {
327331
self.check_wide_ptr_meta(place.meta, place.layout)?;
328332
}
@@ -334,7 +338,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
334338
format_args!("invalid {} metadata: {}", kind, msg),
335339
self.path
336340
),
337-
_ => bug!("Unexpected error during ptr size_and_align_of: {}", err),
341+
_ => bug!("unexpected error during ptr size_and_align_of: {}", err),
338342
},
339343
};
340344
let (size, align) = size_and_align
@@ -477,10 +481,11 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
477481
}
478482
ty::RawPtr(..) => {
479483
// We are conservative with undef for integers, but try to
480-
// actually enforce our current rules for raw pointers.
484+
// actually enforce the strict rules for raw pointers (mostly because
485+
// that lets us re-use `ref_to_mplace`).
481486
let place = try_validation!(
482487
self.ecx.ref_to_mplace(self.ecx.read_immediate(value)?),
483-
"undefined pointer",
488+
"uninitialized raw pointer",
484489
self.path
485490
);
486491
if place.layout.is_unsized() {
@@ -776,14 +781,14 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
776781
// For some errors we might be able to provide extra information
777782
match err.kind {
778783
err_ub!(InvalidUndefBytes(Some(ptr))) => {
779-
// Some byte was undefined, determine which
784+
// Some byte was uninitialized, determine which
780785
// element that byte belongs to so we can
781786
// provide an index.
782787
let i = usize::try_from(ptr.offset.bytes() / layout.size.bytes())
783788
.unwrap();
784789
self.path.push(PathElem::ArrayElem(i));
785790

786-
throw_validation_failure!("undefined bytes", self.path)
791+
throw_validation_failure!("uninitialized value", self.path)
787792
}
788793
// Other errors shouldn't be possible
789794
_ => return Err(err),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ LL | |
6262
LL | | let uninit_len = MaybeUninit::<usize> { uninit: () };
6363
LL | | mem::transmute((42, uninit_len))
6464
LL | | };
65-
| |__^ type validation failed: encountered undefined pointer
65+
| |__^ type validation failed: encountered uninitialized reference
6666
|
6767
= 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.
6868

@@ -130,7 +130,7 @@ LL | |
130130
LL | | let uninit_len = MaybeUninit::<usize> { uninit: () };
131131
LL | | mem::transmute((42, uninit_len))
132132
LL | | };
133-
| |__^ type validation failed: encountered undefined pointer
133+
| |__^ type validation failed: encountered uninitialized raw pointer
134134
|
135135
= 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.
136136

src/test/ui/consts/const-eval/union-ice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LL | | unsafe { UNION.field3 },
2727
... |
2828
LL | | a: 42,
2929
LL | | };
30-
| |__^ type validation failed: encountered undefined bytes at .b[1]
30+
| |__^ type validation failed: encountered uninitialized value at .b[1]
3131
|
3232
= 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.
3333

0 commit comments

Comments
 (0)