Skip to content

Commit 0e14b9f

Browse files
committed
Add tests
1 parent 6faad6d commit 0e14b9f

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/test/ui/consts/huge-values.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// build-pass
22
// ignore-32bit
33

4+
// This test is a canary test that will essentially not compile in a reasonable time frame
5+
// (so it'll take hours) if any of the optimizations regress. With the optimizations, these compile
6+
// in milliseconds just as if the length were set to `1`.
7+
48
#[derive(Clone, Copy)]
59
struct Foo;
610

711
fn main() {
812
let _ = [(); 4_000_000_000];
913
let _ = [0u8; 4_000_000_000];
1014
let _ = [Foo; 4_000_000_000];
15+
let _ = [(Foo, (), Foo, ((), Foo, [0; 0])); 4_000_000_000];
16+
let _ = [[0; 0]; 4_000_000_000];
1117
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#![feature(const_raw_ptr_deref, never_type)]
22

3-
const FOO: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR undefined behavior
3+
const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR undefined behavior
4+
const _: &[!; 0] = unsafe { &*(1_usize as *const [!; 0]) }; // ok
5+
const _: &[!] = unsafe { &*(1_usize as *const [!; 0]) }; // ok
6+
const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR undefined behavior
7+
const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) }; //~ ERROR undefined behavior
48

59
fn main() {}
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
error[E0080]: it is undefined behavior to use this value
22
--> $DIR/validate_never_arrays.rs:3:1
33
|
4-
LL | const FOO: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>
4+
LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>
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

9-
error: aborting due to previous error
9+
error[E0080]: it is undefined behavior to use this value
10+
--> $DIR/validate_never_arrays.rs:6:1
11+
|
12+
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) };
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>[0]
14+
|
15+
= 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.
16+
17+
error[E0080]: it is undefined behavior to use this value
18+
--> $DIR/validate_never_arrays.rs:7:1
19+
|
20+
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 42]) };
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>[0]
22+
|
23+
= 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.
24+
25+
error: aborting due to 3 previous errors
1026

1127
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)