Skip to content

Commit 3b88b41

Browse files
committed
Revise unsafe keyword chapter
In light of `unsafe extern`, we need to note that this is another position that `unsafe` is allowed. While we're here, let's make some further revisions to clean up the start of this chapter, including separating off into a rule these allowed positions. Co-authored-by: ehuss
1 parent b9a3735 commit 3b88b41

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/unsafe-keyword.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@ r[unsafe]
22
# The `unsafe` keyword
33

44
r[unsafe.intro]
5-
The `unsafe` keyword can occur in several different contexts:
6-
unsafe functions (`unsafe fn`), unsafe blocks (`unsafe {}`), unsafe traits (`unsafe trait`), unsafe trait implementations (`unsafe impl`), unsafe external blocks (`unsafe extern`), and unsafe attributes (`#[unsafe(attr)]`).
7-
It plays several different roles, depending on where it is used and whether the `unsafe_op_in_unsafe_fn` lint is enabled:
8-
- it is used to mark code that *defines* extra safety conditions (`unsafe fn`, `unsafe trait`)
9-
- it is used to mark code that needs to *satisfy* extra safety conditions (`unsafe {}`, `unsafe impl`, `unsafe fn` without [`unsafe_op_in_unsafe_fn`], `unsafe extern`, `#[unsafe(attr)]`)
5+
The `unsafe` keyword is used to create or discharge the obligation to prove something safe. Specifically:
6+
7+
- It is used to mark code that *defines* extra safety conditions that must be upheld elsewhere.
8+
- This includes `unsafe fn`, `unsafe static`, and `unsafe trait`.
9+
- It is used to mark code that the programmer *asserts* satisfies safety conditions defined elsewhere.
10+
- This includes `unsafe {}`, `unsafe impl`, `unsafe fn` without [`unsafe_op_in_unsafe_fn`], `unsafe extern`, and `#[unsafe(attr)]`.
1011

1112
The following discusses each of these cases.
1213
See the [keyword documentation][keyword] for some illustrative examples.
1314

15+
r[unsafe.positions]
16+
The `unsafe` keyword can occur in several different contexts:
17+
18+
- unsafe functions (`unsafe fn`)
19+
- unsafe blocks (`unsafe {}`)
20+
- unsafe traits (`unsafe trait`)
21+
- unsafe trait implementations (`unsafe impl`)
22+
- unsafe external blocks (`unsafe extern`)
23+
- unsafe external statics (`unsafe static`)
24+
- unsafe attributes (`#[unsafe(attr)]`)
25+
1426
r[unsafe.fn]
1527
## Unsafe functions (`unsafe fn`)
1628

0 commit comments

Comments
 (0)