Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
886f81e
Fix sentence structure
Anirban166 Jun 23, 2020
0c88dd6
Update Box::from_raw example to generalize better
Keno Jun 24, 2020
3b5d7f8
Minor correction to sentence structure
Anirban166 Jun 24, 2020
d6cf8fc
Update README.md
Anirban166 Jun 24, 2020
2bbc2b3
Document the static keyword
poliorcetics Jun 25, 2020
22fc18f
Commit suggestion
Anirban166 Jun 25, 2020
8edcc6d
Add alternate text for rust logo image
Anirban166 Jun 25, 2020
3a1ac28
Added clickable-link
Anirban166 Jun 25, 2020
4c33b7c
Add responsiveness to logo
Anirban166 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
df88972
Update psm version
nagisa Jun 26, 2020
79a42e3
linker: Create GNU_EH_FRAME header by default when producing ELFs
petrochenkov Jun 20, 2020
765bd47
Recover extra trailing angle brackets in struct definition
Aaron1011 Jun 27, 2020
3fc5593
Document the type keyword
poliorcetics 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
4224313
Fix small nits
poliorcetics Jun 28, 2020
5239a68
add spans to injected coverage counters
richkadel Jun 22, 2020
f3645ca
remove rustdoc warnings
tshepang Jun 30, 2020
8afebc0
Stabilize `#[track_caller]`.
anp May 21, 2020
de36943
Rollup merge of #72445 - anp:stabilize-track-caller, r=oli-obk
Manishearth Jun 30, 2020
d8f38e9
Rollup merge of #73548 - tshepang:fix-rustdoc-warnings, r=ecstatic-morse
Manishearth Jun 30, 2020
9f330e4
Rollup merge of #73564 - petrochenkov:ehdr, r=Amanieu
Manishearth Jun 30, 2020
3de07e0
Rollup merge of #73649 - Anirban166:patch-1, r=steveklabnik
Manishearth Jun 30, 2020
c0809ed
Rollup merge of #73678 - Keno:patch-1, r=LukasKalbertodt
Manishearth Jun 30, 2020
dfefa37
Rollup merge of #73684 - richkadel:llvm-coverage-map-gen-2, r=wesleyw…
Manishearth Jun 30, 2020
78edd26
Rollup merge of #73716 - poliorcetics:static-keyword, r=LukasKalbertodt
Manishearth Jun 30, 2020
8c3acfc
Rollup merge of #73752 - TyPR124:invalid-parameter-error, r=LukasKalb…
Manishearth Jun 30, 2020
b849298
Rollup merge of #73781 - nagisa:psm-up, r=Mark-Simulacrum
Manishearth Jun 30, 2020
fc12919
Rollup merge of #73803 - Aaron1011:feature/angle-field-recovery, r=ma…
Manishearth Jun 30, 2020
f180d3d
Rollup merge of #73805 - poliorcetics:type-keyword, r=kennytm
Manishearth Jun 30, 2020
cfe8a08
Rollup merge of #73812 - petrochenkov:prettyref, r=varkor
Manishearth Jun 30, 2020
901ce7c
Rollup merge of #73828 - nop:fix/parameter-name-help, r=estebank
Manishearth Jun 30, 2020
9796035
Rollup merge of #73839 - crlf0710:snapshot_the_reality, r=Manishearth
Manishearth Jun 30, 2020
62793dc
Rollup merge of #73841 - tmiasko:print-region-graph, r=Mark-Simulacrum
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
Prev Previous commit
Next Next commit
Apply suggestions, reformulating some paragraphs and improving some e…
…xamples
  • Loading branch information
poliorcetics committed Jun 28, 2020
commit dfd454bd3843c4f4dee2e943297bf3d208252dc6
74 changes: 36 additions & 38 deletions src/libstd/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,22 +1030,39 @@ mod self_upper_keyword {}
//
/// A place that is valid for the duration of a program.
///
/// A `static` item is similar to a [`const`] item in that it lives for the
/// entire duration of the program and need to have its type explicited, with a
/// `static` lifetime, outliving any other lifetime. Added to that, `static`
/// items represent a precise memory location.
/// A static item is a value which is valid for the entire duration of your
/// program (a `'static` lifetime).
///
/// 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.
///
/// 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.
///
/// Items that are both static and owned cannot be moved:
///
/// ```rust,compile_fail,E0507
/// static VEC: Vec<u32> = vec![];
///
/// fn move_vec(v: Vec<u32>) -> Vec<u32> {
/// v
/// }
///
/// move_vec(VEC);
/// ```
///
/// # Simple `static`s
///
/// Non-[`mut`] `static` items that contain a type that is not interior mutable
/// may be placed in read-only memory. All access to a `static` item are
/// considered safe but some restrictions apply. See the [Reference] for more
/// information.
/// 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];
Expand All @@ -1054,43 +1071,22 @@ mod self_upper_keyword {}
/// let r2 = &FOO as *const _;
/// // With a strictly read-only static, references will have the same adress
/// assert_eq!(r1, r2);
/// // A static item is used just like a variable
/// 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. To make concurrency bugs hard to run into,
/// all access to a `static mut` require an [`unsafe`] block. Care should be
/// taken to ensure access (both read and write) are thread-safe.
/// 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 very useful: they can be used
/// to represent global state shared by the whole program or be used in
/// 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.
///
/// As global state:
///
/// ```rust
/// # #![allow(unused_variables)]
/// # fn main() {}
/// # fn atomic_add(_: &mut u32, _: u32) -> u32 { 2 }
/// static mut LEVELS: u32 = 0;
///
/// // This violates the idea of no shared state, and this doesn't internally
/// // protect against races, so this function is `unsafe`
/// unsafe fn bump_levels_unsafe1() -> u32 {
/// let ret = LEVELS;
/// LEVELS += 1;
/// return ret;
/// }
///
/// // Assuming that we have an atomic_add function which returns the old value,
/// // this function is "safe" but the meaning of the return value may not be
/// // what callers expect, so it's still marked as `unsafe`
/// unsafe fn bump_levels_unsafe2() -> u32 {
/// return atomic_add(&mut LEVELS, 1);
/// }
/// ```
///
/// In an [`extern`] block:
///
/// ```rust,no_run
Expand All @@ -1108,7 +1104,9 @@ mod self_upper_keyword {}
/// [`mut`]: keyword.mut.html
/// [`unsafe`]: keyword.unsafe.html
/// [`drop`]: mem/fn.drop.html
/// [Reference]: ../reference/items/static-items.html#static-items
/// [`Sync`]: marker/trait.Sync.html
/// [`RefCell`]: cell/struct.RefCell.html
/// [Reference]: ../reference/items/static-items.html
mod static_keyword {}

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