Open
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.