@@ -1527,146 +1527,26 @@ impl<T: Hash> Hash for Vec<T> {
15271527
15281528#[ stable( feature = "rust1" , since = "1.0.0" ) ]
15291529#[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1530- impl < T > Index < usize > for Vec < T > {
1531- type Output = T ;
1530+ impl < T , I > Index < I > for Vec < T > where [ T ] : Index < I > {
1531+ type Output = < [ T ] as Index < I > > :: Output ;
15321532
15331533 #[ inline]
1534- fn index ( & self , index : usize ) -> & T {
1534+ fn index ( & self , index : I ) -> & Self :: Output {
15351535 // NB built-in indexing via `&[T]`
15361536 & ( * * self ) [ index]
15371537 }
15381538}
15391539
15401540#[ stable( feature = "rust1" , since = "1.0.0" ) ]
15411541#[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1542- impl < T > IndexMut < usize > for Vec < T > {
1542+ impl < T , I > IndexMut < I > for Vec < T > where [ T ] : IndexMut < I > {
15431543 #[ inline]
1544- fn index_mut ( & mut self , index : usize ) -> & mut T {
1544+ fn index_mut ( & mut self , index : I ) -> & mut Self :: Output {
15451545 // NB built-in indexing via `&mut [T]`
15461546 & mut ( * * self ) [ index]
15471547 }
15481548}
15491549
1550- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1551- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1552- impl < T > ops:: Index < ops:: Range < usize > > for Vec < T > {
1553- type Output = [ T ] ;
1554-
1555- #[ inline]
1556- fn index ( & self , index : ops:: Range < usize > ) -> & [ T ] {
1557- Index :: index ( & * * self , index)
1558- }
1559- }
1560-
1561- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1562- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1563- impl < T > ops:: Index < ops:: RangeTo < usize > > for Vec < T > {
1564- type Output = [ T ] ;
1565-
1566- #[ inline]
1567- fn index ( & self , index : ops:: RangeTo < usize > ) -> & [ T ] {
1568- Index :: index ( & * * self , index)
1569- }
1570- }
1571-
1572- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1573- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1574- impl < T > ops:: Index < ops:: RangeFrom < usize > > for Vec < T > {
1575- type Output = [ T ] ;
1576-
1577- #[ inline]
1578- fn index ( & self , index : ops:: RangeFrom < usize > ) -> & [ T ] {
1579- Index :: index ( & * * self , index)
1580- }
1581- }
1582-
1583- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1584- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1585- impl < T > ops:: Index < ops:: RangeFull > for Vec < T > {
1586- type Output = [ T ] ;
1587-
1588- #[ inline]
1589- fn index ( & self , _index : ops:: RangeFull ) -> & [ T ] {
1590- self
1591- }
1592- }
1593-
1594- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1595- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1596- impl < T > ops:: Index < ops:: RangeInclusive < usize > > for Vec < T > {
1597- type Output = [ T ] ;
1598-
1599- #[ inline]
1600- fn index ( & self , index : ops:: RangeInclusive < usize > ) -> & [ T ] {
1601- Index :: index ( & * * self , index)
1602- }
1603- }
1604-
1605- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1606- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1607- impl < T > ops:: Index < ops:: RangeToInclusive < usize > > for Vec < T > {
1608- type Output = [ T ] ;
1609-
1610- #[ inline]
1611- fn index ( & self , index : ops:: RangeToInclusive < usize > ) -> & [ T ] {
1612- Index :: index ( & * * self , index)
1613- }
1614- }
1615-
1616- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1617- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1618- impl < T > ops:: IndexMut < ops:: Range < usize > > for Vec < T > {
1619- #[ inline]
1620- fn index_mut ( & mut self , index : ops:: Range < usize > ) -> & mut [ T ] {
1621- IndexMut :: index_mut ( & mut * * self , index)
1622- }
1623- }
1624-
1625- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1626- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1627- impl < T > ops:: IndexMut < ops:: RangeTo < usize > > for Vec < T > {
1628- #[ inline]
1629- fn index_mut ( & mut self , index : ops:: RangeTo < usize > ) -> & mut [ T ] {
1630- IndexMut :: index_mut ( & mut * * self , index)
1631- }
1632- }
1633-
1634- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1635- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1636- impl < T > ops:: IndexMut < ops:: RangeFrom < usize > > for Vec < T > {
1637- #[ inline]
1638- fn index_mut ( & mut self , index : ops:: RangeFrom < usize > ) -> & mut [ T ] {
1639- IndexMut :: index_mut ( & mut * * self , index)
1640- }
1641- }
1642-
1643- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1644- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1645- impl < T > ops:: IndexMut < ops:: RangeFull > for Vec < T > {
1646- #[ inline]
1647- fn index_mut ( & mut self , _index : ops:: RangeFull ) -> & mut [ T ] {
1648- self
1649- }
1650- }
1651-
1652- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1653- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1654- impl < T > ops:: IndexMut < ops:: RangeInclusive < usize > > for Vec < T > {
1655- #[ inline]
1656- fn index_mut ( & mut self , index : ops:: RangeInclusive < usize > ) -> & mut [ T ] {
1657- IndexMut :: index_mut ( & mut * * self , index)
1658- }
1659- }
1660-
1661- #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
1662- #[ rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`" ]
1663- impl < T > ops:: IndexMut < ops:: RangeToInclusive < usize > > for Vec < T > {
1664- #[ inline]
1665- fn index_mut ( & mut self , index : ops:: RangeToInclusive < usize > ) -> & mut [ T ] {
1666- IndexMut :: index_mut ( & mut * * self , index)
1667- }
1668- }
1669-
16701550#[ stable( feature = "rust1" , since = "1.0.0" ) ]
16711551impl < T > ops:: Deref for Vec < T > {
16721552 type Target = [ T ] ;
0 commit comments