Skip to content

mut in slice pattern: [_, mut @ ..] = &[...] is not needed? #126676

Open

Description

Might be related to #123076

Code

fn foo(s: &[usize]) {
    let [a, b @ ..] = s else {panic!()};
    let [a, mut b @ ..] = s else {panic!()};
}

Current output

error[E0277]: the size for values of type `[usize]` cannot be known at compilation time
 --> src/lib.rs:3:13
  |
3 |     let [a, mut b @ ..] = s else {panic!()};
  |             ^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[usize]`
  = note: all local variables must have a statically known size
  = help: unsized locals are gated as an unstable feature

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

3 |     let [a, mut b @ ..] = s else {panic!()};
  |             ^^^^^^^^^^ doesn't have a size known at compile-time
                ^^^ help: remove this `mut` because ...

Rationale and extra context

I use mut b @ .. because I would like to change b later.
But removing mut makes it compile. So my thoughts are misleading.

Other cases

No response

Rust Version

Nightly version: 1.81.0-nightly

(2024-06-18 8fcd4dd08e2ba3e922d9)

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingA-slice-patternsArea: Slice patterns, https://github.com/rust-lang/rust/issues/23121Area: Slice patterns, https://github.com/rust-lang/rust/issues/23121T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler 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