Skip to content

TAIT: ref mut destructuring does not require marking variable as mutable #160120

Description

@matthiaskrgr
#![feature(type_alias_impl_trait)]
#[derive(Copy, Clone)]
struct Foo((u32, u32));
fn main() {
    type T = impl Copy;
    let foo: T = Foo((2, 2));
    || {
        let Foo(ref mut cdr) = foo;
    };
}

this code fails to build with --edition=2015

error[E0596]: cannot borrow `foo.0` as mutable, as `foo` is not declared as mutable
 --> code.rs:8:17
  |
8 |         let Foo(ref mut cdr) = foo;
  |                 ^^^^^^^^^^^ cannot borrow as mutable
  |
help: consider changing this to be mutable
  |
6 |     let mut foo: T = Foo((2, 2));
  |         +++

warning: unused variable: `cdr`
 --> code.rs:8:17
  |
8 |         let Foo(ref mut cdr) = foo;
  |                 ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_cdr`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

but it compiles with --edition=2021 or 2024:

warning: unused closure that must be used
 --> code.rs:7:5
  |
7 | /     || {
8 | |         let Foo(ref mut cdr) = foo;
9 | |     };
  | |_____^
  |
  = note: closures are lazy and do nothing unless called
  = note: `#[warn(unused_must_use)]` (part of `#[warn(unused)]`) on by default

UNLESS we turn on the next solver, then it fails as above on all editions again 🤔

maybe there's some edition-specific code missing from the next solver?

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions