-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
10 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,26 @@ | ||
#![allow(unused, dead_code)] | ||
|
||
static mut FOO: u64 = 0; | ||
|
||
fn static_mod() { | ||
unsafe {static BAR: u64 = FOO;} | ||
//~^ ERROR: use of mutable static is unsafe | ||
//~| NOTE: use of mutable static | ||
//~| NOTE: mutable statics can be mutated by multiple threads | ||
//~| NOTE: items do not inherit unsafety | ||
} | ||
|
||
unsafe fn unsafe_call() {} | ||
fn foo() { | ||
unsafe { | ||
//~^ NOTE: items do not inherit unsafety | ||
fn bar() { | ||
unsafe_call(); | ||
//~^ ERROR: call to unsafe function | ||
//~| NOTE: call to unsafe function | ||
//~| NOTE: consult the function's documentation | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
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,24 @@ | ||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block | ||
--> $DIR/unsafe-not-inherited.rs:6:31 | ||
| | ||
LL | unsafe {static BAR: u64 = FOO;} | ||
| ------ ^^^ use of mutable static | ||
| | | ||
| items do not inherit unsafety from separate enclosing items | ||
| | ||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior | ||
|
||
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block | ||
--> $DIR/unsafe-not-inherited.rs:18:13 | ||
| | ||
LL | unsafe { | ||
| ------ items do not inherit unsafety from separate enclosing items | ||
... | ||
LL | unsafe_call(); | ||
| ^^^^^^^^^^^^^ call to unsafe function | ||
| | ||
= note: consult the function's documentation for information on how to avoid undefined behavior | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |