Skip to content

Commit cb4bd5a

Browse files
committed
Update ub-uninhabit tests
1 parent 9c66599 commit cb4bd5a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/librustc/ty/sty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,10 +1571,10 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
15711571
}
15721572
ty::Tuple(tys) => tys.iter().any(|ty| ty.conservative_is_uninhabited(tcx)),
15731573
ty::Array(ty, len) => {
1574-
match len.val.try_to_scalar() {
1574+
match len.assert_usize(tcx) {
15751575
// If the array is definitely non-empty, it's uninhabited if
15761576
// the type of its elements is uninhabited.
1577-
Some(n) if !n.is_null() => ty.conservative_is_uninhabited(tcx),
1577+
Some(n) if n != 0 => ty.conservative_is_uninhabited(tcx),
15781578
_ => false
15791579
}
15801580
}

src/test/ui/consts/const-eval/ub-uninhabit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ union TransmuteUnion<A: Clone + Copy, B: Clone + Copy> {
1212
}
1313

1414
const BAD_BAD_BAD: Bar = unsafe { (TransmuteUnion::<(), Bar> { a: () }).b };
15-
//~^ ERROR this constant likely exhibits undefined behavior
15+
//~^ ERROR it is undefined behavior to use this value
1616

1717
const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
1818
//~^ ERROR it is undefined behavior to use this value
1919

2020
const BAD_BAD_ARRAY: [Bar; 1] = unsafe { (TransmuteUnion::<(), [Bar; 1]> { a: () }).b };
21-
//~^ ERROR this constant likely exhibits undefined behavior
21+
//~^ ERROR it is undefined behavior to use this value
2222

2323
fn main() {}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/ub-uninhabit.rs:19:1
2+
--> $DIR/ub-uninhabit.rs:13:1
33
|
44
LL | const BAD_BAD_BAD: Bar = unsafe { (TransmuteUnion::<(), Bar> { a: () }).b };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type
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 rust compiler 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-uninhabit.rs:22:1
10+
--> $DIR/ub-uninhabit.rs:16:1
1111
|
1212
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>
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 rust compiler 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-uninhabit.rs:25:1
18+
--> $DIR/ub-uninhabit.rs:19:1
1919
|
2020
LL | const BAD_BAD_ARRAY: [Bar; 1] = unsafe { (TransmuteUnion::<(), [Bar; 1]> { a: () }).b };
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type

0 commit comments

Comments
 (0)