about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2022-03-16 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2022-03-16 13:00:33 +0100
commit5e7610378f5dce4f3cfdaf05fbafc962d000ffcd (patch)
tree293ff233b52ccb0739973ffd2756212d741bd33c /src/test
parentd8e564715e0eb17130e99e8fcc92a36fce7feaf5 (diff)
downloadrust-5e7610378f5dce4f3cfdaf05fbafc962d000ffcd.tar.gz
rust-5e7610378f5dce4f3cfdaf05fbafc962d000ffcd.zip
Reject `#[thread_local]` attribute on non-static items
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/thread-local/non-static.rs30
-rw-r--r--src/test/ui/thread-local/non-static.stderr38
2 files changed, 68 insertions, 0 deletions
diff --git a/src/test/ui/thread-local/non-static.rs b/src/test/ui/thread-local/non-static.rs
new file mode 100644
index 00000000000..f1c4273870b
--- /dev/null
+++ b/src/test/ui/thread-local/non-static.rs
@@ -0,0 +1,30 @@
+// Check that #[thread_local] attribute is rejected on non-static items.
+#![feature(thread_local)]
+
+#[thread_local]
+//~^ ERROR attribute should be applied to a static
+const A: u32 = 0;
+
+#[thread_local]
+//~^ ERROR attribute should be applied to a static
+fn main() {
+    #[thread_local] || {};
+    //~^ ERROR attribute should be applied to a static
+}
+
+struct S {
+    #[thread_local]
+    //~^ ERROR attribute should be applied to a static
+    a: String,
+    b: String,
+}
+
+#[thread_local]
+// Static. OK.
+static B: u32 = 0;
+
+extern "C" {
+    #[thread_local]
+    // Foreign static. OK.
+    static C: u32;
+}
diff --git a/src/test/ui/thread-local/non-static.stderr b/src/test/ui/thread-local/non-static.stderr
new file mode 100644
index 00000000000..09a1618d6e7
--- /dev/null
+++ b/src/test/ui/thread-local/non-static.stderr
@@ -0,0 +1,38 @@
+error: attribute should be applied to a static
+  --> $DIR/non-static.rs:4:1
+   |
+LL | #[thread_local]
+   | ^^^^^^^^^^^^^^^
+LL |
+LL | const A: u32 = 0;
+   | ----------------- not a static
+
+error: attribute should be applied to a static
+  --> $DIR/non-static.rs:8:1
+   |
+LL |   #[thread_local]
+   |   ^^^^^^^^^^^^^^^
+LL |
+LL | / fn main() {
+LL | |     #[thread_local] || {};
+LL | |
+LL | | }
+   | |_- not a static
+
+error: attribute should be applied to a static
+  --> $DIR/non-static.rs:11:5
+   |
+LL |     #[thread_local] || {};
+   |     ^^^^^^^^^^^^^^^ ----- not a static
+
+error: attribute should be applied to a static
+  --> $DIR/non-static.rs:16:5
+   |
+LL |     #[thread_local]
+   |     ^^^^^^^^^^^^^^^
+LL |
+LL |     a: String,
+   |     --------- not a static
+
+error: aborting due to 4 previous errors
+