Open
Description
Consider the following:
struct S(u32);
fn foo(x: &S) {
let _: &u32 = match x {
S(y) => y,
_ => &0,
};
}
Here, the variable binding y
has type &u32
outside the pattern. However, inside the pattern it has type u32
. The fact that these types do not align is confusing, as it means you can't dereference y
inside the pattern like this:
fn foo(x: &S) {
let _: u32 = match x {
S(&y) => y,
_ => 0,
};
}
and instead have to dereference it outside the pattern:
fn foo(x: &S) {
let _: u32 = match x {
S(y) => *y,
_ => 0,
};
}
Is there any reason this was chosen to be the case, or is required to be the case? As it stands, this behaviour is very counter-intuitive.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Idea