Skip to content

Commit f8335fb

Browse files
committed
Fix nit and add link for Cow
1 parent 837a761 commit f8335fb

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

src/libstd/keyword_docs.rs

+8-32
Original file line numberDiff line numberDiff line change
@@ -1684,14 +1684,6 @@ mod use_keyword {}
16841684
/// of `shorter`, thus the constraint is respected:
16851685
///
16861686
/// ```rust
1687-
/// fn select<'a, 'b: 'a>(s1: &'a str, s2: &'b str, second: bool) -> &'a str {
1688-
/// if second {
1689-
/// s2
1690-
/// } else {
1691-
/// s1
1692-
/// }
1693-
/// }
1694-
///
16951687
/// fn select_where<'a, 'b>(s1: &'a str, s2: &'b str, second: bool) -> &'a str
16961688
/// where
16971689
/// 'b: 'a,
@@ -1706,30 +1698,18 @@ mod use_keyword {}
17061698
/// let outer = String::from("Long living ref");
17071699
/// let longer = &outer;
17081700
/// {
1709-
/// let inner = String::from("Long living ref");
1701+
/// let inner = String::from("Short living ref");
17101702
/// let shorter = &inner;
17111703
///
1712-
/// assert_eq!(select(shorter, longer, false), shorter);
1713-
/// assert_eq!(select(shorter, longer, true), longer);
1714-
///
17151704
/// assert_eq!(select_where(shorter, longer, false), shorter);
17161705
/// assert_eq!(select_where(shorter, longer, true), longer);
17171706
/// }
17181707
/// ```
17191708
///
17201709
/// On the other hand, this will not compile: `shorter` does not have a lifetime
1721-
/// that respects the constraint imposed by the `select` and `select_where`
1722-
/// functions.
1710+
/// that respects the constraint imposed by the `select_where` functions.
17231711
///
17241712
/// ```rust,compile_fail,E0597
1725-
/// # fn select<'a, 'b: 'a>(s1: &'a str, s2: &'b str, second: bool) -> &'a str {
1726-
/// # if second {
1727-
/// # s2
1728-
/// # } else {
1729-
/// # s1
1730-
/// # }
1731-
/// # }
1732-
/// #
17331713
/// # fn select_where<'a, 'b>(s1: &'a str, s2: &'b str, second: bool) -> &'a str
17341714
/// # where
17351715
/// # 'b: 'a,
@@ -1742,17 +1722,14 @@ mod use_keyword {}
17421722
/// # }
17431723
/// let outer = String::from("Long living ref");
17441724
/// let longer = &outer;
1745-
/// let res1;
1746-
/// let res2;
1725+
/// let res;
17471726
/// {
1748-
/// let inner = String::from("Long living ref");
1727+
/// let inner = String::from("Short living ref");
17491728
/// let shorter = &inner;
17501729
///
1751-
/// res1 = select(longer, shorter, false);
1752-
/// res2 = select_where(longer, shorter, false);
1730+
/// res = select_where(longer, shorter, false);
17531731
/// }
1754-
/// assert_eq!(res1, &outer);
1755-
/// assert_eq!(res2, &outer);
1732+
/// assert_eq!(res, &outer);
17561733
/// ```
17571734
///
17581735
/// `where` can also be used to express more complicated constraints that cannot
@@ -1771,12 +1748,11 @@ mod use_keyword {}
17711748
/// assert_eq!(first_or_default(Vec::<i32>::new().into_iter()), 0);
17721749
/// ```
17731750
///
1774-
/// `where` is available anywhere generic and lifetime parameters are available:
1751+
/// `where` is available anywhere generic and lifetime parameters are available,
1752+
/// as can be seen in the [`Cow`](crate::borrow::Cow) from the standard library:
17751753
///
17761754
/// ```rust
17771755
/// # #![allow(dead_code)]
1778-
/// // The Cow type from the standard library uses where to impose constraints
1779-
/// // on its parameters.
17801756
/// pub enum Cow<'a, B>
17811757
/// where
17821758
/// B: 'a + ToOwned + ?Sized,

0 commit comments

Comments
 (0)