From 86fd9a552d25f6e174512581ca75f38f84462811 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 18 Aug 2017 16:32:38 +0200 Subject: [PATCH 1/3] Add missing url for fmt module --- src/liballoc/fmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/fmt.rs b/src/liballoc/fmt.rs index 480fb4b9eaa2b..578d90c5ba9bb 100644 --- a/src/liballoc/fmt.rs +++ b/src/liballoc/fmt.rs @@ -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 From a5a1739945581f776fd494cc5074cceaec32aeda Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 18 Aug 2017 16:41:54 +0200 Subject: [PATCH 2/3] Add missing urls for Result struct --- src/libcore/result.rs | 100 ++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 27 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 20cfb02afcc77..ea064ca5c39fe 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -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 Result { // 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 Result { } } - /// 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 Result { ///////////////////////////////////////////////////////////////////////// /// Maps a `Result` to `Result` 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 Result { } /// Maps a `Result` to `Result` 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 Result { // 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 Result { } } - /// 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 Result { } } - /// 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 Result { } } - /// 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 Result { } } - /// 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 Result { } } - /// 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 Result { } impl Result { - /// 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 Result { } } - /// 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 Result { } impl Result { - /// 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 Result { } } - /// 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,8 +864,8 @@ impl Result { impl Result { /// 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 @@ -829,7 +873,7 @@ impl Result { /// 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 Result { /// /// [`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 { From b88773f58822c592155c531200ed0b20ef11e9f1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 18 Aug 2017 17:17:46 +0200 Subject: [PATCH 3/3] Add missing links for String module and type --- src/liballoc/string.rs | 73 ++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 76ee0158a6233..96bd6273c9484 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -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`]: ../../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`]: ../../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) -> Result { @@ -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::>().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`. + /// 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: