Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some more initial stub docs for 2024. #291

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/rust-2024/cargo-remove-implicit-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".

This feature has not yet been implemented.
More information may be found in the tracking issue at <https://github.com/rust-lang/cargo/issues/12826>.

## Summary

## Details
Expand Down
3 changes: 3 additions & 0 deletions src/rust-2024/public-private-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".

This feature is only partially implemented, and not yet ready for testing.
More information may be found in the tracking issue at <https://github.com/rust-lang/rust/issues/44663>.

## Summary

## Details
Expand Down
3 changes: 3 additions & 0 deletions src/rust-2024/rpit-lifetime-capture.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".

This feature is partially implemented, and not yet ready for testing.
More information may be found in the tracking issue at <https://github.com/rust-lang/rust/issues/117587>.

## Summary

## Details
Expand Down
3 changes: 3 additions & 0 deletions src/rust-2024/rustfmt-overflow-delimited-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".

This feature is not yet implemented.
More information may be found in <https://github.com/rust-lang/rust/pull/114764>.

## Summary

## Details
Expand Down
31 changes: 31 additions & 0 deletions src/rust-2024/static-mut-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@

## Summary

- The [`static_mut_ref`] lint is now a hard error that cannot be disabled.
This prevents taking a shared or mutable reference to a `static mut`.

[`static_mut_ref`]: ../../rustc/lints/listing/warn-by-default.html#static-mut-ref

## Details

Taking a reference to a [`static mut`] is no longer allowed:

<!-- edition2024,E0796 -->
```rust
static mut X: i32 = 23;
static mut Y: i32 = 24;

unsafe {
let y = &X; // ERROR: reference of mutable static
let ref x = X; // ERROR: reference of mutable static
let (x, y) = (&X, &Y); // ERROR: reference of mutable static
}
```

Shared or mutable references of mutable static are almost always a mistake and can lead to undefined behavior and various other problems in your code.
For example, another thread writing to the `static mut` will cause an aliasing violation and incur [Undefined Behavior].

<!-- TODO: Discuss possible alternatives. -->

[Undefined Behavior]: ../../reference/behavior-considered-undefined.html
[`static mut`]: ../../reference/items/static-items.html#mutable-statics

## Migration

🚧 The automatic migration for this has not yet been implemented.

<!-- TODO: Discuss alternatives around rewriting your code. -->
49 changes: 49 additions & 0 deletions src/rust-2024/unsafe-op-in-unsafe-fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,55 @@

## Summary

- The [`unsafe_op_in_unsafe_fn`] lint now warns by default.
This warning detects calls to unsafe operations in unsafe functions without an explicit unsafe block.

[`unsafe_op_in_unsafe_fn`]: ../../rustc/lints/listing/allowed-by-default.html#unsafe-op-in-unsafe-fn

## Details

The [`unsafe_op_in_unsafe_fn`] lint will fire if there are [unsafe operations] in an unsafe function without an explicit [`unsafe {}` block][unsafe-block].

```rust
# #![warn(unsafe_op_in_unsafe_fn)]
unsafe fn get_unchecked<T>(x: &[T], i: usize) -> &T {
x.get_unchecked(i) // WARNING: requires unsafe block
}
```

The solution is to wrap any unsafe operations in an `unsafe` block:

```rust
# #![deny(unsafe_op_in_unsafe_fn)]
unsafe fn get_unchecked<T>(x: &[T], i: usize) -> &T {
unsafe { x.get_unchecked(i) }
}
```

This change is intended to help protect against accidental use of unsafe operations in an unsafe function.
The `unsafe` function keyword was performing two roles.
One was to declare that *calling* the function requires unsafe, and that the caller is responsible to uphold additional safety requirements.
The other role was to allow the use of unsafe operations inside of the function.
This second role was determined to be too risky without explicit `unsafe` blocks.

More information and motivation may be found in [RFC #2585].

[unsafe operations]: ../../reference/unsafety.html
[unsafe-block]: ../../reference/expressions/block-expr.html#unsafe-blocks
[RFC #2585]: https://rust-lang.github.io/rfcs/2585-unsafe-block-in-unsafe-fn.html

## Migration

The [`unsafe_op_in_unsafe_fn`] lint is part of the `rust-2024-compatibility` lint group.
In order to migrate your code to be Rust 2024 Edition compatible, run:

```sh
cargo fix --edition
```

Alternatively, you can manually enable the lint to find places where unsafe blocks need to be added, or switch it to `allow` to silence the lint completely.

```rust
// Add this to the root of your crate to do a manual migration.
#![warn(unsafe_op_in_unsafe_fn)]
```