-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.
Description
Code
fn meow(mut x: Option<u32>) {
match x {
Some(y) if { x = None; false } => loop {},
_ => loop {},
}
}Current output
error[E0506]: cannot assign to `x` because it is borrowed
--> meow.rs:3:22
|
3 | Some(y) if { x = None; false } => loop {},
| - ^^^^^^^^ - borrow later used here
| | |
| | `x` is assigned to here but it was already borrowed
| `x` is borrowed hereDesired output
error[E0510]: cannot assign `x` in match guard
--> meow.rs:3:22
|
2 | match x {
| - value is immutable in match guard
3 | Some(y) if { x = None; false } => loop {},
| ^^^^^^^^ cannot assignRationale and extra context
No response
Other cases
// with Some(_) instead of Some(y) as the pattern, E0510 is emitted already
fn meow(mut x: Option<u32>) {
match x {
Some(_) if { x = None; false } => loop {},
_ => loop {},
}
}Rust Version
rustc 1.87.0-nightly (85abb2763 2025-02-25)
binary: rustc
commit-hash: 85abb276361c424d64743c0965242dd0e7b866d1
commit-date: 2025-02-25
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.