about summary refs log tree commit diff
path: root/src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-11-16 17:26:11 +0100
committerGitHub <noreply@github.com>2020-11-16 17:26:11 +0100
commit4cdd22062580b46cbb6cf97ca56d59ebeb1e91b7 (patch)
tree4db6c92ac32c271ab3fc6b558ec1ba321ebf0d93 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs
parentf5230fbf76bafd86ee4376a0e26e551df8d17fec (diff)
parentc03dfa6671bb462d243c12c72c8829f98c99e394 (diff)
downloadrust-4cdd22062580b46cbb6cf97ca56d59ebeb1e91b7.tar.gz
rust-4cdd22062580b46cbb6cf97ca56d59ebeb1e91b7.zip
Rollup merge of #74989 - pubfnbar:impl-array-indexing, r=KodrAus
Implement `Index` and `IndexMut` for arrays

Adds implementations of `Index` and `IndexMut` for arrays that simply forward to the slice indexing implementation in order to fix the following problem:

If you implement `Index<MyIndexType>` for an array, you lose all the other indexing functionality that used to be available to the array via its implicit coercion to a slice. An example of what I'm talking about:
```rust
use std::ops::Index;

pub enum MyIndexType {
    _0, _1, _2, _3, _4, _5, _6, _7,
}

impl<T> Index<MyIndexType> for [T; 8] {
    type Output = T;

    fn index(&self, index: MyIndexType) -> &T {
        unsafe { self.get_unchecked(index as usize) }
    }
}

fn main() {
    let array = [11u8; 8];

    println!("{:?}", array[MyIndexType::_0]); // OK

    println!("{:?}", array[0usize]); // error[E0277]
    //               ^^^^^^^^^^^^^ `[u8; 8]` cannot be indexed by `usize`
}
```
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions