Rollup merge of #26853 - steveklabnik:gh26346, r=Gankro

This incorrectly implied that doing things is fine in unsafe code

Fixes #26346
This commit is contained in:
Steve Klabnik 2015-07-07 09:49:55 -04:00
commit 10c795a6ea

View File

@ -33,9 +33,21 @@ in the sections marked `unsafe`.
# What does safe mean? # What does safe mean?
Safe, in the context of Rust, means “doesnt do anything unsafe.” Easy! Safe, in the context of Rust, means doesnt do anything unsafe. Its also
important to know that there are certain behaviors that are probably not
desirable in your code, but are expressly _not_ unsafe:
Okay, lets try again: what is not safe to do? Heres a list: * Deadlocks
* Leaks of memory or other resources
* Exiting without calling destructors
* Integer overflow
Rust cannot prevent all kinds of software problems. Buggy code can and will be
written in Rust. These things arent great, but they dont qualify as `unsafe`
specifically.
In addition, the following are all undefined behaviors in Rust, and must be
avoided, even when writing `unsafe` code:
* Data races * Data races
* Dereferencing a null/dangling raw pointer * Dereferencing a null/dangling raw pointer
@ -64,18 +76,6 @@ Okay, lets try again: what is not safe to do? Heres a list:
[undef]: http://llvm.org/docs/LangRef.html#undefined-values [undef]: http://llvm.org/docs/LangRef.html#undefined-values
[aliasing]: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules [aliasing]: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules
Whew! Thats a bunch of stuff. Its also important to notice all kinds of
behaviors that are certainly bad, but are expressly _not_ unsafe:
* Deadlocks
* Leaks of memory or other resources
* Exiting without calling destructors
* Integer overflow
Rust cannot prevent all kinds of software problems. Buggy code can and will be
written in Rust. These things arent great, but they dont qualify as `unsafe`
specifically.
# Unsafe Superpowers # Unsafe Superpowers
In both unsafe functions and unsafe blocks, Rust will let you do three things In both unsafe functions and unsafe blocks, Rust will let you do three things