TAIT: `ref mut` destructuring does not require marking variable as mutable
Open
Nobody has claimed this yet.
F-type_alias_impl_trait
fixed-by-next-solver
needs-triage
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the code.rs reproducer and compare compilation under editions 2015, 2021, and 2024, both with and without the next solver. Trace the handling of ref mut destructuring in the closure and type-alias-impl-trait case. Done means the edition and solver behavior is understood and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100