Auto merge of #30126 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30108, #30114, #30115, #30119, #30120, #30122 - Failed merges:
This commit is contained in:
commit
407e8b3aac
@ -29,4 +29,4 @@ rustdoc reference.md
|
||||
An overview of how to use the `rustdoc` command is available [in the docs][1].
|
||||
Further details are available from the command line by with `rustdoc --help`.
|
||||
|
||||
[1]: https://github.com/rust-lang/rust/blob/master/src/doc/trpl/documentation.md
|
||||
[1]: https://github.com/rust-lang/rust/blob/master/src/doc/book/documentation.md
|
||||
|
@ -14,18 +14,24 @@ Coercion occurs in `let`, `const`, and `static` statements; in
|
||||
function call arguments; in field values in struct initialization; and in a
|
||||
function result.
|
||||
|
||||
The main cases of coercion are:
|
||||
The most common case of coercion is removing mutability from a reference:
|
||||
|
||||
* `&mut T` to `&T`
|
||||
|
||||
An analogous conversion is to remove mutability from a
|
||||
[raw pointer](raw-pointers.md):
|
||||
|
||||
* `*mut T` to `*const T`
|
||||
|
||||
References can also be coerced to raw pointers:
|
||||
|
||||
* `&T` to `*const T`
|
||||
|
||||
* `&mut T` to `*mut T`
|
||||
|
||||
* A custom coercion using [`Deref`](deref-coercions.md)
|
||||
|
||||
|
||||
Custom coercions may be defined using [`Deref`](deref-coercions.md).
|
||||
|
||||
Coercion is transitive.
|
||||
|
||||
# `as`
|
||||
|
||||
@ -64,6 +70,7 @@ For example
|
||||
```rust
|
||||
let one = true as u8;
|
||||
let at_sign = 64 as char;
|
||||
let two_hundred = -56i8 as u8;
|
||||
```
|
||||
|
||||
The semantics of numeric casts are:
|
||||
@ -94,9 +101,14 @@ The semantics of numeric casts are:
|
||||
|
||||
## Pointer casts
|
||||
|
||||
Perhaps surprisingly, it is safe to cast pointers to and from integers, and
|
||||
to cast between pointers to different types subject to some constraints. It
|
||||
is only unsafe to dereference the pointer.
|
||||
Perhaps surprisingly, it is safe to cast [raw pointers](raw-pointers.md) to and
|
||||
from integers, and to cast between pointers to different types subject to
|
||||
some constraints. It is only unsafe to dereference the pointer:
|
||||
|
||||
```rust
|
||||
let a = 300 as *const char; // a pointer to location 300
|
||||
let b = a as u32;
|
||||
```
|
||||
|
||||
`e as U` is a valid pointer cast in any of the following cases:
|
||||
|
||||
|
@ -109,7 +109,7 @@ stack frame. It grows upward, the more functions we call.
|
||||
|
||||
There are some important things we have to take note of here. The numbers 0, 1,
|
||||
and 2 are all solely for illustrative purposes, and bear no relationship to the
|
||||
actual numbers the computer will actually use. In particular, the series of
|
||||
address values the computer will use in reality. In particular, the series of
|
||||
addresses are in reality going to be separated by some number of bytes that
|
||||
separate each address, and that separation may even exceed the size of the
|
||||
value being stored.
|
||||
@ -464,7 +464,7 @@ At the end of `bar()`, it calls `baz()`:
|
||||
| (2<sup>30</sup>) - 2 | | 5 |
|
||||
| ... | ... | ... |
|
||||
| 12 | g | 100 |
|
||||
| 11 | f | → 9 |
|
||||
| 11 | f | → (2<sup>30</sup>) - 2 |
|
||||
| 10 | e | → 9 |
|
||||
| 9 | d | → (2<sup>30</sup>) - 2 |
|
||||
| 8 | c | 5 |
|
||||
|
@ -1141,7 +1141,18 @@ impl ops::DerefMut for String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error returned from `String::from`
|
||||
/// An error when parsing a `String`.
|
||||
///
|
||||
/// This `enum` is slightly awkward: it will never actually exist. This error is
|
||||
/// part of the type signature of the implementation of [`FromStr`] on
|
||||
/// [`String`]. The return type of [`from_str()`], requires that an error be
|
||||
/// defined, but, given that a [`String`] can always be made into a new
|
||||
/// [`String`] without error, this type will never actually be returned. As
|
||||
/// such, it is only here to satisfy said signature, and is useless otherwise.
|
||||
///
|
||||
/// [`FromStr`]: ../str/trait.FromStr.html
|
||||
/// [`String`]: struct.String.html
|
||||
/// [`from_str()`]: ../str/trait.FromStr.html#tymethod.from_str
|
||||
#[stable(feature = "str_parse_error", since = "1.5.0")]
|
||||
#[derive(Copy)]
|
||||
pub enum ParseError {}
|
||||
@ -1179,10 +1190,28 @@ impl PartialEq for ParseError {
|
||||
#[stable(feature = "str_parse_error", since = "1.5.0")]
|
||||
impl Eq for ParseError {}
|
||||
|
||||
/// A generic trait for converting a value to a string
|
||||
/// A trait for converting a value to a `String`.
|
||||
///
|
||||
/// This trait is automatically implemented for any type which implements the
|
||||
/// [`Display`] trait. As such, `ToString` shouldn't be implemented directly:
|
||||
/// [`Display`] should be implemented instead, and you get the `ToString`
|
||||
/// implementation for free.
|
||||
///
|
||||
/// [`Display`]: ../fmt/trait.Display.html
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub trait ToString {
|
||||
/// Converts the value of `self` to an owned string
|
||||
/// Converts the given value to a `String`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let i = 5;
|
||||
/// let five = String::from("5");
|
||||
///
|
||||
/// assert_eq!(five, i.to_string());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
fn to_string(&self) -> String;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user