Skip to content

Commit e0b0c83

Browse files
author
Alfie John
committed
doc: clarifying unsafe code vs undefined behavior
1 parent cf7df1e commit e0b0c83

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
@@ -1117,13 +1117,13 @@ Rust:
11171117
##### Unsafe functions
11181118

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

11221123
##### Unsafe blocks
11231124

1124-
A block of code can also be prefixed with the `unsafe` keyword, to permit
1125-
calling `unsafe` functions or dereferencing raw pointers within a safe
1126-
function.
1125+
A block of code can be prefixed with the `unsafe` keyword, to permit calling
1126+
`unsafe` functions or dereferencing raw pointers within a safe function.
11271127

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

1146-
##### Behavior considered unsafe
1146+
##### Behavior considered undefined
11471147

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

11531152
* Data races
11541153
* Dereferencing a null/dangling raw pointer

0 commit comments

Comments
 (0)