mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
7d9ed2a864
Stabilize unsafe extern blocks (RFC 3484) # Stabilization report ## Summary This is a tracking issue for the RFC 3484: Unsafe Extern Blocks We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](https://github.com/rust-lang/rfcs/pull/3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use. RFC: https://github.com/rust-lang/rfcs/pull/3484 Tracking issue: #123743 ## What is stabilized ### Summary of stabilization We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results. ```rust unsafe extern { // sqrt (from libm) may be called with any `f64` pub safe fn sqrt(x: f64) -> f64; // strlen (from libc) requires a valid pointer, // so we mark it as being an unsafe fn pub unsafe fn strlen(p: *const c_char) -> usize; // this function doesn't say safe or unsafe, so it defaults to unsafe pub fn free(p: *mut core::ffi::c_void); pub safe static IMPORTANT_BYTES: [u8; 256]; pub safe static LINES: SyncUnsafeCell<i32>; } ``` ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`. ## History - https://github.com/rust-lang/rust/pull/124482 - https://github.com/rust-lang/rust/pull/124455 - https://github.com/rust-lang/rust/pull/125077 - https://github.com/rust-lang/rust/pull/125522 - https://github.com/rust-lang/rust/issues/126738 - https://github.com/rust-lang/rust/issues/126749 - https://github.com/rust-lang/rust/issues/126755 - https://github.com/rust-lang/rust/pull/126757 - https://github.com/rust-lang/rust/pull/126758 - https://github.com/rust-lang/rust/issues/126756 - https://github.com/rust-lang/rust/pull/126973 - https://github.com/rust-lang/rust/pull/127535 - https://github.com/rust-lang/rustfmt/pull/6204 ## Unresolved questions I am not aware of any unresolved questions. |
||
---|---|---|
.. | ||
prelude-migration | ||
unsafe-attributes | ||
unsafe-extern-blocks | ||
box-slice-into-iter-ambiguous.fixed | ||
box-slice-into-iter-ambiguous.rs | ||
box-slice-into-iter-ambiguous.stderr | ||
gen-kw-in-macro.rs | ||
gen-kw.e2015.stderr | ||
gen-kw.e2018.stderr | ||
gen-kw.rs | ||
prelude2024.rs | ||
safe-outside-extern.gated.stderr | ||
safe-outside-extern.rs | ||
safe-outside-extern.stderr | ||
safe-outside-extern.ungated.stderr | ||
unsafe-env-suggestion.fixed | ||
unsafe-env-suggestion.rs | ||
unsafe-env-suggestion.stderr | ||
unsafe-env.e2021.stderr | ||
unsafe-env.e2024.stderr | ||
unsafe-env.rs |