-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.T-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
The following doesn't compile:
enum Test<'a> {
A(&'a u64),
B(u64),
}
fn foo(test: Test) {
match test {
Test::A(r) | Test::B(ref r) => println!("{}", r)
}
}
fn main() {
foo(Test::A(&0));
foo(Test::B(1));
}
failing with the following error:
test.rs:7:30: 7:35 error: variable `r` is bound with different mode in pattern #2 than in pattern #1
test.rs:7 Test::A(r) | Test::B(ref r) => println!("{}", r)
^~~~~
error: aborting due to previous error
However, the following does work:
enum Test<'a> {
A(&'a u64),
B(u64),
}
fn foo(test: Test) {
match test {
Test::A(&ref r) | Test::B(ref r) => println!("{}", r)
}
}
fn main() {
foo(Test::A(&0));
foo(Test::B(1));
}
Is there any reason rust can't just perform this reborrow automatically? &ref
is a very cryptic pattern.
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-bugCategory: This is a bug.Category: This is a bug.T-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.