@@ -1617,12 +1617,7 @@ mod traits {
1617
1617
1618
1618
#[ inline]
1619
1619
fn index ( & self , index : ops:: RangeTo < usize > ) -> & str {
1620
- // is_char_boundary checks that the index is in [0, .len()]
1621
- if self . is_char_boundary ( index. end ) {
1622
- unsafe { self . slice_unchecked ( 0 , index. end ) }
1623
- } else {
1624
- super :: slice_error_fail ( self , 0 , index. end )
1625
- }
1620
+ index. index ( self )
1626
1621
}
1627
1622
}
1628
1623
@@ -1636,12 +1631,7 @@ mod traits {
1636
1631
impl ops:: IndexMut < ops:: RangeTo < usize > > for str {
1637
1632
#[ inline]
1638
1633
fn index_mut ( & mut self , index : ops:: RangeTo < usize > ) -> & mut str {
1639
- // is_char_boundary checks that the index is in [0, .len()]
1640
- if self . is_char_boundary ( index. end ) {
1641
- unsafe { self . slice_mut_unchecked ( 0 , index. end ) }
1642
- } else {
1643
- super :: slice_error_fail ( self , 0 , index. end )
1644
- }
1634
+ index. index_mut ( self )
1645
1635
}
1646
1636
}
1647
1637
@@ -1657,12 +1647,7 @@ mod traits {
1657
1647
1658
1648
#[ inline]
1659
1649
fn index ( & self , index : ops:: RangeFrom < usize > ) -> & str {
1660
- // is_char_boundary checks that the index is in [0, .len()]
1661
- if self . is_char_boundary ( index. start ) {
1662
- unsafe { self . slice_unchecked ( index. start , self . len ( ) ) }
1663
- } else {
1664
- super :: slice_error_fail ( self , index. start , self . len ( ) )
1665
- }
1650
+ index. index ( self )
1666
1651
}
1667
1652
}
1668
1653
@@ -1676,13 +1661,7 @@ mod traits {
1676
1661
impl ops:: IndexMut < ops:: RangeFrom < usize > > for str {
1677
1662
#[ inline]
1678
1663
fn index_mut ( & mut self , index : ops:: RangeFrom < usize > ) -> & mut str {
1679
- // is_char_boundary checks that the index is in [0, .len()]
1680
- if self . is_char_boundary ( index. start ) {
1681
- let len = self . len ( ) ;
1682
- unsafe { self . slice_mut_unchecked ( index. start , len) }
1683
- } else {
1684
- super :: slice_error_fail ( self , index. start , self . len ( ) )
1685
- }
1664
+ index. index_mut ( self )
1686
1665
}
1687
1666
}
1688
1667
@@ -1724,9 +1703,7 @@ mod traits {
1724
1703
1725
1704
#[ inline]
1726
1705
fn index ( & self , index : ops:: RangeInclusive < usize > ) -> & str {
1727
- assert ! ( index. end != usize :: max_value( ) ,
1728
- "attempted to index str up to maximum usize" ) ;
1729
- self . index ( index. start .. index. end +1 )
1706
+ index. index ( self )
1730
1707
}
1731
1708
}
1732
1709
@@ -1738,9 +1715,7 @@ mod traits {
1738
1715
1739
1716
#[ inline]
1740
1717
fn index ( & self , index : ops:: RangeToInclusive < usize > ) -> & str {
1741
- assert ! ( index. end != usize :: max_value( ) ,
1742
- "attempted to index str up to maximum usize" ) ;
1743
- self . index ( .. index. end +1 )
1718
+ index. index ( self )
1744
1719
}
1745
1720
}
1746
1721
@@ -1750,9 +1725,7 @@ mod traits {
1750
1725
impl ops:: IndexMut < ops:: RangeInclusive < usize > > for str {
1751
1726
#[ inline]
1752
1727
fn index_mut ( & mut self , index : ops:: RangeInclusive < usize > ) -> & mut str {
1753
- assert ! ( index. end != usize :: max_value( ) ,
1754
- "attempted to index str up to maximum usize" ) ;
1755
- self . index_mut ( index. start .. index. end +1 )
1728
+ index. index_mut ( self )
1756
1729
}
1757
1730
}
1758
1731
#[ unstable( feature = "inclusive_range" ,
@@ -1761,9 +1734,7 @@ mod traits {
1761
1734
impl ops:: IndexMut < ops:: RangeToInclusive < usize > > for str {
1762
1735
#[ inline]
1763
1736
fn index_mut ( & mut self , index : ops:: RangeToInclusive < usize > ) -> & mut str {
1764
- assert ! ( index. end != usize :: max_value( ) ,
1765
- "attempted to index str up to maximum usize" ) ;
1766
- self . index_mut ( .. index. end +1 )
1737
+ index. index_mut ( self )
1767
1738
}
1768
1739
}
1769
1740
@@ -1886,6 +1857,7 @@ mod traits {
1886
1857
}
1887
1858
#[ inline]
1888
1859
fn index_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1860
+ // is_char_boundary checks that the index is in [0, .len()]
1889
1861
if slice. is_char_boundary ( self . end ) {
1890
1862
unsafe { self . get_unchecked_mut ( slice) }
1891
1863
} else {
@@ -1932,6 +1904,7 @@ mod traits {
1932
1904
}
1933
1905
#[ inline]
1934
1906
fn index_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1907
+ // is_char_boundary checks that the index is in [0, .len()]
1935
1908
if slice. is_char_boundary ( self . start ) {
1936
1909
unsafe { self . get_unchecked_mut ( slice) }
1937
1910
} else {
@@ -1961,10 +1934,14 @@ mod traits {
1961
1934
}
1962
1935
#[ inline]
1963
1936
fn index ( self , slice : & str ) -> & Self :: Output {
1937
+ assert ! ( self . end != usize :: max_value( ) ,
1938
+ "attempted to index str up to maximum usize" ) ;
1964
1939
( self . start ..self . end +1 ) . index ( slice)
1965
1940
}
1966
1941
#[ inline]
1967
1942
fn index_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1943
+ assert ! ( self . end != usize :: max_value( ) ,
1944
+ "attempted to index str up to maximum usize" ) ;
1968
1945
( self . start ..self . end +1 ) . index_mut ( slice)
1969
1946
}
1970
1947
}
@@ -2002,11 +1979,15 @@ mod traits {
2002
1979
}
2003
1980
#[ inline]
2004
1981
fn index ( self , slice : & str ) -> & Self :: Output {
1982
+ assert ! ( self . end != usize :: max_value( ) ,
1983
+ "attempted to index str up to maximum usize" ) ;
2005
1984
let end = self . end + 1 ;
2006
1985
self . get ( slice) . unwrap_or_else ( || super :: slice_error_fail ( slice, 0 , end) )
2007
1986
}
2008
1987
#[ inline]
2009
1988
fn index_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1989
+ assert ! ( self . end != usize :: max_value( ) ,
1990
+ "attempted to index str up to maximum usize" ) ;
2010
1991
if slice. is_char_boundary ( self . end ) {
2011
1992
unsafe { self . get_unchecked_mut ( slice) }
2012
1993
} else {
0 commit comments