Skip to content

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

@alexkazik

Description

@alexkazik

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`

Metadata

Metadata

Assignees

Labels

T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions