about summary refs log tree commit diff
path: root/library/std/src/keyword_docs.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-28 15:17:13 +0000
committerbors <bors@rust-lang.org>2020-11-28 15:17:13 +0000
commite37f25aa3f356546ab851e394d5598fc575eabda (patch)
tree74c4ea90fdc836713c72cb393d1b8f442dd0e4c4 /library/std/src/keyword_docs.rs
parent4ae328bef47dffcbf363e5ae873f419c06a5511d (diff)
parent208d680f771601cf5efb6a7bfb49cb2b9e655d3e (diff)
downloadrust-e37f25aa3f356546ab851e394d5598fc575eabda.tar.gz
rust-e37f25aa3f356546ab851e394d5598fc575eabda.zip
Auto merge of #79507 - jonas-schievink:rollup-e5yeayh, r=jonas-schievink
Rollup of 10 pull requests

Successful merges:

 - #78086 (Improve doc for 'as _')
 - #78853 (rustc_parse: fix ConstBlock expr span)
 - #79234 (Resolve typedefs in HashMap gdb/lldb pretty-printers)
 - #79344 (Convert UNC path to local path to satisfy install script on Windows)
 - #79383 (Fix bold code formatting in keyword docs)
 - #79460 (Remove intermediate vectors from `add_bounds`)
 - #79474 (Change comments on types to doc-comments)
 - #79476 (Sync rustc_codegen_cranelift)
 - #79478 (Expand docs on Peekable::peek_mut)
 - #79486 (Slightly improve code samples in E0591)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/keyword_docs.rs')
-rw-r--r--library/std/src/keyword_docs.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs
index 80b74a9ba9b..dad3add5c55 100644
--- a/library/std/src/keyword_docs.rs
+++ b/library/std/src/keyword_docs.rs
@@ -20,19 +20,30 @@
 /// explicitly using `as` allows a few more coercions that aren't allowed implicitly, such as
 /// changing the type of a raw pointer or turning closures into raw pointers.
 ///
-/// `as` is also used to rename imports in [`use`] and [`extern crate`] statements:
+/// `as` can be seen as the primitive for `From` and `Into`: `as` only works  with primitives
+/// (`u8`, `bool`, `str`, pointers, ...) whereas `From` and `Into`  also works with types like
+/// `String` or `Vec`.
+///
+/// `as` can also be used with the `_` placeholder when the destination type can be inferred. Note
+/// that this can cause inference breakage and usually such code should use an explicit type for
+/// both clarity and stability. This is most useful when converting pointers using `as *const _` or
+/// `as *mut _` though the [`cast`][const-cast] method is recommended over `as *const _` and it is
+/// [the same][mut-cast] for `as *mut _`: those methods make the intent clearer.
+///
+/// `as` is also used to rename imports in [`use`] and [`extern crate`][`crate`] statements:
 ///
 /// ```
 /// # #[allow(unused_imports)]
 /// use std::{mem as memory, net as network};
 /// // Now you can use the names `memory` and `network` to refer to `std::mem` and `std::net`.
 /// ```
-///
 /// For more information on what `as` is capable of, see the [Reference].
 ///
 /// [Reference]: ../reference/expressions/operator-expr.html#type-cast-expressions
+/// [`crate`]: keyword.crate.html
 /// [`use`]: keyword.use.html
-/// [`extern crate`]: keyword.crate.html
+/// [const-cast]: primitive.pointer.html#method.cast
+/// [mut-cast]: primitive.pointer.html#method.cast-1
 mod as_keyword {}
 
 #[doc(keyword = "break")]
@@ -707,8 +718,8 @@ mod impl_keyword {}
 ///
 /// ## Literal Examples:
 ///
-///    * `for _ **in** 1..3 {}` - Iterate over an exclusive range up to but excluding 3.
-///    * `for _ **in** 1..=3 {}` - Iterate over an inclusive range up to and including 3.
+///    * `for _ in 1..3 {}` - Iterate over an exclusive range up to but excluding 3.
+///    * `for _ in 1..=3 {}` - Iterate over an inclusive range up to and including 3.
 ///
 /// (Read more about [range patterns])
 ///