Skip to content

Commit 289c4ff

Browse files
committed
Improve note on unsafe functions and unsafe blocks
See discussion in rust-lang#4147, rust-lang#4148.
1 parent c4cede2 commit 289c4ff

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/ch20-01-unsafe-rust.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,13 @@ With the `unsafe` block, we’re asserting to Rust that we’ve read the functio
186186
documentation, we understand how to use it properly, and we’ve verified that
187187
we’re fulfilling the contract of the function.
188188

189-
> Note: In earlier versions of Rust, the body of an unsafe function was treated
190-
> as an `unsafe` block, so you could perform any unsafe operation within the
191-
> body of an `unsafe` function. In later versions of Rust, the compiler will
192-
> warn you that you need to use an `unsafe` block to perform unsafe operations
193-
> in the body of an unsafe function. This is because Rust now distinguishes
194-
> between `unsafe fn`, which defines what you need to do to call the function
195-
> safely, and an `unsafe` block, where you actually uphold that “contract” the
196-
> function establishes.
189+
> Note: In earlier editions of Rust, the body of an unsafe function was treated
190+
> as an `unsafe` block, so you could perform any unsafe operation within it.
191+
> Starting with the 2024 edition, the compiler will warn you that you need to
192+
> use an `unsafe` block to perform unsafe operations even in the body of an
193+
> unsafe function. This helps to keep `unsafe` blocks as small as possible, as
194+
> unsafe operations may not be needed across the whole function body. For more
195+
> information about Rust editions, refer to [Appendix E][editions].
197196
198197
#### Creating a Safe Abstraction over Unsafe Code
199198

@@ -540,4 +539,5 @@ that the code you have written upholds Rust’s rules.
540539
[the-slice-type]: ch04-03-slices.html#the-slice-type
541540
[reference]: ../reference/items/unions.html
542541
[miri]: https://github.com/rust-lang/miri
542+
[editions]: appendix-05-editions.html
543543
[nightly]: appendix-07-nightly-rust.html

0 commit comments

Comments
 (0)