rustc_lint::builtin

Static UNSAFE_ATTR_OUTSIDE_UNSAFE

source
pub static UNSAFE_ATTR_OUTSIDE_UNSAFE: &'static Lint
Expand description

The unsafe_attr_outside_unsafe lint detects a missing unsafe keyword on attributes considered unsafe.

§Example

#![warn(unsafe_attr_outside_unsafe)]

#[no_mangle]
extern "C" fn foo() {}

fn main() {}

{{produces}}

§Explanation

Some attributes (e.g. no_mangle, export_name, link_section – see issue #82499 for a more complete list) are considered “unsafe” attributes. An unsafe attribute must only be used inside unsafe(…).

This lint can automatically wrap the attributes in unsafe(...) , but this obviously cannot verify that the preconditions of the unsafe attributes are fulfilled, so that is still up to the user.

The lint is currently “allow” by default, but that might change in the future.