Skip to content

Commit 763fdf2

Browse files
committed
moved renamed docs formatted stderr | integral-indexing.rs
1 parent 5c89099 commit 763fdf2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

tests/ui/integral-indexing.rs renamed to tests/ui/indexing/indexing-integral-types.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
//! Test that only usize can be used for indexing arrays and slices.
2+
13
pub fn main() {
24
let v: Vec<isize> = vec![0, 1, 2, 3, 4, 5];
35
let s: String = "abcdef".to_string();
6+
7+
// Valid indexing with usize
48
v[3_usize];
5-
v[3];
9+
v[3]; // inferred as usize
10+
11+
// Invalid indexing with other integral types
612
v[3u8]; //~ERROR : the type `[isize]` cannot be indexed by `u8`
713
v[3i8]; //~ERROR : the type `[isize]` cannot be indexed by `i8`
814
v[3u32]; //~ERROR : the type `[isize]` cannot be indexed by `u32`
915
v[3i32]; //~ERROR : the type `[isize]` cannot be indexed by `i32`
16+
17+
// Same rules apply to byte slices
1018
s.as_bytes()[3_usize];
11-
s.as_bytes()[3];
19+
s.as_bytes()[3]; // inferred as usize
20+
1221
s.as_bytes()[3u8]; //~ERROR : the type `[u8]` cannot be indexed by `u8`
1322
s.as_bytes()[3i8]; //~ERROR : the type `[u8]` cannot be indexed by `i8`
1423
s.as_bytes()[3u32]; //~ERROR : the type `[u8]` cannot be indexed by `u32`

tests/ui/integral-indexing.stderr renamed to tests/ui/indexing/indexing-integral-types.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the type `[isize]` cannot be indexed by `u8`
2-
--> $DIR/integral-indexing.rs:6:7
2+
--> $DIR/indexing-integral-types.rs:12:7
33
|
44
LL | v[3u8];
55
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -11,7 +11,7 @@ LL | v[3u8];
1111
= note: required for `Vec<isize>` to implement `Index<u8>`
1212

1313
error[E0277]: the type `[isize]` cannot be indexed by `i8`
14-
--> $DIR/integral-indexing.rs:7:7
14+
--> $DIR/indexing-integral-types.rs:13:7
1515
|
1616
LL | v[3i8];
1717
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -23,7 +23,7 @@ LL | v[3i8];
2323
= note: required for `Vec<isize>` to implement `Index<i8>`
2424

2525
error[E0277]: the type `[isize]` cannot be indexed by `u32`
26-
--> $DIR/integral-indexing.rs:8:7
26+
--> $DIR/indexing-integral-types.rs:14:7
2727
|
2828
LL | v[3u32];
2929
| ^^^^ slice indices are of type `usize` or ranges of `usize`
@@ -35,7 +35,7 @@ LL | v[3u32];
3535
= note: required for `Vec<isize>` to implement `Index<u32>`
3636

3737
error[E0277]: the type `[isize]` cannot be indexed by `i32`
38-
--> $DIR/integral-indexing.rs:9:7
38+
--> $DIR/indexing-integral-types.rs:15:7
3939
|
4040
LL | v[3i32];
4141
| ^^^^ slice indices are of type `usize` or ranges of `usize`
@@ -47,7 +47,7 @@ LL | v[3i32];
4747
= note: required for `Vec<isize>` to implement `Index<i32>`
4848

4949
error[E0277]: the type `[u8]` cannot be indexed by `u8`
50-
--> $DIR/integral-indexing.rs:12:18
50+
--> $DIR/indexing-integral-types.rs:21:18
5151
|
5252
LL | s.as_bytes()[3u8];
5353
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -59,7 +59,7 @@ LL | s.as_bytes()[3u8];
5959
= note: required for `[u8]` to implement `Index<u8>`
6060

6161
error[E0277]: the type `[u8]` cannot be indexed by `i8`
62-
--> $DIR/integral-indexing.rs:13:18
62+
--> $DIR/indexing-integral-types.rs:22:18
6363
|
6464
LL | s.as_bytes()[3i8];
6565
| ^^^ slice indices are of type `usize` or ranges of `usize`
@@ -71,7 +71,7 @@ LL | s.as_bytes()[3i8];
7171
= note: required for `[u8]` to implement `Index<i8>`
7272

7373
error[E0277]: the type `[u8]` cannot be indexed by `u32`
74-
--> $DIR/integral-indexing.rs:14:18
74+
--> $DIR/indexing-integral-types.rs:23:18
7575
|
7676
LL | s.as_bytes()[3u32];
7777
| ^^^^ slice indices are of type `usize` or ranges of `usize`
@@ -83,7 +83,7 @@ LL | s.as_bytes()[3u32];
8383
= note: required for `[u8]` to implement `Index<u32>`
8484

8585
error[E0277]: the type `[u8]` cannot be indexed by `i32`
86-
--> $DIR/integral-indexing.rs:15:18
86+
--> $DIR/indexing-integral-types.rs:24:18
8787
|
8888
LL | s.as_bytes()[3i32];
8989
| ^^^^ slice indices are of type `usize` or ranges of `usize`

0 commit comments

Comments
 (0)