Skip to content

Commit 7a6d03c

Browse files
committed
miri errors: rename InvalidDiscriminant -> InvalidTag
1 parent f7d745f commit 7a6d03c

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/librustc_middle/mir/interpret/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ pub enum UndefinedBehaviorInfo<'tcx> {
390390
InvalidBool(u8),
391391
/// Using a non-character `u32` as character.
392392
InvalidChar(u32),
393-
/// An enum discriminant was set to a value which was outside the range of valid values.
394-
InvalidDiscriminant(Scalar),
393+
/// The tag of an enum does not encode an actual discriminant.
394+
InvalidTag(Scalar),
395395
/// Using a pointer-not-to-a-function as function pointer.
396396
InvalidFunctionPointer(Pointer),
397397
/// Using a string that is not valid UTF-8,
@@ -463,7 +463,7 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
463463
InvalidChar(c) => {
464464
write!(f, "interpreting an invalid 32-bit value as a char: 0x{:08x}", c)
465465
}
466-
InvalidDiscriminant(val) => write!(f, "enum value has invalid discriminant: {}", val),
466+
InvalidTag(val) => write!(f, "enum value has invalid tag: {}", val),
467467
InvalidFunctionPointer(p) => {
468468
write!(f, "using {} as function pointer but it does not point to a function", p)
469469
}

src/librustc_mir/interpret/operand.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::layout::{PrimitiveExt, TyAndLayout};
1111
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer};
1212
use rustc_middle::ty::Ty;
1313
use rustc_middle::{mir, ty};
14-
use rustc_target::abi::{Abi, TagEncoding, HasDataLayout, LayoutOf, Size};
14+
use rustc_target::abi::{Abi, HasDataLayout, LayoutOf, Size, TagEncoding};
1515
use rustc_target::abi::{VariantIdx, Variants};
1616

1717
use super::{
@@ -641,7 +641,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
641641
TagEncoding::Direct => {
642642
let tag_bits = self
643643
.force_bits(tag_val, tag_layout.size)
644-
.map_err(|_| err_ub!(InvalidDiscriminant(tag_val.erase_tag())))?;
644+
.map_err(|_| err_ub!(InvalidTag(tag_val.erase_tag())))?;
645645
// Cast bits from tag layout to discriminant layout.
646646
let discr_val = self.cast_from_scalar(tag_bits, tag_layout, discr_layout.ty);
647647
let discr_bits = discr_val.assert_bits(discr_layout.size);
@@ -658,7 +658,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
658658
}
659659
_ => bug!("tagged layout for non-adt non-generator"),
660660
}
661-
.ok_or_else(|| err_ub!(InvalidDiscriminant(tag_val.erase_tag())))?;
661+
.ok_or_else(|| err_ub!(InvalidTag(tag_val.erase_tag())))?;
662662
// Return the cast value, and the index.
663663
(discr_val, index.0)
664664
}
@@ -674,7 +674,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
674674
&& variants_start == variants_end
675675
&& !self.memory.ptr_may_be_null(ptr);
676676
if !ptr_valid {
677-
throw_ub!(InvalidDiscriminant(tag_val.erase_tag()))
677+
throw_ub!(InvalidTag(tag_val.erase_tag()))
678678
}
679679
dataful_variant
680680
}

src/librustc_mir/interpret/validity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
696696
try_validation!(
697697
self.walk_value(op),
698698
self.path,
699-
err_ub!(InvalidDiscriminant(val)) =>
700-
{ "{}", val } expected { "a valid enum discriminant" },
699+
err_ub!(InvalidTag(val)) =>
700+
{ "{}", val } expected { "a valid enum tag" },
701701
err_unsup!(ReadPointerAsBytes) =>
702702
{ "a pointer" } expected { "plain (non-pointer) bytes" },
703703
);

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 0x05 at .1.<deref>, but expected a valid enum discriminant
8+
| |___^ type validation failed: encountered 0x05 at .1.<deref>, but expected a valid enum tag
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/ub-enum.stderr

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

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

0 commit comments

Comments
 (0)