-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team
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.
mark-i-m, CryZe, bluss, Boscop, sollyucko and 7 moremark-i-m, CryZe, RalfJung, Boscop, jplatte and 2 more
Metadata
Metadata
Assignees
Labels
A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language team
Type
Projects
Status
Idea