From debe597a9a4339f7ea7dc58fbfe8196aadacc593 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 26 Jul 2020 11:12:22 +0200 Subject: [PATCH] check that even referencing a TLS static during CTFE fails --- src/test/ui/consts/miri_unleashed/tls.rs | 7 +++++++ src/test/ui/consts/miri_unleashed/tls.stderr | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/ui/consts/miri_unleashed/tls.rs b/src/test/ui/consts/miri_unleashed/tls.rs index ba86a554bbb..7d4f8962a19 100644 --- a/src/test/ui/consts/miri_unleashed/tls.rs +++ b/src/test/ui/consts/miri_unleashed/tls.rs @@ -14,4 +14,11 @@ static TEST_BAD: () = { //~| NOTE cannot access thread local static }; +// Make sure we catch taking a reference to thread-local storage. +static TEST_BAD_REF: () = { + unsafe { let _val = &A; } + //~^ ERROR could not evaluate static initializer + //~| NOTE cannot access thread local static +}; + fn main() {} diff --git a/src/test/ui/consts/miri_unleashed/tls.stderr b/src/test/ui/consts/miri_unleashed/tls.stderr index d3e87f319ac..27d2b2df4d8 100644 --- a/src/test/ui/consts/miri_unleashed/tls.stderr +++ b/src/test/ui/consts/miri_unleashed/tls.stderr @@ -4,6 +4,12 @@ error[E0080]: could not evaluate static initializer LL | unsafe { let _val = A; } | ^ cannot access thread local static (DefId(0:4 ~ tls[317d]::A[0])) +error[E0080]: could not evaluate static initializer + --> $DIR/tls.rs:19:26 + | +LL | unsafe { let _val = &A; } + | ^ cannot access thread local static (DefId(0:4 ~ tls[317d]::A[0])) + warning: skipping const checks | help: skipping check that does not even have a feature gate @@ -11,7 +17,12 @@ help: skipping check that does not even have a feature gate | LL | unsafe { let _val = A; } | ^ +help: skipping check that does not even have a feature gate + --> $DIR/tls.rs:19:26 + | +LL | unsafe { let _val = &A; } + | ^ -error: aborting due to previous error; 1 warning emitted +error: aborting due to 2 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0080`.