rust/tests/ui/rust-2024
Matthias Krüger 7d9ed2a864
Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors
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.
2024-08-03 20:51:51 +02:00
..
prelude-migration Add migration lint for 2024 prelude additions 2024-07-28 11:44:03 +02:00
unsafe-attributes Add hard error and migration lint for unsafe attrs 2024-06-23 19:02:14 -05:00
unsafe-extern-blocks Stabilize unsafe extern blocks (RFC 3484) 2024-07-23 00:29:39 -03:00
box-slice-into-iter-ambiguous.fixed Adjust the method ambiguity lint too 2024-05-20 19:21:38 -04:00
box-slice-into-iter-ambiguous.rs Adjust the method ambiguity lint too 2024-05-20 19:21:38 -04:00
box-slice-into-iter-ambiguous.stderr Adjust the method ambiguity lint too 2024-05-20 19:21:38 -04:00
gen-kw-in-macro.rs Make sure we don't deny macro vars w keyword names 2024-05-07 19:13:33 -04:00
gen-kw.e2015.stderr Make sure we don't deny macro vars w keyword names 2024-05-07 19:13:33 -04:00
gen-kw.e2018.stderr Make sure we don't deny macro vars w keyword names 2024-05-07 19:13:33 -04:00
gen-kw.rs Make sure we don't deny macro vars w keyword names 2024-05-07 19:13:33 -04:00
prelude2024.rs Add Future and IntoFuture to the 2024 prelude 2024-02-18 23:20:05 +01:00
safe-outside-extern.gated.stderr Don't allow unsafe statics outside of extern blocks 2024-07-18 18:02:29 -04:00
safe-outside-extern.rs Stabilize unsafe extern blocks (RFC 3484) 2024-07-23 00:29:39 -03:00
safe-outside-extern.stderr Stabilize unsafe extern blocks (RFC 3484) 2024-07-23 00:29:39 -03:00
safe-outside-extern.ungated.stderr Don't allow unsafe statics outside of extern blocks 2024-07-18 18:02:29 -04:00
unsafe-env-suggestion.fixed Rename deprecated_safe lint to deprecated_safe_2024 2024-07-17 14:39:56 +02:00
unsafe-env-suggestion.rs Rename deprecated_safe lint to deprecated_safe_2024 2024-07-17 14:39:56 +02:00
unsafe-env-suggestion.stderr Rename deprecated_safe lint to deprecated_safe_2024 2024-07-17 14:39:56 +02:00
unsafe-env.e2021.stderr Don't trigger unsafe_op_in_unsafe_fn for deprecated safe fns 2024-06-05 23:44:59 +02:00
unsafe-env.e2024.stderr Don't trigger unsafe_op_in_unsafe_fn for deprecated safe fns 2024-06-05 23:44:59 +02:00
unsafe-env.rs Don't trigger unsafe_op_in_unsafe_fn for deprecated safe fns 2024-06-05 23:44:59 +02:00