Skip to content

Rollup of 4 pull requests #43980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
@@ -211,7 +211,7 @@
//!
//! - [`fmt::Display`][`Display`] implementations assert that the type can be faithfully
//! represented as a UTF-8 string at all times. It is **not** expected that
//! all types implement the `Display` trait.
//! all types implement the [`Display`] trait.
//! - [`fmt::Debug`][`Debug`] implementations should be implemented for **all** public types.
//! Output will typically represent the internal state as faithfully as possible.
//! The purpose of the [`Debug`] trait is to facilitate debugging Rust code. In
73 changes: 41 additions & 32 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
//! let message = s + " world!";
//! ```
//!
//! If you have a vector of valid UTF-8 bytes, you can make a `String` out of
//! If you have a vector of valid UTF-8 bytes, you can make a [`String`] out of
//! it. You can do the reverse too.
//!
//! ```
@@ -155,17 +155,14 @@ use boxed::Box;
/// takes_str(&s);
/// ```
///
/// [`&str`]: ../../std/primitive.str.html
/// [`Deref`]: ../../std/ops/trait.Deref.html
///
/// This will create a [`&str`] from the `String` and pass it in. This
/// conversion is very inexpensive, and so generally, functions will accept
/// [`&str`]s as arguments unless they need a `String` for some specific
/// reason.
///
/// In certain cases Rust doesn't have enough information to make this
/// conversion, known as `Deref` coercion. In the following example a string
/// slice `&'a str` implements the trait `TraitExample`, and the function
/// conversion, known as [`Deref`] coercion. In the following example a string
/// slice [`&'a str`][`&str`] implements the trait `TraitExample`, and the function
/// `example_func` takes anything that implements the trait. In this case Rust
/// would need to make two implicit conversions, which Rust doesn't have the
/// means to do. For that reason, the following example will not compile.
@@ -185,13 +182,13 @@ use boxed::Box;
///
/// There are two options that would work instead. The first would be to
/// change the line `example_func(&example_string);` to
/// `example_func(example_string.as_str());`, using the method `as_str()`
/// `example_func(example_string.as_str());`, using the method [`as_str()`]
/// to explicitly extract the string slice containing the string. The second
/// way changes `example_func(&example_string);` to
/// `example_func(&*example_string);`. In this case we are dereferencing a
/// `String` to a `str`, then referencing the `str` back to `&str`. The
/// second way is more idiomatic, however both work to do the conversion
/// explicitly rather than relying on the implicit conversion.
/// `String` to a [`str`][`&str`], then referencing the [`str`][`&str`] back to
/// [`&str`]. The second way is more idiomatic, however both work to do the
/// conversion explicitly rather than relying on the implicit conversion.
///
/// # Representation
///
@@ -287,6 +284,10 @@ use boxed::Box;
/// ```
///
/// Here, there's no need to allocate more memory inside the loop.
///
/// [`&str`]: ../../std/primitive.str.html
/// [`Deref`]: ../../std/ops/trait.Deref.html
/// [`as_str()`]: struct.String.html#method.as_str
#[derive(PartialOrd, Eq, Ord)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct String {
@@ -443,32 +444,22 @@ impl String {
/// requires that it is valid UTF-8. `from_utf8()` checks to ensure that
/// the bytes are valid UTF-8, and then does the conversion.
///
/// [`&str`]: ../../std/primitive.str.html
/// [`u8`]: ../../std/primitive.u8.html
/// [`Vec<u8>`]: ../../std/vec/struct.Vec.html
///
/// If you are sure that the byte slice is valid UTF-8, and you don't want
/// to incur the overhead of the validity check, there is an unsafe version
/// of this function, [`from_utf8_unchecked`], which has the same behavior
/// but skips the check.
///
/// [`from_utf8_unchecked`]: struct.String.html#method.from_utf8_unchecked
///
/// This method will take care to not copy the vector, for efficiency's
/// sake.
///
/// If you need a `&str` instead of a `String`, consider
/// If you need a [`&str`] instead of a `String`, consider
/// [`str::from_utf8`].
///
/// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html
///
/// The inverse of this method is [`as_bytes`].
///
/// [`as_bytes`]: #method.as_bytes
///
/// # Errors
///
/// Returns `Err` if the slice is not UTF-8 with a description as to why the
/// Returns [`Err`] if the slice is not UTF-8 with a description as to why the
/// provided bytes are not UTF-8. The vector you moved in is also included.
///
/// # Examples
@@ -497,7 +488,14 @@ impl String {
/// See the docs for [`FromUtf8Error`] for more details on what you can do
/// with this error.
///
/// [`from_utf8_unchecked`]: struct.String.html#method.from_utf8_unchecked
/// [`&str`]: ../../std/primitive.str.html
/// [`u8`]: ../../std/primitive.u8.html
/// [`Vec<u8>`]: ../../std/vec/struct.Vec.html
/// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html
/// [`as_bytes`]: struct.String.html#method.as_bytes
/// [`FromUtf8Error`]: struct.FromUtf8Error.html
/// [`Err`]: ../../stdresult/enum.Result.html#variant.Err
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_utf8(vec: Vec<u8>) -> Result<String, FromUtf8Error> {
@@ -594,9 +592,11 @@ impl String {
Cow::Owned(res)
}

/// Decode a UTF-16 encoded vector `v` into a `String`, returning `Err`
/// Decode a UTF-16 encoded vector `v` into a `String`, returning [`Err`]
/// if `v` contains any invalid data.
///
/// [`Err`]: ../../std/result/enum.Result.htlm#variant.Err
///
/// # Examples
///
/// Basic usage:
@@ -618,7 +618,7 @@ impl String {
decode_utf16(v.iter().cloned()).collect::<Result<_, _>>().map_err(|_| FromUtf16Error(()))
}

/// Decode a UTF-16 encoded vector `v` into a string, replacing
/// Decode a UTF-16 encoded slice `v` into a `String`, replacing
/// invalid data with the replacement character (U+FFFD).
///
/// # Examples
@@ -800,11 +800,12 @@ impl String {
/// If you do not want this "at least" behavior, see the [`reserve_exact`]
/// method.
///
/// [`reserve_exact`]: #method.reserve_exact
///
/// # Panics
///
/// Panics if the new capacity overflows `usize`.
/// Panics if the new capacity overflows [`usize`].
///
/// [`reserve_exact`]: struct.String.html#method.reserve_exact
/// [`usize`]: ../../std/primitive.usize.html
///
/// # Examples
///
@@ -909,7 +910,9 @@ impl String {
self.vec.shrink_to_fit()
}

/// Appends the given `char` to the end of this `String`.
/// Appends the given [`char`] to the end of this `String`.
///
/// [`char`]: ../../std/primitive.char.html
///
/// # Examples
///
@@ -990,7 +993,9 @@ impl String {

/// Removes the last character from the string buffer and returns it.
///
/// Returns `None` if this `String` is empty.
/// Returns [`None`] if this `String` is empty.
///
/// [`None`]: ../../std/option/enum.Option.html#variant.None
///
/// # Examples
///
@@ -1019,7 +1024,7 @@ impl String {
Some(ch)
}

/// Removes a `char` from this `String` at a byte position and returns it.
/// Removes a [`char`] from this `String` at a byte position and returns it.
///
/// This is an `O(n)` operation, as it requires copying every element in the
/// buffer.
@@ -1389,7 +1394,7 @@ impl String {
/// replaces with the given string, and yields the removed chars.
/// The given string doesn’t need to be the same length as the range.
///
/// Note: The element range is removed when the `Splice` is dropped,
/// Note: The element range is removed when the [`Splice`] is dropped,
/// even if the iterator is not consumed until the end.
///
/// # Panics
@@ -1398,6 +1403,7 @@ impl String {
/// boundary, or if they're out of bounds.
///
/// [`char`]: ../../std/primitive.char.html
/// [`Splice`]: ../../std/string/struct.Splice.html
///
/// # Examples
///
@@ -1450,10 +1456,13 @@ impl String {
}
}

/// Converts this `String` into a `Box<str>`.
/// Converts this `String` into a [`Box`]`<`[`str`]`>`.
///
/// This will drop any excess capacity.
///
/// [`Box`]: ../../std/boxed/struct.Box.html
/// [`str`]: ../../std/primitive.str.html
///
/// # Examples
///
/// Basic usage:
100 changes: 73 additions & 27 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
@@ -244,9 +244,12 @@ use fmt;
use iter::{FromIterator, FusedIterator, TrustedLen};
use ops;

/// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
/// `Result` is a type that represents either success ([`Ok`]) or failure ([`Err`]).
///
/// See the [`std::result`](index.html) module documentation for details.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
@@ -269,7 +272,9 @@ impl<T, E> Result<T, E> {
// Querying the contained values
/////////////////////////////////////////////////////////////////////////

/// Returns `true` if the result is `Ok`.
/// Returns `true` if the result is [`Ok`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
///
/// # Examples
///
@@ -291,7 +296,9 @@ impl<T, E> Result<T, E> {
}
}

/// Returns `true` if the result is `Err`.
/// Returns `true` if the result is [`Err`].
///
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -433,10 +440,13 @@ impl<T, E> Result<T, E> {
/////////////////////////////////////////////////////////////////////////

/// Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a
/// contained `Ok` value, leaving an `Err` value untouched.
/// contained [`Ok`] value, leaving an [`Err`] value untouched.
///
/// This function can be used to compose the results of two functions.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Print the numbers on each line of a string multiplied by two.
@@ -461,11 +471,14 @@ impl<T, E> Result<T, E> {
}

/// Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a
/// contained `Err` value, leaving an `Ok` value untouched.
/// contained [`Err`] value, leaving an [`Ok`] value untouched.
///
/// This function can be used to pass through a successful result while handling
/// an error.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
@@ -546,7 +559,10 @@ impl<T, E> Result<T, E> {
// Boolean operations on the values, eager and lazy
/////////////////////////////////////////////////////////////////////////

/// Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`.
/// Returns `res` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -578,7 +594,10 @@ impl<T, E> Result<T, E> {
}
}

/// Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`.
/// Calls `op` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// This function can be used for control flow based on `Result` values.
///
@@ -604,7 +623,10 @@ impl<T, E> Result<T, E> {
}
}

/// Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`.
/// Returns `res` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -636,10 +658,13 @@ impl<T, E> Result<T, E> {
}
}

/// Calls `op` if the result is `Err`, otherwise returns the `Ok` value of `self`.
/// Calls `op` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`.
///
/// This function can be used for control flow based on result values.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
@@ -662,9 +687,12 @@ impl<T, E> Result<T, E> {
}
}

/// Unwraps a result, yielding the content of an `Ok`.
/// Unwraps a result, yielding the content of an [`Ok`].
/// Else, it returns `optb`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
@@ -686,8 +714,11 @@ impl<T, E> Result<T, E> {
}
}

/// Unwraps a result, yielding the content of an `Ok`.
/// If the value is an `Err` then it calls `op` with its value.
/// Unwraps a result, yielding the content of an [`Ok`].
/// If the value is an [`Err`] then it calls `op` with its value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -710,12 +741,15 @@ impl<T, E> Result<T, E> {
}

