Skip to content

Commit 407e8b3

Browse files
committed
Auto merge of #30126 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30108, #30114, #30115, #30119, #30120, #30122 - Failed merges:
2 parents a2866e3 + 06df5d8 commit 407e8b3

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

src/doc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ rustdoc reference.md
2929
An overview of how to use the `rustdoc` command is available [in the docs][1].
3030
Further details are available from the command line by with `rustdoc --help`.
3131

32-
[1]: https://github.com/rust-lang/rust/blob/master/src/doc/trpl/documentation.md
32+
[1]: https://github.com/rust-lang/rust/blob/master/src/doc/book/documentation.md

src/doc/book/casting-between-types.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ Coercion occurs in `let`, `const`, and `static` statements; in
1414
function call arguments; in field values in struct initialization; and in a
1515
function result.
1616

17-
The main cases of coercion are:
17+
The most common case of coercion is removing mutability from a reference:
1818

1919
* `&mut T` to `&T`
20+
21+
An analogous conversion is to remove mutability from a
22+
[raw pointer](raw-pointers.md):
2023

2124
* `*mut T` to `*const T`
25+
26+
References can also be coerced to raw pointers:
2227

2328
* `&T` to `*const T`
2429

2530
* `&mut T` to `*mut T`
26-
27-
* A custom coercion using [`Deref`](deref-coercions.md)
28-
31+
32+
Custom coercions may be defined using [`Deref`](deref-coercions.md).
33+
34+
Coercion is transitive.
2935

3036
# `as`
3137

@@ -64,6 +70,7 @@ For example
6470
```rust
6571
let one = true as u8;
6672
let at_sign = 64 as char;
73+
let two_hundred = -56i8 as u8;
6774
```
6875

6976
The semantics of numeric casts are:
@@ -94,9 +101,14 @@ The semantics of numeric casts are:
94101

95102
## Pointer casts
96103

97-
Perhaps surprisingly, it is safe to cast pointers to and from integers, and
98-
to cast between pointers to different types subject to some constraints. It
99-
is only unsafe to dereference the pointer.
104+
Perhaps surprisingly, it is safe to cast [raw pointers](raw-pointers.md) to and
105+
from integers, and to cast between pointers to different types subject to
106+
some constraints. It is only unsafe to dereference the pointer:
107+
108+
```rust
109+
let a = 300 as *const char; // a pointer to location 300
110+
let b = a as u32;
111+
```
100112

101113
`e as U` is a valid pointer cast in any of the following cases:
102114

src/doc/book/the-stack-and-the-heap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ stack frame. It grows upward, the more functions we call.
109109

110110
There are some important things we have to take note of here. The numbers 0, 1,
111111
and 2 are all solely for illustrative purposes, and bear no relationship to the
112-
actual numbers the computer will actually use. In particular, the series of
112+
address values the computer will use in reality. In particular, the series of
113113
addresses are in reality going to be separated by some number of bytes that
114114
separate each address, and that separation may even exceed the size of the
115115
value being stored.
@@ -464,7 +464,7 @@ At the end of `bar()`, it calls `baz()`:
464464
| (2<sup>30</sup>) - 2 | | 5 |
465465
| ... | ... | ... |
466466
| 12 | g | 100 |
467-
| 11 | f |9 |
467+
| 11 | f |(2<sup>30</sup>) - 2 |
468468
| 10 | e | → 9 |
469469
| 9 | d | → (2<sup>30</sup>) - 2 |
470470
| 8 | c | 5 |

src/libcollections/string.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,18 @@ impl ops::DerefMut for String {
11411141
}
11421142
}
11431143

1144-
/// Error returned from `String::from`
1144+
/// An error when parsing a `String`.
1145+
///
1146+
/// This `enum` is slightly awkward: it will never actually exist. This error is
1147+
/// part of the type signature of the implementation of [`FromStr`] on
1148+
/// [`String`]. The return type of [`from_str()`], requires that an error be
1149+
/// defined, but, given that a [`String`] can always be made into a new
1150+
/// [`String`] without error, this type will never actually be returned. As
1151+
/// such, it is only here to satisfy said signature, and is useless otherwise.
1152+
///
1153+
/// [`FromStr`]: ../str/trait.FromStr.html
1154+
/// [`String`]: struct.String.html
1155+
/// [`from_str()`]: ../str/trait.FromStr.html#tymethod.from_str
11451156
#[stable(feature = "str_parse_error", since = "1.5.0")]
11461157
#[derive(Copy)]
11471158
pub enum ParseError {}
@@ -1179,10 +1190,28 @@ impl PartialEq for ParseError {
11791190
#[stable(feature = "str_parse_error", since = "1.5.0")]
11801191
impl Eq for ParseError {}
11811192

1182-
/// A generic trait for converting a value to a string
1193+
/// A trait for converting a value to a `String`.
1194+
///
1195+
/// This trait is automatically implemented for any type which implements the
1196+
/// [`Display`] trait. As such, `ToString` shouldn't be implemented directly:
1197+
/// [`Display`] should be implemented instead, and you get the `ToString`
1198+
/// implementation for free.
1199+
///
1200+
/// [`Display`]: ../fmt/trait.Display.html
11831201
#[stable(feature = "rust1", since = "1.0.0")]
11841202
pub trait ToString {
1185-
/// Converts the value of `self` to an owned string
1203+
/// Converts the given value to a `String`.
1204+
///
1205+
/// # Examples
1206+
///
1207+
/// Basic usage:
1208+
///
1209+
/// ```
1210+
/// let i = 5;
1211+
/// let five = String::from("5");
1212+
///
1213+
/// assert_eq!(five, i.to_string());
1214+
/// ```
11861215
#[stable(feature = "rust1", since = "1.0.0")]
11871216
fn to_string(&self) -> String;
11881217
}

0 commit comments

Comments
 (0)