Skip to content

Commit 8a7f0d9

Browse files
author
Jonas Schievink
committed
Allow macros to expand to or-patterns
1 parent 9700add commit 8a7f0d9

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

crates/hir/src/diagnostics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ pub struct MissingOkOrSomeInTailExpr {
164164
pub struct MissingMatchArms {
165165
pub file: HirFileId,
166166
pub match_expr: AstPtr<ast::Expr>,
167-
pub arms: AstPtr<ast::MatchArmList>,
168167
}
169168

170169
#[derive(Debug)]

crates/hir/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,17 +1266,14 @@ impl DefWithBody {
12661266
if let ast::Expr::MatchExpr(match_expr) =
12671267
&source_ptr.value.to_node(&root)
12681268
{
1269-
if let (Some(match_expr), Some(arms)) =
1270-
(match_expr.expr(), match_expr.match_arm_list())
1271-
{
1269+
if let Some(match_expr) = match_expr.expr() {
12721270
acc.push(
12731271
MissingMatchArms {
12741272
file: source_ptr.file_id,
12751273
match_expr: AstPtr::new(&match_expr),
1276-
arms: AstPtr::new(&arms),
12771274
}
12781275
.into(),
1279-
)
1276+
);
12801277
}
12811278
}
12821279
}

crates/ide_diagnostics/src/handlers/missing_match_arms.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,36 @@ fn foo() {
900900
);
901901
}
902902

903+
#[test]
904+
fn macro_or_pat() {
905+
check_diagnostics_no_bails(
906+
r#"
907+
macro_rules! m {
908+
() => {
909+
Enum::Type1 | Enum::Type2
910+
};
911+
}
912+
913+
enum Enum {
914+
Type1,
915+
Type2,
916+
Type3,
917+
}
918+
919+
fn f(ty: Enum) {
920+
match ty {
921+
//^^ error: missing match arm
922+
m!() => (),
923+
}
924+
925+
match ty {
926+
m!() | Enum::Type3 => ()
927+
}
928+
}
929+
"#,
930+
);
931+
}
932+
903933
mod false_negatives {
904934
//! The implementation of match checking here is a work in progress. As we roll this out, we
905935
//! prefer false negatives to false positives (ideally there would be no false positives). This

crates/parser/src/grammar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub(crate) mod entry {
112112

113113
pub(crate) fn pattern(p: &mut Parser) {
114114
let m = p.start();
115-
patterns::pattern_single(p);
115+
patterns::pattern_top(p);
116116
if p.at(EOF) {
117117
m.abandon(p);
118118
return;

0 commit comments

Comments
 (0)