Closed
Description
When refactoring code, it's easy to accidentally end up with nested unsafe
blocks. This can lead to confusing rustc errors.
unsafe fn very_dangerous() -> u64 {
1
}
fn main() {
unsafe {
// lots of code...
unsafe {
very_dangerous();
}
}
The compiler says:
rustc 1.16.0-nightly (ff591b6dc 2017-01-15)
warning: unnecessary `unsafe` block, #[warn(unused_unsafe)] on by default
--> <anon>:9:9
|
9 | unsafe {
| _________^ starting here...
10 | | very_dangerous();
11 | | }
| |_________^ ...ending here
This is surprising at first glance, since very_dangerous
requires an unsafe
block but the message implies otherwise. Could we warn about nested unsafe
blocks?