Skip to content

Commit ceb496c

Browse files
committed
improve validity error range printing for singleton ranges
1 parent d9d6b3b commit ceb496c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/librustc_mir/interpret/validity.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,16 @@ fn wrapping_range_format(r: &RangeInclusive<u128>, max_hi: u128) -> String {
151151
debug_assert!(hi <= max_hi);
152152
if lo > hi {
153153
format!("less or equal to {}, or greater or equal to {}", hi, lo)
154+
} else if lo == hi {
155+
format!("equal to {}", lo)
156+
} else if lo == 0 {
157+
debug_assert!(hi < max_hi, "should not be printing if the range covers everything");
158+
format!("less or equal to {}", hi)
159+
} else if hi == max_hi {
160+
debug_assert!(lo > 0, "should not be printing if the range covers everything");
161+
format!("greater or equal to {}", lo)
154162
} else {
155-
if lo == 0 {
156-
debug_assert!(hi < max_hi, "should not be printing if the range covers everything");
157-
format!("less or equal to {}", hi)
158-
} else if hi == max_hi {
159-
format!("greater or equal to {}", lo)
160-
} else {
161-
format!("in the range {:?}", r)
162-
}
163+
format!("in the range {:?}", r)
163164
}
164165
}
165166

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

+2-2
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:28:1
1919
|
2020
LL | const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { TransmuteEnum { in1: &1 }.out2 };
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected something that cannot possibly fail to be less or equal to 0
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected something that cannot possibly fail to be equal to 0
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 rust compiler repository if you believe it should not be considered undefined behavior
2424

@@ -42,7 +42,7 @@ error[E0080]: it is undefined behavior to use this value
4242
--> $DIR/ub-enum.rs:50:1
4343
|
4444
LL | const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { TransmuteEnum2 { in2: &0 }.out2 };
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected something that cannot possibly fail to be in the range 2..=2
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected something that cannot possibly fail to be equal to 2
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 rust compiler repository if you believe it should not be considered undefined behavior
4848

0 commit comments

Comments
 (0)