You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)]`.
10
11
11
12
The following discusses each of these cases.
12
13
See the [keyword documentation][keyword] for some illustrative examples.
13
14
15
+
r[unsafe.positions]
16
+
The `unsafe` keyword can occur in several different contexts:
Copy file name to clipboardExpand all lines: src/unsafety.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,13 @@ r[safety.unsafe-deref]
13
13
- Dereferencing a [raw pointer].
14
14
15
15
r[safety.unsafe-static]
16
-
- Reading or writing a [mutable] or [external] static variable.
16
+
- Reading or writing a [mutable] or unsafe [external] static variable.
17
17
18
18
r[safety.unsafe-union-access]
19
19
- Accessing a field of a [`union`], other than to assign to it.
20
20
21
21
r[safety.unsafe-call]
22
-
- Calling an unsafe function (including an intrinsic or foreign function).
22
+
- Calling an unsafe function.
23
23
24
24
r[safety.unsafe-target-feature-call]
25
25
- Calling a safe function marked with a [`target_feature`][attributes.codegen.target_feature] from a function that does not have a `target_feature` attribute enabling the same features (see [attributes.codegen.target_feature.safety-restrictions]).
0 commit comments