rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.24k stars 12.71k forks source link

Tracking issue for release notes of #128771: Stabilize `unsafe_attributes` #129566

Closed rustbot closed 2 weeks ago

rustbot commented 2 months ago

This issue tracks the release notes text for #128771.

Release notes text:

The section title will be de-duplicated by the release team with other release notes issues. Prefer to use the standard titles from previous releases. More than one section can be included if needed.

# Language
- [Stabilize explicit opt-in to unsafe attributes](https://github.com/rust-lang/rust/pull/128771)

Release blog section (if any, leave blank if no section is expected):

traviscross commented 2 months ago

@RalfJung: Would you like to propose any language here? This is user-facing enough it seems perhaps worth a mention in the blog post.

cc @rust-lang/lang

RalfJung commented 2 months ago

Here's a sketch, but @carbotaniuman did the implementation and I didn't closely follow that so they are in a better position to refine this.

Unsafe attributes

Some of our attributes, such as no_mangle, can be used to cause Undefined Behavior without any unsafe block. If this was regular code we would require them to be placed in an unsafe {} block, but so far attributes have not had comparable syntax. To reflect the fact that these attributes can undermine Rust's safety guarantees, they are now considered "unsafe" and should be written as follows:

#[unsafe(no_mangle)]
pub fn my_global_function() { }

The old form of the attribute (without unsafe) is currently still accepted, but might be linted against at some point in the future, and will be a hard error in a future edition.

This affects the following attributes: