Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

mut keyword alone unexpectedly dereferences value in pattern matching #105647

Copy link
Copy link
@yescallop

Description

@yescallop
Issue body actions

I tried this code:

let [a] = &[()];
let [mut b] = &[()];
b = a;

I expected to see this happen: the mutable binding b has type &(), and thus the compilation succeeds without any error.

Instead, this happened: the mutable binding b has type (), and the compilation fails with error:

error[E0308]: mismatched types
  --> src\lib.rs:80:9
   |
79 |     let [mut b] = &[()];
   |          ----- expected due to the type of this binding
80 |     b = a;
   |         ^ expected `()`, found `&()`
   |
help: consider dereferencing the borrow
   |
80 |     b = *a;
   |         +

Meta

rustc --version --verbose:

rustc 1.68.0-nightly (37d7de337 2022-12-12)
binary: rustc
commit-hash: 37d7de337903a558dbeb1e82c844fe915ab8ff25
commit-date: 2022-12-12
host: x86_64-pc-windows-msvc
release: 1.68.0-nightly
LLVM version: 15.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.