Skip to content

Commit 2a4fb72

Browse files
authored
Merge pull request #4148 from rust-lang/unsafe-fn-blocks-separation
Rust 2024: distinguish `unsafe fn` vs. `unsafe` blocks
2 parents 5f1b7ab + 6f0d1f8 commit 2a4fb72

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ch20-01-unsafe-rust.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,14 @@ 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-
Bodies of unsafe functions are effectively `unsafe` blocks, so to perform other
190-
unsafe operations within an unsafe function, we don’t need to add another
191-
`unsafe` block.
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.
192197
193198
#### Creating a Safe Abstraction over Unsafe Code
194199

0 commit comments

Comments
 (0)