Skip to content

Commit a28b246

Browse files
usize index message for vec
1 parent b2f67c8 commit a28b246

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
#![feature(unique)]
122122
#![feature(unsize)]
123123
#![feature(allocator_internals)]
124+
#![feature(on_unimplemented)]
124125

125126
#![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))]
126127
#![cfg_attr(test, feature(test, box_heap))]

src/liballoc/vec.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,7 @@ impl<T: Hash> Hash for Vec<T> {
15431543
}
15441544

15451545
#[stable(feature = "rust1", since = "1.0.0")]
1546+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
15461547
impl<T> Index<usize> for Vec<T> {
15471548
type Output = T;
15481549

@@ -1554,6 +1555,7 @@ impl<T> Index<usize> for Vec<T> {
15541555
}
15551556

15561557
#[stable(feature = "rust1", since = "1.0.0")]
1558+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
15571559
impl<T> IndexMut<usize> for Vec<T> {
15581560
#[inline]
15591561
fn index_mut(&mut self, index: usize) -> &mut T {
@@ -1562,8 +1564,8 @@ impl<T> IndexMut<usize> for Vec<T> {
15621564
}
15631565
}
15641566

1565-
15661567
#[stable(feature = "rust1", since = "1.0.0")]
1568+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
15671569
impl<T> ops::Index<ops::Range<usize>> for Vec<T> {
15681570
type Output = [T];
15691571

@@ -1572,7 +1574,9 @@ impl<T> ops::Index<ops::Range<usize>> for Vec<T> {
15721574
Index::index(&**self, index)
15731575
}
15741576
}
1577+
15751578
#[stable(feature = "rust1", since = "1.0.0")]
1579+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
15761580
impl<T> ops::Index<ops::RangeTo<usize>> for Vec<T> {
15771581
type Output = [T];
15781582

@@ -1581,7 +1585,9 @@ impl<T> ops::Index<ops::RangeTo<usize>> for Vec<T> {
15811585
Index::index(&**self, index)
15821586
}
15831587
}
1588+
15841589
#[stable(feature = "rust1", since = "1.0.0")]
1590+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
15851591
impl<T> ops::Index<ops::RangeFrom<usize>> for Vec<T> {
15861592
type Output = [T];
15871593

@@ -1590,7 +1596,9 @@ impl<T> ops::Index<ops::RangeFrom<usize>> for Vec<T> {
15901596
Index::index(&**self, index)
15911597
}
15921598
}
1599+
15931600
#[stable(feature = "rust1", since = "1.0.0")]
1601+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
15941602
impl<T> ops::Index<ops::RangeFull> for Vec<T> {
15951603
type Output = [T];
15961604

@@ -1599,7 +1607,9 @@ impl<T> ops::Index<ops::RangeFull> for Vec<T> {
15991607
self
16001608
}
16011609
}
1610+
16021611
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
1612+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16031613
impl<T> ops::Index<ops::RangeInclusive<usize>> for Vec<T> {
16041614
type Output = [T];
16051615

@@ -1608,7 +1618,9 @@ impl<T> ops::Index<ops::RangeInclusive<usize>> for Vec<T> {
16081618
Index::index(&**self, index)
16091619
}
16101620
}
1621+
16111622
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
1623+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16121624
impl<T> ops::Index<ops::RangeToInclusive<usize>> for Vec<T> {
16131625
type Output = [T];
16141626

@@ -1619,41 +1631,52 @@ impl<T> ops::Index<ops::RangeToInclusive<usize>> for Vec<T> {
16191631
}
16201632

16211633
#[stable(feature = "rust1", since = "1.0.0")]
1634+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16221635
impl<T> ops::IndexMut<ops::Range<usize>> for Vec<T> {
16231636
#[inline]
16241637
fn index_mut(&mut self, index: ops::Range<usize>) -> &mut [T] {
16251638
IndexMut::index_mut(&mut **self, index)
16261639
}
16271640
}
1641+
16281642
#[stable(feature = "rust1", since = "1.0.0")]
1643+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16291644
impl<T> ops::IndexMut<ops::RangeTo<usize>> for Vec<T> {
16301645
#[inline]
16311646
fn index_mut(&mut self, index: ops::RangeTo<usize>) -> &mut [T] {
16321647
IndexMut::index_mut(&mut **self, index)
16331648
}
16341649
}
1650+
16351651
#[stable(feature = "rust1", since = "1.0.0")]
1652+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16361653
impl<T> ops::IndexMut<ops::RangeFrom<usize>> for Vec<T> {
16371654
#[inline]
16381655
fn index_mut(&mut self, index: ops::RangeFrom<usize>) -> &mut [T] {
16391656
IndexMut::index_mut(&mut **self, index)
16401657
}
16411658
}
1659+
16421660
#[stable(feature = "rust1", since = "1.0.0")]
1661+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16431662
impl<T> ops::IndexMut<ops::RangeFull> for Vec<T> {
16441663
#[inline]
16451664
fn index_mut(&mut self, _index: ops::RangeFull) -> &mut [T] {
16461665
self
16471666
}
16481667
}
1668+
16491669
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
1670+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16501671
impl<T> ops::IndexMut<ops::RangeInclusive<usize>> for Vec<T> {
16511672
#[inline]
16521673
fn index_mut(&mut self, index: ops::RangeInclusive<usize>) -> &mut [T] {
16531674
IndexMut::index_mut(&mut **self, index)
16541675
}
16551676
}
1677+
16561678
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
1679+
#[rustc_on_unimplemented = "vector indices are of type `usize` or ranges of `usize`"]
16571680
impl<T> ops::IndexMut<ops::RangeToInclusive<usize>> for Vec<T> {
16581681
#[inline]
16591682
fn index_mut(&mut self, index: ops::RangeToInclusive<usize>) -> &mut [T] {

src/test/compile-fail/index-help.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = vec![1];
13+
x[0i32]; //~ ERROR E0277
14+
//~| NOTE vector indices are of type `usize` or ranges of `usize`
15+
}

0 commit comments

Comments
 (0)