Skip to content

Commit

Permalink
Add test for E0796 error
Browse files Browse the repository at this point in the history
  • Loading branch information
obeis committed Nov 10, 2023
1 parent 30c0f1f commit de71124
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/ui/static/use_of_mutable_static_unsafe_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// compile-flags: --edition 2024 -Zunstable-options

fn main() {
static mut X: i32 = 1;
unsafe {
let _y = &X;
//~^ ERROR use of mutable static is discouraged
}
}
11 changes: 11 additions & 0 deletions tests/ui/static/use_of_mutable_static_unsafe_block.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0796]: use of mutable static is discouraged
--> $DIR/use_of_mutable_static_unsafe_block.rs:6:18
|
LL | let _y = &X;
| ^^ 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 previous error

For more information about this error, try `rustc --explain E0796`.
9 changes: 9 additions & 0 deletions tests/ui/static/use_of_mutable_static_unsafe_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// compile-flags: --edition 2024 -Zunstable-options

fn main() {}

unsafe fn _foo() {
static mut X: i32 = 1;
let _y = &X;
//~^ ERROR use of mutable static is discouraged
}
11 changes: 11 additions & 0 deletions tests/ui/static/use_of_mutable_static_unsafe_fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0796]: use of mutable static is discouraged
--> $DIR/use_of_mutable_static_unsafe_fn.rs:7:14
|
LL | let _y = &X;
| ^^ 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 previous error

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

0 comments on commit de71124

Please sign in to comment.