Skip to content
Closed
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08b0aca
string: implement From<&String> for String
jsgf Apr 9, 2019
eba03d4
Fix convert module's documentation links
czipperz Apr 12, 2019
6bf94cd
Remove dangling ` in Into documentation
czipperz Apr 13, 2019
b701d32
Remove broken links to self in Into documentation
czipperz Apr 13, 2019
4a33ece
Remove blank lines in AsRef documentation
czipperz Apr 13, 2019
27ff536
Reorder blank lines in AsMut documentation
czipperz Apr 13, 2019
1e48da6
Escape &str in convert docs
czipperz Apr 13, 2019
1f5d510
Fix stray ` in previous change
czipperz Apr 14, 2019
c921aae
Include expression to wait for to the span of Await
topecongiro May 10, 2019
1ea7c5f
Update ui test
topecongiro May 10, 2019
e392db6
Update rustc book CLI docs.
ehuss May 12, 2019
d29f0d2
Move token tree related lexer state to a separate struct
matklad May 12, 2019
b91e0a3
move span and token to tt reader
matklad May 13, 2019
e249f2e
move raw span to tt reader
matklad May 13, 2019
ea93215
Bump measureme dependency to 0.3
wesleywiser May 14, 2019
7171bd1
README: Mention MSVC 2017+, not 2013(!)
scottmcm May 14, 2019
1107158
Use `Symbol` more in lint APIs
oli-obk May 14, 2019
65d09ea
Move `box` from the stable keyword to unstable keywords list
Pulkit07 May 15, 2019
3ed9c54
Rollup merge of #59825 - jsgf:from-ref-string, r=sfackler
Centril May 15, 2019
c526a7c
Rollup merge of #59923 - czipperz:fix-convert-doc-links, r=steveklabnik
Centril May 15, 2019
9952052
Rollup merge of #60691 - topecongiro:await-macro-span, r=Centril
Centril May 15, 2019
04ac4bf
Rollup merge of #60763 - matklad:tt-parser, r=petrochenkov
Centril May 15, 2019
a82b43d
Rollup merge of #60769 - ehuss:rustc-cli-docs, r=steveklabnik
Centril May 15, 2019
7fc0f76
Rollup merge of #60811 - wesleywiser:bump_measureme, r=varkor
Centril May 15, 2019
e43aff7
Rollup merge of #60816 - scottmcm:vcpp-download-link, r=alexcrichton
Centril May 15, 2019
e40f14a
Rollup merge of #60827 - oli-obk:late_symbol, r=nnethercote
Centril May 15, 2019
9ad3d8f
Rollup merge of #60851 - Pulkit07:issue60849, r=Centril
Centril May 15, 2019
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
40 changes: 20 additions & 20 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pub const fn identity<T>(x: T) -> T { x }
/// If you need to do a costly conversion it is better to implement [`From`] with type
/// `&T` or write a custom function.
///
///
/// `AsRef` has the same signature as [`Borrow`], but `Borrow` is different in few aspects:
///
/// - Unlike `AsRef`, `Borrow` has a blanket impl for any `T`, and can be used to accept either
Expand Down Expand Up @@ -133,7 +132,7 @@ pub const fn identity<T>(x: T) -> T { x }
/// converted a the specified type `T`.
///
/// For example: By creating a generic function that takes an `AsRef<str>` we express that we
/// want to accept all references that can be converted to &str as an argument.
/// want to accept all references that can be converted to `&str` as an argument.
/// Since both [`String`] and `&str` implement `AsRef<str>` we can accept both as input argument.
///
/// [`String`]: ../../std/string/struct.String.html
Expand All @@ -149,7 +148,6 @@ pub const fn identity<T>(x: T) -> T { x }
/// let s = "hello".to_string();
/// is_hello(s);
/// ```
///
#[stable(feature = "rust1", since = "1.0.0")]
pub trait AsRef<T: ?Sized> {
/// Performs the conversion.
Expand Down Expand Up @@ -182,6 +180,7 @@ pub trait AsRef<T: ?Sized> {
/// write a function `add_one`that takes all arguments that can be converted to `&mut u64`.
/// Because [`Box<T>`] implements `AsMut<T>` `add_one` accepts arguments of type
/// `&mut Box<u64>` as well:
///
/// ```
/// fn add_one<T: AsMut<u64>>(num: &mut T) {
/// *num.as_mut() += 1;
Expand All @@ -191,8 +190,8 @@ pub trait AsRef<T: ?Sized> {
/// add_one(&mut boxed_num);
/// assert_eq!(*boxed_num, 1);
/// ```
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
///
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
#[stable(feature = "rust1", since = "1.0.0")]
pub trait AsMut<T: ?Sized> {
/// Performs the conversion.
Expand All @@ -203,18 +202,18 @@ pub trait AsMut<T: ?Sized> {
/// A value-to-value conversion that consumes the input value. The
/// opposite of [`From`].
///
/// One should only implement [`Into`] if a conversion to a type outside the current crate is
/// required. Otherwise one should always prefer implementing [`From`] over [`Into`] because
/// implementing [`From`] automatically provides one with a implementation of [`Into`] thanks to
/// One should only implement `Into` if a conversion to a type outside the current crate is
/// required. Otherwise one should always prefer implementing [`From`] over `Into` because
/// implementing [`From`] automatically provides one with a implementation of `Into` thanks to
/// the blanket implementation in the standard library. [`From`] cannot do these type of
/// conversions because of Rust's orphaning rules.
///
/// **Note: This trait must not fail**. If the conversion can fail, use [`TryInto`].
///
/// # Generic Implementations
///
/// - [`From<T>`]` for U` implies `Into<U> for T`
/// - [`Into`]` is reflexive, which means that `Into<T> for T` is implemented
/// - [`From`]`<T> for U` implies `Into<U> for T`
/// - `Into` is reflexive, which means that `Into<T> for T` is implemented
///
/// # Implementing `Into` for conversions to external types
///
Expand Down Expand Up @@ -273,7 +272,7 @@ pub trait AsMut<T: ?Sized> {
/// [`Option<T>`]: ../../std/option/enum.Option.html
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
/// [`String`]: ../../std/string/struct.String.html
/// [From]: trait.From.html
/// [`From`]: trait.From.html
/// [`into`]: trait.Into.html#tymethod.into
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Into<T>: Sized {
Expand All @@ -285,18 +284,18 @@ pub trait Into<T>: Sized {
/// Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
/// [`Into`].
///
/// One should always prefer implementing [`From`] over [`Into`]
/// because implementing [`From`] automatically provides one with a implementation of [`Into`]
/// One should always prefer implementing `From` over [`Into`]
/// because implementing `From` automatically provides one with a implementation of [`Into`]
/// thanks to the blanket implementation in the standard library.
///
/// Only implement [`Into`] if a conversion to a type outside the current crate is required.
/// [`From`] cannot do these type of conversions because of Rust's orphaning rules.
/// `From` cannot do these type of conversions because of Rust's orphaning rules.
/// See [`Into`] for more details.
///
/// Prefer using [`Into`] over using [`From`] when specifying trait bounds on a generic function.
/// Prefer using [`Into`] over using `From` when specifying trait bounds on a generic function.
/// This way, types that directly implement [`Into`] can be used as arguments as well.
///
/// The [`From`] is also very useful when performing error handling. When constructing a function
/// The `From` is also very useful when performing error handling. When constructing a function
/// that is capable of failing, the return type will generally be of the form `Result<T, E>`.
/// The `From` trait simplifies error handling by allowing a function to return a single error type
/// that encapsulate multiple error types. See the "Examples" section and [the book][book] for more
Expand All @@ -306,14 +305,15 @@ pub trait Into<T>: Sized {
///
/// # Generic Implementations
///
/// - [`From<T>`]` for U` implies [`Into<U>`]` for T`
/// - [`From`] is reflexive, which means that `From<T> for T` is implemented
/// - `From<T> for U` implies [`Into`]`<U> for T`
/// - `From` is reflexive, which means that `From<T> for T` is implemented
///
/// # Examples
///
/// [`String`] implements `From<&str>`:
///
/// An explicit conversion from a &str to a String is done as follows:
/// An explicit conversion from a `&str` to a String is done as follows:
///
/// ```
/// let string = "hello".to_string();
/// let other_string = String::from("hello");
Expand Down Expand Up @@ -361,7 +361,7 @@ pub trait Into<T>: Sized {
/// [`Option<T>`]: ../../std/option/enum.Option.html
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
/// [`String`]: ../../std/string/struct.String.html
/// [`Into<U>`]: trait.Into.html
/// [`Into`]: trait.Into.html
/// [`from`]: trait.From.html#tymethod.from
/// [book]: ../../book/ch09-00-error-handling.html
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -422,7 +422,7 @@ pub trait TryInto<T>: Sized {
///
/// # Generic Implementations
///
/// - `TryFrom<T> for U` implies [`TryInto<U>`]` for T`
/// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T`
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
/// is implemented and cannot fail -- the associated `Error` type for
/// calling `T::try_from()` on a value of type `T` is `Infallible`.
Expand Down