File: indexing-requires-a-uint.stderr

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (35 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
error[E0277]: the type `[{integer}]` cannot be indexed by `u8`
  --> $DIR/indexing-requires-a-uint.rs:6:9
   |
LL |     [0][0u8];
   |         ^^^ slice indices are of type `usize` or ranges of `usize`
   |
   = help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8`
           but it is implemented for `usize`
   = help: for that trait implementation, expected `usize`, found `u8`
   = note: required for `[{integer}]` to implement `Index<u8>`
   = note: 1 redundant requirement hidden
   = note: required for `[{integer}; 1]` to implement `Index<u8>`

error[E0308]: mismatched types
  --> $DIR/indexing-requires-a-uint.rs:12:18
   |
LL |     bar::<isize>(i);  // i should not be re-coerced back to an isize
   |     ------------ ^ expected `isize`, found `usize`
   |     |
   |     arguments to this function are incorrect
   |
note: function defined here
  --> $DIR/indexing-requires-a-uint.rs:5:8
   |
LL |     fn bar<T>(_: T) {}
   |        ^^^    ----
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
   |
LL |     bar::<isize>(i.try_into().unwrap());  // i should not be re-coerced back to an isize
   |                   ++++++++++++++++++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.