impl<T, E: fmt::Debug> Result<T, E> {
/// Unwraps a result, yielding the content of an `Ok`.
/// Unwraps a result, yielding the content of an [`Ok`].
///
/// # Panics
///
/// Panics if the value is an `Err`, with a panic message provided by the
/// `Err`'s value.
/// Panics if the value is an [`Err`], with a panic message provided by the
/// [`Err`]'s value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -739,12 +773,15 @@ impl<T, E: fmt::Debug> Result<T, E> {
}
}

/// Unwraps a result, yielding the content of an `Ok`.
/// Unwraps a result, yielding the content of an [`Ok`].
///
/// # Panics
///
/// Panics if the value is an `Err`, with a panic message including the
/// passed message, and the content of the `Err`.
/// Panics if the value is an [`Err`], with a panic message including the
/// passed message, and the content of the [`Err`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -765,12 +802,16 @@ impl<T, E: fmt::Debug> Result<T, E> {
}

impl<T: fmt::Debug, E> Result<T, E> {
/// Unwraps a result, yielding the content of an `Err`.
/// Unwraps a result, yielding the content of an [`Err`].
///
/// # Panics
///
/// Panics if the value is an `Ok`, with a custom panic message provided
/// by the `Ok`'s value.
/// Panics if the value is an [`Ok`], with a custom panic message provided
/// by the [`Ok`]'s value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
///
/// # Examples
///
@@ -792,12 +833,15 @@ impl<T: fmt::Debug, E> Result<T, E> {
}
}

/// Unwraps a result, yielding the content of an `Err`.
/// Unwraps a result, yielding the content of an [`Err`].
///
/// # Panics
///
/// Panics if the value is an `Ok`, with a panic message including the
/// passed message, and the content of the `Ok`.
/// Panics if the value is an [`Ok`], with a panic message including the
/// passed message, and the content of the [`Ok`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
@@ -820,16 +864,16 @@ impl<T: fmt::Debug, E> Result<T, E> {
impl<T: Default, E> Result<T, E> {
/// Returns the contained value or a default
///
/// Consumes the `self` argument then, if `Ok`, returns the contained
/// value, otherwise if `Err`, returns the default value for that
/// Consumes the `self` argument then, if [`Ok`], returns the contained
/// value, otherwise if [`Err`], returns the default value for that
/// type.
///
/// # Examples
///
/// Convert a string to an integer, turning poorly-formed strings
/// into 0 (the default value for integers). [`parse`] converts
/// a string to any other type that implements [`FromStr`], returning an
/// `Err` on error.
/// [`Err`] on error.
///
/// ```
/// let good_year_from_input = "1909";
@@ -843,6 +887,8 @@ impl<T: Default, E> Result<T, E> {
///
/// [`parse`]: ../../std/primitive.str.html#method.parse
/// [`FromStr`]: ../../std/str/trait.FromStr.html
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
#[inline]
#[stable(feature = "result_unwrap_or_default", since = "1.16.0")]
pub fn unwrap_or_default(self) -> T {
8 changes: 4 additions & 4 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
@@ -121,10 +121,10 @@ pub enum FindLintError {

pub enum CheckLintNameResult<'a> {
Ok(&'a [LintId]),
// Lint doesn't exist
/// Lint doesn't exist
NoLint,
// The lint is either renamed or removed. This is the warning
// message.
/// The lint is either renamed or removed. This is the warning
/// message.
Warning(String),
}

@@ -253,7 +253,7 @@ impl LintStore {
}
}

// Checks the validity of lint names derived from the command line
/// Checks the validity of lint names derived from the command line
pub fn check_lint_name_cmdline(&self,
sess: &Session,
lint_name: &str,
31 changes: 18 additions & 13 deletions src/libstd/primitive_docs.rs
Original file line number Diff line number Diff line change
@@ -103,26 +103,31 @@ mod prim_bool { }
/// [`String`]: string/struct.String.html
///
/// As always, remember that a human intuition for 'character' may not map to
/// Unicode's definitions. For example, emoji symbols such as '❤️' can be more
/// than one Unicode code point; this ❤️ in particular is two:
/// Unicode's definitions. For example, despite looking similar, the 'é'
/// character is one Unicode code point while 'é' is two Unicode code points:
///
/// ```
/// let s = String::from("❤️");
/// let mut chars = "é".chars();
/// // U+00e9: 'latin small letter e with acute'
/// assert_eq!(Some('\u{00e9}'), chars.next());
/// assert_eq!(None, chars.next());
///
/// // we get two chars out of a single ❤️
/// let mut iter = s.chars();
/// assert_eq!(Some('\u{2764}'), iter.next());
/// assert_eq!(Some('\u{fe0f}'), iter.next());
/// assert_eq!(None, iter.next());
/// let mut chars = "é".chars();
/// // U+0065: 'latin small letter e'
/// assert_eq!(Some('\u{0065}'), chars.next());
/// // U+0301: 'combining acute accent'
/// assert_eq!(Some('\u{0301}'), chars.next());
/// assert_eq!(None, chars.next());
/// ```
///
/// This means it won't fit into a `char`. Trying to create a literal with
/// `let heart = '❤️';` gives an error:
/// This means that the contents of the first string above _will_ fit into a
/// `char` while the contents of the second string _will not_. Trying to create
/// a `char` literal with the contents of the second string gives an error:
///
/// ```text
/// error: character literal may only contain one codepoint: '
/// let heart = '❤️';
/// ^~
/// error: character literal may only contain one codepoint: 'é'
/// let c = '';
/// ^^^^
/// ```
///
/// Another implication of the 4-byte fixed size of a `char` is that
1 change: 1 addition & 0 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ static TARGETS: &'static [&'static str] = &[
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"x86_64-unknown-netbsd",
"x86_64-unknown-redox",
];

static MINGW: &'static [&'static str] = &[