Skip to content

Commit

Permalink
Merge pull request rust-lang#1138 from stephaneyfx/master
Browse files Browse the repository at this point in the history
Fixed some statements regarding Drop, Sync, const and static
  • Loading branch information
carols10cents authored Jan 29, 2018
2 parents df18aec + 1034a34 commit 356f7f8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions first-edition/src/const-and-static.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ reference stored in a static has a [`'static` lifetime][lifetimes]:
static NAME: &'static str = "Steve";
```

The type of a `static` value must be `Sync` unless the `static` value is
mutable.

[lifetimes]: lifetimes.html

## Mutability
Expand All @@ -64,17 +67,20 @@ unsafe {

[unsafe]: unsafe.html

Furthermore, any type stored in a `static` must be `Sync`, and must not have
a [`Drop`][drop] implementation.

[drop]: drop.html

# Initializing

Both `const` and `static` have requirements for giving them a value. They must
be given a value that’s a constant expression. In other words, you cannot use
the result of a function call or anything similarly complex or at runtime.

# Dropping

Types implementing [`Drop`][drop] are allowed in `const` and `static`
definitions. Constants are inlined where they are used and are dropped
accordingly. `static` values are not dropped.

[drop]: drop.html

# Which construct should I use?

Almost always, if you can choose between the two, choose `const`. It’s pretty
Expand Down

0 comments on commit 356f7f8

Please sign in to comment.