Skip to content

Commit

Permalink
Merge pull request rust-lang#459 from matthewjasper/more-unsafe
Browse files Browse the repository at this point in the history
Note additional things as unsafe
  • Loading branch information
Havvy authored Nov 3, 2018
2 parents 34c92dd + 95257ba commit 8401995
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/items/external-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ specified name.
extern { }
```

The type of a function declared in an extern block is `extern "abi" fn(A1, ...,
An) -> R`, where `A1...An` are the declared types of its arguments and `R` is
the declared return type.
A function declared in an extern block is implicitly `unsafe`. When coerced to
a function pointer, a function declared in an extern block has type `unsafe
extern "abi" for<'l1, ..., 'lm> fn(A1, ..., An) -> R`, where `'l1`, ... `'lm`
are its lifetime parameters, `A1`, ..., `An` are the declared types of its
parameters and `R` is the declared return type.

It is `unsafe` to access a static item declared in an extern block, whether or
not it's mutable.

It is valid to add the `link` attribute on an empty extern block. You can use
this to satisfy the linking requirements of extern blocks elsewhere in your
Expand Down
6 changes: 3 additions & 3 deletions src/unsafety.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ The following language level features cannot be used in the safe subset of
Rust:

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

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

0 comments on commit 8401995

Please sign in to comment.