1
Fork 0

Make extern blocks without unsafe warn in edition 2024

This commit is contained in:
Santiago Pastorino 2024-05-21 12:27:21 -03:00
parent 46cd80b691
commit 3ba8de0b60
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
10 changed files with 78 additions and 7 deletions

View file

@ -66,6 +66,7 @@ declare_lint_pass! {
META_VARIABLE_MISUSE,
MISSING_ABI,
MISSING_FRAGMENT_SPECIFIER,
MISSING_UNSAFE_ON_EXTERN,
MUST_NOT_SUSPEND,
NAMED_ARGUMENTS_USED_POSITIONALLY,
NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
@ -4851,3 +4852,33 @@ declare_lint! {
reference: "issue #27970 <https://github.com/rust-lang/rust/issues/27970>",
};
}
declare_lint! {
/// The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations.
///
/// ### Example
///
/// ```rust,edition2024
/// extern "C" {
/// fn foo(_: i32);
/// }
///
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Declaring extern items, even without ever using them, can cause Undefined Behavior. We
/// should consider all sources of Undefined Behavior to be unsafe.
///
/// This is a [future-incompatible] lint to transition this to a
/// hard error in the future.
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub MISSING_UNSAFE_ON_EXTERN,
Allow,
"detects missing unsafe keyword on extern declarations",
@edition Edition2024 => Warn;
}