-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pattern support #2082
Comments
basic identifiers in match expressions: match f { // f: i32
a => {}
} the gimple output here should be something like:
the idea here is that an identifier matches against any expression (hence, the |
Extending for match f { // f: (i32, i32, i32, i32)
(1, _, 2, a) => {}
(3, .., a) => {}
(a, .., b) => {}
} gimple:
For |
for ReferencePattern, we'll need to dereference the scrutinee and check against the inner pattern of the arm: match f { // f: &(i32, i32)
&(1, a) => {}
&(b, 5) => {}
&c => {}
} gimple:
For For match f { // f: (i32, i32, i32)
(1, a, _) | (2, _, a) => {
// do something with a here
}
_ => {}
} gimple:
|
a compile test for the unsupported patterns in function parameters. enum E {
A(i32, i32, i32, i32),
B { x: i32, y: i32 },
}
fn foo(
(a, .., b): (i32, i32, i32, i32, i32),
(E::A {0: c, 1: d, 2: 1, 3: 1} | E::A(.., c, d) | E::B { x: c, y: d }): E,
&([1, .., e, f] | [e, f, ..]): &[i32; 6],
) {
// use a, b, c, d, e, f here
} the same test can be used with let statement. A corner case which should compile successfully: fn foo(0..: u8) {} |
enum AnEnum {
VariantA,
VariantB { a: i32 },
}
use AnEnum::VariantA;
const X: u32 = 42;
fn main() {
match AnEnum::VariantA {
VariantA => (),
}
let VariantA = AnEnum::VariantA;
match 27 {
X => (),
}
let X = 27;
} All of these should fail to compile. |
Exhaustive list of what needs to be supported for patterns.
match:
1
,'a'
e
_
(1, 2, .., 10, 11)
)[a, b, _]
1..=5
..
Foo::A | Foo::B
Match to-dos (done items not listed)
MatchExpr
to if statements #2004)((Foo::A, 1), ('c', Foo::B))
(handled in hir: CompileMatchExpr
to if statements #2004)Some(x) if x < 10
if let
andwhile let
are not yet implemented but they'll follow the same logic as match.Once the refactor in #2004 is done, we'll be able to add support for if let and while let.
function params and let statements (refutable patterns omitted):
e
_
[a, b, _]
..
Foo::A | Foo::B
Params and Vars to-dos:
patterns in
for
loops cannot be added until #869 is finished.additional to-dos:
ref
mut
identifier pattern handlingAnything I forgot?
The text was updated successfully, but these errors were encountered: