rust-lang / rust-lang/rust

Missing AsMut<[T;N]> for [T;N]

Open
#129,849 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

fn foo<T: AsMut<[u8; 12]>>(mut t: T) {
    t.as_mut()[0] = 0;
}
fn bar(x: &mut [u8; 12]) {
    foo(x);
}

I expected it to compile.

Instead, this happened:

error[E0277]: the trait bound `[u8; 12]: AsMut<[u8; 12]>` is not satisfied
 --> crate/src/it.rs:5:9
  |
5 |     foo(x);
  |     --- ^ the trait `AsMut<[u8; 12]>` is not implemented for `[u8; 12]`, which is required by `&mut [u8; 12]: AsMut<[u8; 12]>`
  |     |
  |     required by a bound introduced by this call
  |
  = help: the following other types implement trait `AsMut<T>`:
            [T; N]
            [T]
  = note: required for `&mut [u8; 12]` to implement `AsMut<[u8; 12]>`
note: required by a bound in `foo`
 --> crate/src/it.rs:1:11
  |
1 | fn foo<T: AsMut<[u8; 12]>>(mut t: T) {
  |           ^^^^^^^^^^^^^^^ required by this bound in `foo`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer in crate/src/it.rs and run it to confirm the AsMut<[u8; 12]> trait-bound error. Investigate the existing AsMut implementations for [T; N] and [T], then verify that the example compiles after the missing behavior is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.