-
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.
Add a lint against never type fallback affecting unsafe code
- Loading branch information
1 parent
7c653c9
commit 14f1124
Showing
7 changed files
with
258 additions
and
11 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
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
35 changes: 35 additions & 0 deletions
35
tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs
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 @@ | ||
//@ check-pass | ||
use std::mem; | ||
|
||
fn main() { | ||
if false { | ||
unsafe { mem::zeroed() } | ||
//~^ warn: never type fallback affects this call to an `unsafe` function | ||
} else { | ||
return; | ||
}; | ||
|
||
// no ; -> type is inferred without fallback | ||
if true { unsafe { mem::zeroed() } } else { return } | ||
} | ||
|
||
// Minimization of the famous `objc` crate issue | ||
fn _objc() { | ||
pub unsafe fn send_message<R>() -> Result<R, ()> { | ||
Ok(unsafe { core::mem::zeroed() }) | ||
} | ||
|
||
macro_rules! msg_send { | ||
() => { | ||
match send_message::<_ /* ?0 */>() { | ||
//~^ warn: never type fallback affects this call to an `unsafe` function | ||
Ok(x) => x, | ||
Err(_) => loop {}, | ||
} | ||
}; | ||
} | ||
|
||
unsafe { | ||
msg_send!(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.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,23 @@ | ||
warning: never type fallback affects this call to an `unsafe` function | ||
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:6:18 | ||
| | ||
LL | unsafe { mem::zeroed() } | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= help: specify the type explicitly | ||
= note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default | ||
|
||
warning: never type fallback affects this call to an `unsafe` function | ||
--> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:24:19 | ||
| | ||
LL | match send_message::<_ /* ?0 */>() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | msg_send!(); | ||
| ----------- in this macro invocation | ||
| | ||
= help: specify the type explicitly | ||
= note: this warning originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
warning: 2 warnings emitted | ||
|