-
Notifications
You must be signed in to change notification settings - Fork 531
Statics may sometimes inline. #323
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,17 @@ | |
> `=` [_Expression_] `;` | ||
|
||
A *static item* is similar to a [constant], except that it represents a precise | ||
memory location in the program. A static is never "inlined" at the usage site, | ||
and all references to it refer to the same memory location. Static items have | ||
the `static` lifetime, which outlives all other lifetimes in a Rust program. | ||
Static items may be placed in read-only memory if the type is not [interior | ||
mutable]. Static items do not call `drop` at the end of the program. | ||
memory location in the program. All references to the static refer to the same | ||
memory location. Static items have the `static` lifetime, which outlives all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
other lifetimes in a Rust program. Non-`mut` static items that contain a type | ||
that is not [interior mutable] may be placed in read-only memory. Static items | ||
do not call [`drop`] at the end of the program. | ||
|
||
All access to a static is safe, but there are a number of restrictions on | ||
statics: | ||
|
||
* The type must have the `Sync` trait bound to allow thread-safe access. | ||
* Statics allow using paths to statics in the | ||
[constant-expression](expressions.html#constant-expressions) used to | ||
* Statics allow using paths to statics in the [constant-expression] used to | ||
initialize them, but statics may not refer to other statics by value, only | ||
through a reference. | ||
* Constants cannot refer to statics. | ||
|
@@ -33,7 +32,7 @@ modifications to a mutable static are safe with respect to other threads | |
running in the same process. | ||
|
||
Mutable statics are still very useful, however. They can be used with C | ||
libraries and can also be bound from C libraries (in an `extern` block). | ||
libraries and can also be bound from C libraries in an `extern` block. | ||
|
||
```rust | ||
# fn atomic_add(_: &mut u32, _: u32) -> u32 { 2 } | ||
|
@@ -66,10 +65,12 @@ item. Constants should, in general, be preferred over statics unless one of the | |
following are true: | ||
|
||
* Large amounts of data are being stored | ||
* The single-address or non-inlining property of statics is required. | ||
* The single-address property of statics is required. | ||
* Interior mutability is required. | ||
|
||
[constant]: items/constant-items.html | ||
[`drop`]: destructors.html | ||
[constant expression]: expressions.html#constant-expressions | ||
[interior mutable]: interior-mutability.html | ||
[IDENTIFIER]: identifiers.html | ||
[_Type_]: types.html | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph is just a list of properties, which makes me feel like it does not flow very well. I'm not sure the best way to address that; perhaps splitting the things about lifetimes into a separate paragraph would help, or adding more connective prose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It definitely doesn't flow well. It reads almost like a list but without the bullet points. Should probably be addressed, but not as part of this issue.