mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Merge #11307
11307: fix: Allow macros to expand to or-patterns r=jonas-schievink a=jonas-schievink Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11097 Also simplifies the diagnostic slightly. bors r+ Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
This commit is contained in:
commit
1861654623
4 changed files with 33 additions and 7 deletions
|
@ -164,7 +164,6 @@ pub struct MissingOkOrSomeInTailExpr {
|
||||||
pub struct MissingMatchArms {
|
pub struct MissingMatchArms {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub match_expr: AstPtr<ast::Expr>,
|
pub match_expr: AstPtr<ast::Expr>,
|
||||||
pub arms: AstPtr<ast::MatchArmList>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1266,17 +1266,14 @@ impl DefWithBody {
|
||||||
if let ast::Expr::MatchExpr(match_expr) =
|
if let ast::Expr::MatchExpr(match_expr) =
|
||||||
&source_ptr.value.to_node(&root)
|
&source_ptr.value.to_node(&root)
|
||||||
{
|
{
|
||||||
if let (Some(match_expr), Some(arms)) =
|
if let Some(match_expr) = match_expr.expr() {
|
||||||
(match_expr.expr(), match_expr.match_arm_list())
|
|
||||||
{
|
|
||||||
acc.push(
|
acc.push(
|
||||||
MissingMatchArms {
|
MissingMatchArms {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
match_expr: AstPtr::new(&match_expr),
|
match_expr: AstPtr::new(&match_expr),
|
||||||
arms: AstPtr::new(&arms),
|
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -900,6 +900,36 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn macro_or_pat() {
|
||||||
|
check_diagnostics_no_bails(
|
||||||
|
r#"
|
||||||
|
macro_rules! m {
|
||||||
|
() => {
|
||||||
|
Enum::Type1 | Enum::Type2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Enum {
|
||||||
|
Type1,
|
||||||
|
Type2,
|
||||||
|
Type3,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f(ty: Enum) {
|
||||||
|
match ty {
|
||||||
|
//^^ error: missing match arm
|
||||||
|
m!() => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
match ty {
|
||||||
|
m!() | Enum::Type3 => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
mod false_negatives {
|
mod false_negatives {
|
||||||
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
||||||
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
||||||
|
|
|
@ -112,7 +112,7 @@ pub(crate) mod entry {
|
||||||
|
|
||||||
pub(crate) fn pattern(p: &mut Parser) {
|
pub(crate) fn pattern(p: &mut Parser) {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
patterns::pattern_single(p);
|
patterns::pattern_top(p);
|
||||||
if p.at(EOF) {
|
if p.at(EOF) {
|
||||||
m.abandon(p);
|
m.abandon(p);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue