diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 515f49d6f0b..e825acad471 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -174,7 +174,7 @@ impl Option { // Querying the contained values ///////////////////////////////////////////////////////////////////////// - /// Returns `true` if the option is a `Some` value. + /// Returns `true` if the option is a [`Some`] value. /// /// # Examples /// @@ -185,6 +185,8 @@ impl Option { /// let x: Option = None; /// assert_eq!(x.is_some(), false); /// ``` + /// + /// [`Some`]: #variant.Some #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_some(&self) -> bool { @@ -194,7 +196,7 @@ impl Option { } } - /// Returns `true` if the option is a `None` value. + /// Returns `true` if the option is a [`None`] value. /// /// # Examples /// @@ -205,6 +207,8 @@ impl Option { /// let x: Option = None; /// assert_eq!(x.is_none(), true); /// ``` + /// + /// [`None`]: #variant.None #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_none(&self) -> bool { @@ -269,13 +273,14 @@ impl Option { // Getting to contained values ///////////////////////////////////////////////////////////////////////// - /// Unwraps an option, yielding the content of a `Some`. + /// Unwraps an option, yielding the content of a [`Some`]. /// /// # Panics /// /// Panics if the value is a [`None`] with a custom panic message provided by /// `msg`. /// + /// [`Some`]: #variant.Some /// [`None`]: #variant.None /// /// # Examples @@ -298,16 +303,17 @@ impl Option { } } - /// Moves the value `v` out of the `Option` if it is `Some(v)`. + /// Moves the value `v` out of the `Option` if it is [`Some(v)`]. /// /// In general, because this function may panic, its use is discouraged. - /// Instead, prefer to use pattern matching and handle the `None` + /// Instead, prefer to use pattern matching and handle the [`None`] /// case explicitly. /// /// # Panics /// /// Panics if the self value equals [`None`]. /// + /// [`Some(v)`]: #variant.Some /// [`None`]: #variant.None /// /// # Examples @@ -395,7 +401,9 @@ impl Option { } /// Applies a function to the contained value (if any), - /// or returns a `default` (if not). + /// or returns a [`default`][] (if not). + /// + /// [`default`]: ../default/trait.Default.html#tymethod.default /// /// # Examples /// @@ -416,7 +424,9 @@ impl Option { } /// Applies a function to the contained value (if any), - /// or computes a `default` (if not). + /// or computes a [`default`][] (if not). + /// + /// [`default`]: ../default/trait.Default.html#tymethod.default /// /// # Examples /// @@ -438,12 +448,14 @@ impl Option { } } - /// Transforms the `Option` into a [`Result`], mapping `Some(v)` to - /// [`Ok(v)`] and `None` to [`Err(err)`][Err]. + /// Transforms the `Option` into a [`Result`], mapping [`Some(v)`] to + /// [`Ok(v)`] and [`None`] to [`Err(err)`]. /// /// [`Result`]: ../../std/result/enum.Result.html /// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok - /// [Err]: ../../std/result/enum.Result.html#variant.Err + /// [`Err(err)`]: ../../std/result/enum.Result.html#variant.Err + /// [`None`]: #variant.None + /// [`Some(v)`]: #variant.Some /// /// # Examples /// @@ -463,12 +475,14 @@ impl Option { } } - /// Transforms the `Option` into a [`Result`], mapping `Some(v)` to - /// [`Ok(v)`] and `None` to [`Err(err())`][Err]. + /// Transforms the `Option` into a [`Result`], mapping [`Some(v)`] to + /// [`Ok(v)`] and [`None`] to [`Err(err())`]. /// /// [`Result`]: ../../std/result/enum.Result.html /// [`Ok(v)`]: ../../std/result/enum.Result.html#variant.Ok - /// [Err]: ../../std/result/enum.Result.html#variant.Err + /// [`Err(err())`]: ../../std/result/enum.Result.html#variant.Err + /// [`None`]: #variant.None + /// [`Some(v)`]: #variant.Some /// /// # Examples /// @@ -534,7 +548,9 @@ impl Option { // Boolean operations on the values, eager and lazy ///////////////////////////////////////////////////////////////////////// - /// Returns `None` if the option is `None`, otherwise returns `optb`. + /// Returns [`None`] if the option is [`None`], otherwise returns `optb`. + /// + /// [`None`]: #variant.None /// /// # Examples /// @@ -564,11 +580,13 @@ impl Option { } } - /// Returns `None` if the option is `None`, otherwise calls `f` with the + /// Returns [`None`] if the option is [`None`], otherwise calls `f` with the /// wrapped value and returns the result. /// /// Some languages call this operation flatmap. /// + /// [`None`]: #variant.None + /// /// # Examples /// /// ``` @@ -645,9 +663,11 @@ impl Option { // Entry-like operations to insert if None and return a reference ///////////////////////////////////////////////////////////////////////// - /// Inserts `v` into the option if it is `None`, then + /// Inserts `v` into the option if it is [`None`], then /// returns a mutable reference to the contained value. /// + /// [`None`]: #variant.None + /// /// # Examples /// /// ``` @@ -678,9 +698,11 @@ impl Option { } } - /// Inserts a value computed from `f` into the option if it is `None`, then + /// Inserts a value computed from `f` into the option if it is [`None`], then /// returns a mutable reference to the contained value. /// + /// [`None`]: #variant.None + /// /// # Examples /// /// ``` @@ -715,7 +737,9 @@ impl Option { // Misc ///////////////////////////////////////////////////////////////////////// - /// Takes the value out of the option, leaving a `None` in its place. + /// Takes the value out of the option, leaving a [`None`] in its place. + /// + /// [`None`]: #variant.None /// /// # Examples /// @@ -757,16 +781,16 @@ impl<'a, T: Clone> Option<&'a T> { impl Option { /// Returns the contained value or a default /// - /// Consumes the `self` argument then, if `Some`, returns the contained - /// value, otherwise if `None`, returns the default value for that + /// Consumes the `self` argument then, if [`Some`], returns the contained + /// value, otherwise if [`None`], 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 - /// `None` on error. + /// into 0 (the default value for integers). [`parse`] converts + /// a string to any other type that implements [`FromStr`], returning + /// [`None`] on error. /// /// ``` /// let good_year_from_input = "1909"; @@ -777,6 +801,11 @@ impl Option { /// assert_eq!(1909, good_year); /// assert_eq!(0, bad_year); /// ``` + /// + /// [`Some`]: #variant.Some + /// [`None`]: #variant.None + /// [`parse`]: ../../std/primitive.str.html#method.parse + /// [`FromStr`]: ../../std/str/trait.FromStr.html #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn unwrap_or_default(self) -> T { @@ -801,7 +830,9 @@ fn expect_failed(msg: &str) -> ! { #[stable(feature = "rust1", since = "1.0.0")] impl Default for Option { - /// Returns None. + /// Returns [`None`]. + /// + /// [`None`]: #variant.None #[inline] fn default() -> Option { None } } @@ -1020,8 +1051,8 @@ unsafe impl TrustedLen for IntoIter {} #[stable(feature = "rust1", since = "1.0.0")] impl> FromIterator> for Option { - /// Takes each element in the `Iterator`: if it is `None`, no further - /// elements are taken, and the `None` is returned. Should no `None` occur, a + /// Takes each element in the [`Iterator`]: if it is [`None`], no further + /// elements are taken, and the [`None`] is returned. Should no [`None`] occur, a /// container with the values of each `Option` is returned. /// /// Here is an example which increments every integer in a vector, @@ -1037,6 +1068,9 @@ impl> FromIterator> for Option { /// ).collect(); /// assert!(res == Some(vec![2, 3])); /// ``` + /// + /// [`Iterator`]: ../iter/trait.Iterator.html + /// [`None`]: enum.Option.html#variant.None #[inline] fn from_iter>>(iter: I) -> Option { // FIXME(#11084): This could be replaced with Iterator::scan when this