Skip to content

Rollup of 13 pull requests #73880

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

Closed
wants to merge 31 commits into from
Closed
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0c88dd6
Update Box::from_raw example to generalize better
Keno Jun 24, 2020
2bbc2b3
Document the static keyword
poliorcetics Jun 25, 2020
00ef461
Merge pull request #2 from rust-lang/master
TyPR124 Jun 26, 2020
b71a3e1
Map ERROR_INVALID_PARAMETER to InvalidInput
TyPR124 Jun 26, 2020
0d0865f
Make `rustc_peek` a safe intrinsic
oli-obk Jun 27, 2020
765bd47
Recover extra trailing angle brackets in struct definition
Aaron1011 Jun 27, 2020
3fc5593
Document the type keyword
poliorcetics Jun 27, 2020
517d361
Use an 'approximate' universal upper bound when reporting region errors
Aaron1011 Jun 27, 2020
7055c23
ast_pretty: Pass some token streams and trees by reference
petrochenkov Jun 24, 2020
14d0370
Remove defunct `-Z print-region-graph`
tmiasko Jun 28, 2020
7231e57
Fix wording for anonymous parameter name help
nop Jun 28, 2020
e611a3f
Apply suggestions from code review
poliorcetics Jun 28, 2020
e8f5785
Split and expand nonstandard-style lints unicode unit test.
crlf0710 Jun 28, 2020
dfd454b
Apply suggestions, reformulating some paragraphs and improving some e…
poliorcetics Jun 28, 2020
824b2bb
Match on `Symbol` instead of `&str` for type-checking intrinsics.
oli-obk Jun 28, 2020
4224313
Fix small nits
poliorcetics Jun 28, 2020
4966272
Add newline to rustc MultiSpan docs
pierwill Jun 28, 2020
dd34698
Fix Zulip topic format
LeSeulArtichaut Jun 29, 2020
d8e0987
Rollup merge of #73678 - Keno:patch-1, r=LukasKalbertodt
Manishearth Jun 30, 2020
ffe4a21
Rollup merge of #73716 - poliorcetics:static-keyword, r=LukasKalbertodt
Manishearth Jun 30, 2020
7a3bc62
Rollup merge of #73752 - TyPR124:invalid-parameter-error, r=LukasKalb…
Manishearth Jun 30, 2020
fdd6590
Rollup merge of #73803 - Aaron1011:feature/angle-field-recovery, r=ma…
Manishearth Jun 30, 2020
86d4dc0
Rollup merge of #73805 - poliorcetics:type-keyword, r=kennytm
Manishearth Jun 30, 2020
0e585c3
Rollup merge of #73806 - Aaron1011:feature/approx-universal-upper, r=…
Manishearth Jun 30, 2020
0d2c65a
Rollup merge of #73812 - petrochenkov:prettyref, r=varkor
Manishearth Jun 30, 2020
1402233
Rollup merge of #73828 - nop:fix/parameter-name-help, r=estebank
Manishearth Jun 30, 2020
691ba6f
Rollup merge of #73834 - oli-obk:safe_intrinsics, r=ecstatic-morse
Manishearth Jun 30, 2020
366015b
Rollup merge of #73839 - crlf0710:snapshot_the_reality, r=Manishearth
Manishearth Jun 30, 2020
f7d23f4
Rollup merge of #73841 - tmiasko:print-region-graph, r=Mark-Simulacrum
Manishearth Jun 30, 2020
051117b
Rollup merge of #73853 - pierwill:pierwill-multispan-doc, r=jonas-sch…
Manishearth Jun 30, 2020
7f598c0
Rollup merge of #73865 - LeSeulArtichaut:patch-1, r=Dylan-DPC
Manishearth Jun 30, 2020
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
79 changes: 76 additions & 3 deletions src/libstd/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,11 +1281,84 @@ mod self_upper_keyword {}

#[doc(keyword = "static")]
//
/// A place that is valid for the duration of a program.
/// A static item is a value which is valid for the entire duration of your
/// program (a `'static` lifetime).
///
/// The documentation for this keyword is [not yet complete]. Pull requests welcome!
/// On the surface, `static` items seem very similar to [`const`]s: both contain
/// a value, both require type annotations and both can only be initialized with
/// constant functions and values. However, `static`s are notably different in
/// that they represent a location in memory. That means that you can have
/// references to `static` items and potentially even modify them, making them
/// essentially global variables.
///
/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
/// Static items do not call [`drop`] at the end of the program.
///
/// There are two types of `static` items: those declared in association with
/// the [`mut`] keyword and those without.
///
/// Static items cannot be moved:
///
/// ```rust,compile_fail,E0507
/// static VEC: Vec<u32> = vec![];
///
/// fn move_vec(v: Vec<u32>) -> Vec<u32> {
/// v
/// }
///
/// // This line causes an error
/// move_vec(VEC);
/// ```
///
/// # Simple `static`s
///
/// Accessing non-[`mut`] `static` items is considered safe, but some
/// restrictions apply. Most notably, the type of a `static` value needs to
/// implement the [`Sync`] trait, ruling out interior mutability containers
/// like [`RefCell`]. See the [Reference] for more information.
///
/// ```rust
/// static FOO: [i32; 5] = [1, 2, 3, 4, 5];
///
/// let r1 = &FOO as *const _;
/// let r2 = &FOO as *const _;
/// // With a strictly read-only static, references will have the same adress
/// assert_eq!(r1, r2);
/// // A static item can be used just like a variable in many cases
/// println!("{:?}", FOO);
/// ```
///
/// # Mutable `static`s
///
/// If a `static` item is declared with the [`mut`] keyword, then it is allowed
/// to be modified by the program. However, accessing mutable `static`s can
/// cause undefined behavior in a number of ways, for example due to data races
/// in a multithreaded context. As such, all accesses to mutable `static`s
/// require an [`unsafe`] block.
///
/// Despite their unsafety, mutable `static`s are necessary in many contexts:
/// they can be used to represent global state shared by the whole program or in
/// [`extern`] blocks to bind to variables from C libraries.
///
/// In an [`extern`] block:
///
/// ```rust,no_run
/// # #![allow(dead_code)]
/// extern "C" {
/// static mut ERROR_MESSAGE: *mut std::os::raw::c_char;
/// }
/// ```
///
/// Mutable `static`s, just like simple `static`s, have some restrictions that
/// apply to them. See the [Reference] for more information.
///
/// [`const`]: keyword.const.html
/// [`extern`]: keyword.extern.html
/// [`mut`]: keyword.mut.html
/// [`unsafe`]: keyword.unsafe.html
/// [`drop`]: mem/fn.drop.html
/// [`Sync`]: marker/trait.Sync.html
/// [`RefCell`]: cell/struct.RefCell.html
/// [Reference]: ../reference/items/static-items.html
mod static_keyword {}

#[doc(keyword = "struct")]
Expand Down