Skip to content

Commit dd5ce5a

Browse files
committed
auto merge of #19105 : alfie/rust/master, r=thestinger
As discussed in pull #19068, trying to make the wording more clear for unsafe code vs undefined behavior.
2 parents 7936242 + e0b0c83 commit dd5ce5a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/doc/reference.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,13 @@ Rust:
11141114
##### Unsafe functions
11151115

11161116
Unsafe functions are functions that are not safe in all contexts and/or for all
1117-
possible inputs. Such a function must be prefixed with the keyword `unsafe`.
1117+
possible inputs. Such a function must be prefixed with the keyword `unsafe` and
1118+
can only be called from an `unsafe` block or another `unsafe` function.
11181119

11191120
##### Unsafe blocks
11201121

1121-
A block of code can also be prefixed with the `unsafe` keyword, to permit
1122-
calling `unsafe` functions or dereferencing raw pointers within a safe
1123-
function.
1122+
A block of code can be prefixed with the `unsafe` keyword, to permit calling
1123+
`unsafe` functions or dereferencing raw pointers within a safe function.
11241124

11251125
When a programmer has sufficient conviction that a sequence of potentially
11261126
unsafe operations is actually safe, they can encapsulate that sequence (taken
@@ -1140,12 +1140,11 @@ represented with reference-counted pointers in safe code. By using `unsafe`
11401140
blocks to represent the reverse links as raw pointers, it can be implemented
11411141
with only boxes.
11421142

1143-
##### Behavior considered unsafe
1143+
##### Behavior considered undefined
11441144

1145-
This is a list of behavior which is forbidden in all Rust code. Type checking
1146-
provides the guarantee that these issues are never caused by safe code. An
1147-
`unsafe` block or function is responsible for never invoking this behaviour or
1148-
exposing an API making it possible for it to occur in safe code.
1145+
The following is a list of behavior which is forbidden in all Rust code,
1146+
including within `unsafe` blocks and `unsafe` functions. Type checking provides
1147+
the guarantee that these issues are never caused by safe code.
11491148

11501149
* Data races
11511150
* Dereferencing a null/dangling raw pointer

0 commit comments

Comments
 (0)