Skip to content

Re-word UB in unsafe guide #26853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/doc/trpl/unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,21 @@ in the sections marked `unsafe`.

# What does ‘safe’ mean?

Safe, in the context of Rust, means “doesn’t do anything unsafe.” Easy!
Safe, in the context of Rust, means ‘doesn’t do anything unsafe’. It’s also
important to know that there are certain behaviors that are probably not
desirable in your code, but are expressly _not_ unsafe:

Okay, let’s try again: what is not safe to do? Here’s 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 aren’t great, but they don’t 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
* Dereferencing a null/dangling raw pointer
Expand Down Expand Up @@ -64,18 +76,6 @@ Okay, let’s try again: what is not safe to do? Here’s a list:
[undef]: http://llvm.org/docs/LangRef.html#undefined-values
[aliasing]: http://llvm.org/docs/LangRef.html#pointer-aliasing-rules

Whew! That’s a bunch of stuff. It’s 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 aren’t great, but they don’t qualify as `unsafe`
specifically.

# Unsafe Superpowers

In both unsafe functions and unsafe blocks, Rust will let you do three things
Expand Down