Skip to content

Commit debe597

Browse files
committed
check that even referencing a TLS static during CTFE fails
1 parent 1d9efbb commit debe597

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/test/ui/consts/miri_unleashed/tls.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ static TEST_BAD: () = {
1414
//~| NOTE cannot access thread local static
1515
};
1616

17+
// Make sure we catch taking a reference to thread-local storage.
18+
static TEST_BAD_REF: () = {
19+
unsafe { let _val = &A; }
20+
//~^ ERROR could not evaluate static initializer
21+
//~| NOTE cannot access thread local static
22+
};
23+
1724
fn main() {}

src/test/ui/consts/miri_unleashed/tls.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@ error[E0080]: could not evaluate static initializer
44
LL | unsafe { let _val = A; }
55
| ^ cannot access thread local static (DefId(0:4 ~ tls[317d]::A[0]))
66

7+
error[E0080]: could not evaluate static initializer
8+
--> $DIR/tls.rs:19:26
9+
|
10+
LL | unsafe { let _val = &A; }
11+
| ^ cannot access thread local static (DefId(0:4 ~ tls[317d]::A[0]))
12+
713
warning: skipping const checks
814
|
915
help: skipping check that does not even have a feature gate
1016
--> $DIR/tls.rs:12:25
1117
|
1218
LL | unsafe { let _val = A; }
1319
| ^
20+
help: skipping check that does not even have a feature gate
21+
--> $DIR/tls.rs:19:26
22+
|
23+
LL | unsafe { let _val = &A; }
24+
| ^
1425

15-
error: aborting due to previous error; 1 warning emitted
26+
error: aborting due to 2 previous errors; 1 warning emitted
1627

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

0 commit comments

Comments
 (0)