Make str indexing generic on SliceIndex.
This commit is contained in:
parent
af73e64423
commit
c7d25a2a40
13 changed files with 240 additions and 236 deletions
|
|
@ -1,4 +1,4 @@
|
|||
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[{integer}]>` is not satisfied
|
||||
error[E0277]: the type `[{integer}]` cannot be indexed by `i32`
|
||||
--> $DIR/index-help.rs:3:5
|
||||
|
|
||||
LL | x[0i32]; //~ ERROR E0277
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
fn main() {
|
||||
fn bar<T>(_: T) {}
|
||||
[0][0u8]; //~ ERROR: the trait bound `u8: std::slice::SliceIndex<[{integer}]>` is not satisfied
|
||||
[0][0u8]; //~ ERROR: the type `[{integer}]` cannot be indexed by `u8`
|
||||
|
||||
[0][0]; // should infer to be a usize
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
error[E0277]: the trait bound `u8: std::slice::SliceIndex<[{integer}]>` is not satisfied
|
||||
error[E0277]: the type `[{integer}]` cannot be indexed by `u8`
|
||||
--> $DIR/indexing-requires-a-uint.rs:6:5
|
||||
|
|
||||
LL | [0][0u8]; //~ ERROR: the trait bound `u8: std::slice::SliceIndex<[{integer}]>` is not satisfied
|
||||
LL | [0][0u8]; //~ ERROR: the type `[{integer}]` cannot be indexed by `u8`
|
||||
| ^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[{integer}]>` is not implemented for `u8`
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ pub fn main() {
|
|||
let s: String = "abcdef".to_string();
|
||||
v[3_usize];
|
||||
v[3];
|
||||
v[3u8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
v[3i8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
v[3u32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
v[3i32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
v[3u8]; //~ERROR : the type `[isize]` cannot be indexed by `u8`
|
||||
v[3i8]; //~ERROR : the type `[isize]` cannot be indexed by `i8`
|
||||
v[3u32]; //~ERROR : the type `[isize]` cannot be indexed by `u32`
|
||||
v[3i32]; //~ERROR : the type `[isize]` cannot be indexed by `i32`
|
||||
s.as_bytes()[3_usize];
|
||||
s.as_bytes()[3];
|
||||
s.as_bytes()[3u8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
s.as_bytes()[3i8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
s.as_bytes()[3u32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
s.as_bytes()[3i32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
s.as_bytes()[3u8]; //~ERROR : the type `[u8]` cannot be indexed by `u8`
|
||||
s.as_bytes()[3i8]; //~ERROR : the type `[u8]` cannot be indexed by `i8`
|
||||
s.as_bytes()[3u32]; //~ERROR : the type `[u8]` cannot be indexed by `u32`
|
||||
s.as_bytes()[3i32]; //~ERROR : the type `[u8]` cannot be indexed by `i32`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,70 +1,70 @@
|
|||
error[E0277]: the trait bound `u8: std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `u8`
|
||||
--> $DIR/integral-indexing.rs:6:5
|
||||
|
|
||||
LL | v[3u8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
LL | v[3u8]; //~ERROR : the type `[isize]` cannot be indexed by `u8`
|
||||
| ^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `u8`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<u8>` for `std::vec::Vec<isize>`
|
||||
|
||||
error[E0277]: the trait bound `i8: std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `i8`
|
||||
--> $DIR/integral-indexing.rs:7:5
|
||||
|
|
||||
LL | v[3i8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
LL | v[3i8]; //~ERROR : the type `[isize]` cannot be indexed by `i8`
|
||||
| ^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `i8`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<i8>` for `std::vec::Vec<isize>`
|
||||
|
||||
error[E0277]: the trait bound `u32: std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `u32`
|
||||
--> $DIR/integral-indexing.rs:8:5
|
||||
|
|
||||
LL | v[3u32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
LL | v[3u32]; //~ERROR : the type `[isize]` cannot be indexed by `u32`
|
||||
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `u32`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<u32>` for `std::vec::Vec<isize>`
|
||||
|
||||
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
error[E0277]: the type `[isize]` cannot be indexed by `i32`
|
||||
--> $DIR/integral-indexing.rs:9:5
|
||||
|
|
||||
LL | v[3i32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
|
||||
LL | v[3i32]; //~ERROR : the type `[isize]` cannot be indexed by `i32`
|
||||
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `i32`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `std::vec::Vec<isize>`
|
||||
|
||||
error[E0277]: the trait bound `u8: std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `u8`
|
||||
--> $DIR/integral-indexing.rs:12:5
|
||||
|
|
||||
LL | s.as_bytes()[3u8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
LL | s.as_bytes()[3u8]; //~ERROR : the type `[u8]` cannot be indexed by `u8`
|
||||
| ^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `u8`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<u8>` for `[u8]`
|
||||
|
||||
error[E0277]: the trait bound `i8: std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `i8`
|
||||
--> $DIR/integral-indexing.rs:13:5
|
||||
|
|
||||
LL | s.as_bytes()[3i8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
LL | s.as_bytes()[3i8]; //~ERROR : the type `[u8]` cannot be indexed by `i8`
|
||||
| ^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `i8`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<i8>` for `[u8]`
|
||||
|
||||
error[E0277]: the trait bound `u32: std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `u32`
|
||||
--> $DIR/integral-indexing.rs:14:5
|
||||
|
|
||||
LL | s.as_bytes()[3u32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
LL | s.as_bytes()[3u32]; //~ERROR : the type `[u8]` cannot be indexed by `u32`
|
||||
| ^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `u32`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<u32>` for `[u8]`
|
||||
|
||||
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
error[E0277]: the type `[u8]` cannot be indexed by `i32`
|
||||
--> $DIR/integral-indexing.rs:15:5
|
||||
|
|
||||
LL | s.as_bytes()[3i32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
|
||||
LL | s.as_bytes()[3i32]; //~ERROR : the type `[u8]` cannot be indexed by `i32`
|
||||
| ^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `i32`
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[i32]>` is not satisfied
|
||||
error[E0277]: the type `[i32]` cannot be indexed by `i32`
|
||||
--> $DIR/slice-index.rs:11:5
|
||||
|
|
||||
LL | x[1i32]; //~ ERROR E0277
|
||||
|
|
@ -7,7 +7,7 @@ LL | x[1i32]; //~ ERROR E0277
|
|||
= help: the trait `std::slice::SliceIndex<[i32]>` is not implemented for `i32`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `[i32]`
|
||||
|
||||
error[E0277]: the trait bound `std::ops::RangeTo<i32>: std::slice::SliceIndex<[i32]>` is not satisfied
|
||||
error[E0277]: the type `[i32]` cannot be indexed by `std::ops::RangeTo<i32>`
|
||||
--> $DIR/slice-index.rs:12:5
|
||||
|
|
||||
LL | x[..1i32]; //~ ERROR E0277
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
pub fn main() {
|
||||
let s: &str = "hello";
|
||||
let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
let _: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
let _ = s.get(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
let _ = s.get_unchecked(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
let _: u8 = s['c']; //~ ERROR the type `str` cannot be indexed by `char`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,43 @@
|
|||
error[E0277]: the type `str` cannot be indexed by `{integer}`
|
||||
--> $DIR/str-idx.rs:3:17
|
||||
|
|
||||
LL | let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
| ^^^^ `str` cannot be indexed by `{integer}`
|
||||
LL | let _: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
| ^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::ops::Index<{integer}>` is not implemented for `str`
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
|
||||
= note: you can use `.chars().nth()` or `.bytes().nth()`
|
||||
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<{integer}>` for `str`
|
||||
|
||||
error[E0277]: the type `str` cannot be indexed by `{integer}`
|
||||
--> $DIR/str-idx.rs:4:15
|
||||
|
|
||||
LL | let _ = s.get(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
| ^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
|
||||
= note: you can use `.chars().nth()` or `.bytes().nth()`
|
||||
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0277]: the type `str` cannot be indexed by `{integer}`
|
||||
--> $DIR/str-idx.rs:5:15
|
||||
|
|
||||
LL | let _ = s.get_unchecked(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
| ^^^^^^^^^^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
|
||||
= note: you can use `.chars().nth()` or `.bytes().nth()`
|
||||
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
|
||||
|
||||
error[E0277]: the type `str` cannot be indexed by `char`
|
||||
--> $DIR/str-idx.rs:6:17
|
||||
|
|
||||
LL | let _: u8 = s['c']; //~ ERROR the type `str` cannot be indexed by `char`
|
||||
| ^^^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `char`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<char>` for `str`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@ fn mutate(s: &mut str) {
|
|||
//~^ ERROR the size for values of type
|
||||
//~| ERROR the size for values of type
|
||||
s[1usize] = bot();
|
||||
//~^ ERROR the type `str` cannot be mutably indexed by `usize`
|
||||
//~^ ERROR the type `str` cannot be indexed by `usize`
|
||||
s.get_mut(1);
|
||||
//~^ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
s.get_unchecked_mut(1);
|
||||
//~^ ERROR the type `str` cannot be indexed by `{integer}`
|
||||
s['c'];
|
||||
//~^ ERROR the type `str` cannot be indexed by `char`
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
|
|
|
|||
|
|
@ -22,16 +22,44 @@ LL | s[1..2] = bot();
|
|||
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
|
||||
= note: the left-hand-side of an assignment must have a statically known size
|
||||
|
||||
error[E0277]: the type `str` cannot be mutably indexed by `usize`
|
||||
error[E0277]: the type `str` cannot be indexed by `usize`
|
||||
--> $DIR/str-mut-idx.rs:7:5
|
||||
|
|
||||
LL | s[1usize] = bot();
|
||||
| ^^^^^^^^^ `str` cannot be mutably indexed by `usize`
|
||||
| ^^^^^^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::ops::IndexMut<usize>` is not implemented for `str`
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `usize`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<usize>` for `str`
|
||||
|
||||
error[E0277]: the type `str` cannot be indexed by `{integer}`
|
||||
--> $DIR/str-mut-idx.rs:9:7
|
||||
|
|
||||
LL | s.get_mut(1);
|
||||
| ^^^^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
|
||||
= note: you can use `.chars().nth()` or `.bytes().nth()`
|
||||
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0277]: the type `str` cannot be indexed by `{integer}`
|
||||
--> $DIR/str-mut-idx.rs:11:7
|
||||
|
|
||||
LL | s.get_unchecked_mut(1);
|
||||
| ^^^^^^^^^^^^^^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
|
||||
= note: you can use `.chars().nth()` or `.bytes().nth()`
|
||||
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
|
||||
|
||||
error[E0277]: the type `str` cannot be indexed by `char`
|
||||
--> $DIR/str-mut-idx.rs:13:5
|
||||
|
|
||||
LL | s['c'];
|
||||
| ^^^^^^ string indices are ranges of `usize`
|
||||
|
|
||||
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `char`
|
||||
= note: required because of the requirements on the impl of `std::ops::Index<char>` for `str`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue