Skip to content

Commit 7229647

Browse files
authored
Merge pull request #291 from ehuss/2024-initial-docs
Add some more initial stub docs for 2024.
2 parents 76bd48a + cab408d commit 7229647

6 files changed

+92
-0
lines changed

src/rust-2024/cargo-remove-implicit-features.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

5+
This feature has not yet been implemented.
6+
More information may be found in the tracking issue at <https://github.com/rust-lang/cargo/issues/12826>.
7+
58
## Summary
69

710
## Details

src/rust-2024/public-private-dependencies.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

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

710
## Details

src/rust-2024/rpit-lifetime-capture.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

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

710
## Details

src/rust-2024/rustfmt-overflow-delimited-expr.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

5+
This feature is not yet implemented.
6+
More information may be found in <https://github.com/rust-lang/rust/pull/114764>.
7+
58
## Summary
69

710
## Details

src/rust-2024/static-mut-reference.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@
44

55
## Summary
66

7+
- The [`static_mut_ref`] lint is now a hard error that cannot be disabled.
8+
This prevents taking a shared or mutable reference to a `static mut`.
9+
10+
[`static_mut_ref`]: ../../rustc/lints/listing/warn-by-default.html#static-mut-ref
11+
712
## Details
813

14+
Taking a reference to a [`static mut`] is no longer allowed:
15+
16+
<!-- edition2024,E0796 -->
17+
```rust
18+
static mut X: i32 = 23;
19+
static mut Y: i32 = 24;
20+
21+
unsafe {
22+
let y = &X; // ERROR: reference of mutable static
23+
let ref x = X; // ERROR: reference of mutable static
24+
let (x, y) = (&X, &Y); // ERROR: reference of mutable static
25+
}
26+
```
27+
28+
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.
29+
For example, another thread writing to the `static mut` will cause an aliasing violation and incur [Undefined Behavior].
30+
31+
<!-- TODO: Discuss possible alternatives. -->
32+
33+
[Undefined Behavior]: ../../reference/behavior-considered-undefined.html
34+
[`static mut`]: ../../reference/items/static-items.html#mutable-statics
35+
936
## Migration
37+
38+
🚧 The automatic migration for this has not yet been implemented.
39+
40+
<!-- TODO: Discuss alternatives around rewriting your code. -->

src/rust-2024/unsafe-op-in-unsafe-fn.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,55 @@
44

55
## Summary
66

7+
- The [`unsafe_op_in_unsafe_fn`] lint now warns by default.
8+
This warning detects calls to unsafe operations in unsafe functions without an explicit unsafe block.
9+
10+
[`unsafe_op_in_unsafe_fn`]: ../../rustc/lints/listing/allowed-by-default.html#unsafe-op-in-unsafe-fn
11+
712
## Details
813

14+
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].
15+
16+
```rust
17+
# #![warn(unsafe_op_in_unsafe_fn)]
18+
unsafe fn get_unchecked<T>(x: &[T], i: usize) -> &T {
19+
x.get_unchecked(i) // WARNING: requires unsafe block
20+
}
21+
```
22+
23+
The solution is to wrap any unsafe operations in an `unsafe` block:
24+
25+
```rust
26+
# #![deny(unsafe_op_in_unsafe_fn)]
27+
unsafe fn get_unchecked<T>(x: &[T], i: usize) -> &T {
28+
unsafe { x.get_unchecked(i) }
29+
}
30+
```
31+
32+
This change is intended to help protect against accidental use of unsafe operations in an unsafe function.
33+
The `unsafe` function keyword was performing two roles.
34+
One was to declare that *calling* the function requires unsafe, and that the caller is responsible to uphold additional safety requirements.
35+
The other role was to allow the use of unsafe operations inside of the function.
36+
This second role was determined to be too risky without explicit `unsafe` blocks.
37+
38+
More information and motivation may be found in [RFC #2585].
39+
40+
[unsafe operations]: ../../reference/unsafety.html
41+
[unsafe-block]: ../../reference/expressions/block-expr.html#unsafe-blocks
42+
[RFC #2585]: https://rust-lang.github.io/rfcs/2585-unsafe-block-in-unsafe-fn.html
43+
944
## Migration
45+
46+
The [`unsafe_op_in_unsafe_fn`] lint is part of the `rust-2024-compatibility` lint group.
47+
In order to migrate your code to be Rust 2024 Edition compatible, run:
48+
49+
```sh
50+
cargo fix --edition
51+
```
52+
53+
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.
54+
55+
```rust
56+
// Add this to the root of your crate to do a manual migration.
57+
#![warn(unsafe_op_in_unsafe_fn)]
58+
```

0 commit comments

Comments
 (0)