forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#85419 - LeSeulArtichaut:thir-unsafeck-3, r=…
…nikomatsakis Check for use of mutable/extern statics in THIR unsafeck Extends THIR unsafeck to check for use of mutable and extern statics. r? `@ghost` (I don't want to flood Niko's review queue) cc rust-lang/project-thir-unsafeck#7
- Loading branch information
Showing
26 changed files
with
237 additions
and
24 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
2 changes: 1 addition & 1 deletion
2
src/test/ui/intrinsics/issue-28575.stderr → ...test/ui/intrinsics/issue-28575.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![feature(intrinsics)] | ||
|
||
extern "C" { | ||
|
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,11 @@ | ||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-28575.rs:11:5 | ||
| | ||
LL | FOO() | ||
| ^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
2 changes: 1 addition & 1 deletion
2
src/test/ui/issues/issue-14227.stderr → src/test/ui/issues/issue-14227.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
extern "C" { | ||
pub static symbol: 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,11 @@ | ||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-14227.rs:7:21 | ||
| | ||
LL | static CRASH: u32 = symbol; | ||
| ^^^^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
mod Y { | ||
pub type X = usize; | ||
extern "C" { | ||
|
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,27 @@ | ||
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/issue-16538.rs:14:27 | ||
| | ||
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `*const usize` cannot be shared between threads safely | ||
--> $DIR/issue-16538.rs:14:1 | ||
| | ||
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const usize` cannot be shared between threads safely | ||
| | ||
= help: the trait `Sync` is not implemented for `*const usize` | ||
= note: shared static variables must have a type that implements `Sync` | ||
|
||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-16538.rs:14:34 | ||
| | ||
LL | static foo: *const Y::X = Y::foo(Y::x as *const Y::X); | ||
| ^^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0015, E0133, E0277. | ||
For more information about an error, try `rustc --explain E0015`. |
2 changes: 1 addition & 1 deletion
2
src/test/ui/issues/issue-28324.stderr → src/test/ui/issues/issue-28324.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
extern "C" { | ||
static error_message_count: 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,11 @@ | ||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/issue-28324.rs:8:25 | ||
| | ||
LL | pub static BAZ: u32 = *&error_message_count; | ||
| ^^^^^^^^^^^^^^^^^^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
8 changes: 4 additions & 4 deletions
8
src/test/ui/safe-extern-statics-mut.stderr → ...est/ui/safe-extern-statics-mut.mir.stderr
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
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,35 @@ | ||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics-mut.rs:13:13 | ||
| | ||
LL | let b = B; | ||
| ^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics-mut.rs:14:15 | ||
| | ||
LL | let rb = &B; | ||
| ^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics-mut.rs:15:14 | ||
| | ||
LL | let xb = XB; | ||
| ^^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics-mut.rs:16:16 | ||
| | ||
LL | let xrb = &XB; | ||
| ^^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
8 changes: 4 additions & 4 deletions
8
src/test/ui/safe-extern-statics.stderr → src/test/ui/safe-extern-statics.mir.stderr
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
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,35 @@ | ||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics.rs:13:13 | ||
| | ||
LL | let a = A; | ||
| ^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics.rs:14:15 | ||
| | ||
LL | let ra = &A; | ||
| ^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics.rs:15:14 | ||
| | ||
LL | let xa = XA; | ||
| ^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of extern static is unsafe and requires unsafe function or block | ||
--> $DIR/safe-extern-statics.rs:16:16 | ||
| | ||
LL | let xra = &XA; | ||
| ^^ use of extern static | ||
| | ||
= note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
6 changes: 3 additions & 3 deletions
6
...static-mut-foreign-requires-unsafe.stderr → ...ic-mut-foreign-requires-unsafe.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
extern "C" { | ||
static mut a: i32; | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
src/test/ui/static/static-mut-foreign-requires-unsafe.thir.stderr
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,27 @@ | ||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/static-mut-foreign-requires-unsafe.rs:9:5 | ||
| | ||
LL | a += 3; | ||
| ^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/static-mut-foreign-requires-unsafe.rs:10:5 | ||
| | ||
LL | a = 4; | ||
| ^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/static-mut-foreign-requires-unsafe.rs:11:14 | ||
| | ||
LL | let _b = a; | ||
| ^ use of mutable static | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
Oops, something went wrong.