-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #95006 - tmiasko:thread-local-static, r=wesleywiser
Reject `#[thread_local]` attribute on non-static items
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|