@@ -1684,14 +1684,6 @@ mod use_keyword {}
1684
1684
/// of `shorter`, thus the constraint is respected:
1685
1685
///
1686
1686
/// ```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
- ///
1695
1687
/// fn select_where<'a, 'b>(s1: &'a str, s2: &'b str, second: bool) -> &'a str
1696
1688
/// where
1697
1689
/// 'b: 'a,
@@ -1706,30 +1698,18 @@ mod use_keyword {}
1706
1698
/// let outer = String::from("Long living ref");
1707
1699
/// let longer = &outer;
1708
1700
/// {
1709
- /// let inner = String::from("Long living ref");
1701
+ /// let inner = String::from("Short living ref");
1710
1702
/// let shorter = &inner;
1711
1703
///
1712
- /// assert_eq!(select(shorter, longer, false), shorter);
1713
- /// assert_eq!(select(shorter, longer, true), longer);
1714
- ///
1715
1704
/// assert_eq!(select_where(shorter, longer, false), shorter);
1716
1705
/// assert_eq!(select_where(shorter, longer, true), longer);
1717
1706
/// }
1718
1707
/// ```
1719
1708
///
1720
1709
/// 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.
1723
1711
///
1724
1712
/// ```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
- /// #
1733
1713
/// # fn select_where<'a, 'b>(s1: &'a str, s2: &'b str, second: bool) -> &'a str
1734
1714
/// # where
1735
1715
/// # 'b: 'a,
@@ -1742,17 +1722,14 @@ mod use_keyword {}
1742
1722
/// # }
1743
1723
/// let outer = String::from("Long living ref");
1744
1724
/// let longer = &outer;
1745
- /// let res1;
1746
- /// let res2;
1725
+ /// let res;
1747
1726
/// {
1748
- /// let inner = String::from("Long living ref");
1727
+ /// let inner = String::from("Short living ref");
1749
1728
/// let shorter = &inner;
1750
1729
///
1751
- /// res1 = select(longer, shorter, false);
1752
- /// res2 = select_where(longer, shorter, false);
1730
+ /// res = select_where(longer, shorter, false);
1753
1731
/// }
1754
- /// assert_eq!(res1, &outer);
1755
- /// assert_eq!(res2, &outer);
1732
+ /// assert_eq!(res, &outer);
1756
1733
/// ```
1757
1734
///
1758
1735
/// `where` can also be used to express more complicated constraints that cannot
@@ -1771,12 +1748,11 @@ mod use_keyword {}
1771
1748
/// assert_eq!(first_or_default(Vec::<i32>::new().into_iter()), 0);
1772
1749
/// ```
1773
1750
///
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:
1775
1753
///
1776
1754
/// ```rust
1777
1755
/// # #![allow(dead_code)]
1778
- /// // The Cow type from the standard library uses where to impose constraints
1779
- /// // on its parameters.
1780
1756
/// pub enum Cow<'a, B>
1781
1757
/// where
1782
1758
/// B: 'a + ToOwned + ?Sized,
0 commit comments