Skip to content

Commit 3e2e8b9

Browse files
committed
Disallow to optimise out constants in OOB tests
Apparently our constant errors are only reported if there’s a use in MIR for that constant. This means that in these tests `let _ = B` is seen as a no-op use and thus is optimised out. Explicitly drop() the B to make sure it is not optimised (yet, until the inliner happens). NB: the `let _ = B` statement discussed here has no side effects (such as Drop implementation).
1 parent 935dc8d commit 3e2e8b9

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/test/compile-fail/array_const_index-0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ const B: i32 = (&A)[1];
1414
//~| index out of bounds: the len is 0 but the index is 1
1515

1616
fn main() {
17-
let _ = B;
17+
drop(B);
1818
}

src/test/compile-fail/array_const_index-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ const B: i32 = A[1];
1414
//~| index out of bounds: the len is 0 but the index is 1
1515

1616
fn main() {
17-
let _ = B;
17+
drop(B);
1818
}

src/test/compile-fail/const-array-oob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ const BLUB: [u32; FOO[4]] = [5, 6];
2020
//~| index out of bounds: the len is 3 but the index is 4
2121

2222
fn main() {
23-
let _ = BAR;
23+
drop(BAR);
2424
}

src/test/compile-fail/const-slice-oob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ const BAR: u32 = FOO[5];
1414
//~| index out of bounds: the len is 3 but the index is 5
1515

1616
fn main() {
17-
let _ = BAR;
17+
drop(BAR);
1818
}

0 commit comments

Comments
 (0)