mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 11:13:43 +00:00
There are four uses of unsafe, actually
I am not mentioning #[unsafe_drop_flag] because it should go away eventually, and also because it's just an attribute, it's not really a use of the `unsafe` keyword. Fixes #26345
This commit is contained in:
parent
26f0cd5de7
commit
73df19a206
@ -8,7 +8,7 @@ this, Rust has a keyword, `unsafe`. Code using `unsafe` has less restrictions
|
||||
than normal code does.
|
||||
|
||||
Let’s go over the syntax, and then we’ll talk semantics. `unsafe` is used in
|
||||
two contexts. The first one is to mark a function as unsafe:
|
||||
four contexts. The first one is to mark a function as unsafe:
|
||||
|
||||
```rust
|
||||
unsafe fn danger_will_robinson() {
|
||||
@ -27,6 +27,19 @@ unsafe {
|
||||
}
|
||||
```
|
||||
|
||||
The third is for unsafe traits:
|
||||
|
||||
```rust
|
||||
unsafe trait Scary { }
|
||||
```
|
||||
|
||||
And the fourth is for `impl`ementing one of those traits:
|
||||
|
||||
```rust
|
||||
# unsafe trait Scary { }
|
||||
unsafe impl Scary for i32 {}
|
||||
```
|
||||
|
||||
It’s important to be able to explicitly delineate code that may have bugs that
|
||||
cause big problems. If a Rust program segfaults, you can be sure it’s somewhere
|
||||
in the sections marked `unsafe`.
|
||||
|
Loading…
Reference in New Issue
Block a user