Skip to content

Commit 8401995

Browse files
authored
Merge pull request #459 from matthewjasper/more-unsafe
Note additional things as unsafe
2 parents 34c92dd + 95257ba commit 8401995

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/items/external-blocks.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ specified name.
101101
extern { }
102102
```
103103

104-
The type of a function declared in an extern block is `extern "abi" fn(A1, ...,
105-
An) -> R`, where `A1...An` are the declared types of its arguments and `R` is
106-
the declared return type.
104+
A function declared in an extern block is implicitly `unsafe`. When coerced to
105+
a function pointer, a function declared in an extern block has type `unsafe
106+
extern "abi" for<'l1, ..., 'lm> fn(A1, ..., An) -> R`, where `'l1`, ... `'lm`
107+
are its lifetime parameters, `A1`, ..., `An` are the declared types of its
108+
parameters and `R` is the declared return type.
109+
110+
It is `unsafe` to access a static item declared in an extern block, whether or
111+
not it's mutable.
107112

108113
It is valid to add the `link` attribute on an empty extern block. You can use
109114
this to satisfy the linking requirements of extern blocks elsewhere in your

src/unsafety.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ The following language level features cannot be used in the safe subset of
77
Rust:
88

99
- Dereferencing a [raw pointer].
10-
- Reading or writing a [mutable static variable].
11-
- Reading a field of a [`union`], or writing to a field of a
12-
union that isn't [`Copy`].
10+
- Reading or writing a [mutable] or [external] static variable.
11+
- Accessing a field of a [`union`], other than to assign to it.
1312
- Calling an unsafe function (including an intrinsic or foreign function).
1413
- Implementing an [unsafe trait].
1514

1615
[`Copy`]: special-types-and-traits.html#copy
1716
[`union`]: items/unions.html
1817
[mutable static variable]: items/static-items.html#mutable-statics
18+
[external static variable]: items/external-blocks.html
1919
[raw pointer]: types.html#pointer-types
2020
[unsafe trait]: items/traits.html#unsafe-traits

0 commit comments

Comments
 (0)