Uh oh!
There was an error while loading. Please reload this page.
Use primitive indexing in slice's Index/IndexMut - #36454
Conversation
rust-highfive
commented
Sep 13, 2016
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
commented
Sep 13, 2016
@bors: r+ Thanks! |
bors
commented
Sep 13, 2016
📌 Commit 20b9f1c has been approved by |
sfackler
commented
Sep 13, 2016
bors
commented
Sep 14, 2016
⌛ Testing commit 20b9f1c with merge 5675d4f... |
bors
commented
Sep 14, 2016
💔 Test failed - auto-win-msvc-64-opt-rustbuild |
alexcrichton
commented
Sep 14, 2016
@bors: retry On Tue, Sep 13, 2016 at 7:48 PM, bors notifications@github.com wrote:
|
bluss
commented
Sep 14, 2016
Thanks @sfackler |
20b9f1c to
7e425d9Comparebluss
commented
Sep 14, 2016
So huh, it has using the Index trait for arrays, that's not how I understood it. |
bluss
commented
Sep 14, 2016
Fixed the test by amending the commit. |
bluss
commented
Sep 14, 2016
To explain the mystery, it looks like array indexing uses the Index trait for slice in constexprs, and compiler-supplied indexing otherwise (do you know about this @oli-obk ?) |
alexcrichton
commented
Sep 14, 2016
@bors: r+ |
bors
commented
Sep 14, 2016
📌 Commit 7e425d9 has been approved by |
oli-obk
commented
Sep 14, 2016
The error pattern is still wrong. It should not include "assertion failed". The constexpr behaviour sounds very odd. Might be related to @eddyb's new const trans? |
alexcrichton
commented
Sep 14, 2016
@bors: r- Indeed looks like travis is still failing |
eddyb
commented
Sep 14, 2016
Not sure if relevant, but if integer type inference is being relied on, #33903 could be involved. |
[T]'s Index implementation is normally not used for indexing, instead
the compiler supplied indexing is used.
Use the compiler supplied version in Index/IndexMut.
This removes an inconsistency:
Compiler supplied bound check failures look like this:
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4'
If you convince Rust to use the Index impl for slices, bounds check
failure looks like this instead:
thread 'main' panicked at 'assertion failed: index < self.len()'
The latter is used if you for example use Index generically::
use std::ops::Index;
fn foo<T: ?Sized>(x: &T) where T: Index<usize> { &x[4]; }
foo(&[1, 2, 3][..])bluss
commented
Sep 14, 2016
Oh! Sorry, that was dumb. I'm fixing this up. |
7e425d9 to
a4ee9c6Comparebluss
commented
Sep 14, 2016
@bors r=alexcrichton |
bors
commented
Sep 14, 2016
📌 Commit a4ee9c6 has been approved by |
…crichton
Use primitive indexing in slice's Index/IndexMut
[T]'s Index implementation is normally not used for indexing, instead
the compiler supplied indexing is used.
Use the compiler supplied version in Index/IndexMut.
This removes an inconsistency:
Compiler supplied bound check failures look like this:
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4'
If you convince Rust to use the Index impl for slices, bounds check
failure looks like this instead:
thread 'main' panicked at 'assertion failed: index < self.len()'
The latter is used if you for example use Index generically:
```rust
use std::ops::Index;
fn foo<T: ?Sized>(x: &T) where T: Index<usize> { &x[4]; }
foo(&[1, 2, 3][..])
```
[T]'s Index implementation is normally not used for indexing, instead
the compiler supplied indexing is used.
Use the compiler supplied version in Index/IndexMut.
This removes an inconsistency:
Compiler supplied bound check failures look like this:
thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 4'
If you convince Rust to use the Index impl for slices, bounds check
failure looks like this instead:
thread 'main' panicked at 'assertion failed: index < self.len()'
The latter is used if you for example use Index generically: