missing match arms diagnostic change source to match expression

This commit is contained in:
Josh Mcguigan 2020-04-06 06:55:25 -07:00
parent 5fe608fb31
commit da6752d5f9
3 changed files with 7 additions and 3 deletions
crates/ra_hir_ty/src

@ -545,7 +545,7 @@ mod tests {
assert_snapshot!(
check_diagnostic_message(content),
@"\"{\\n }\": Missing match arm\n"
@"\"()\": Missing match arm\n"
);
}

@ -65,6 +65,7 @@ impl AstDiagnostic for MissingFields {
#[derive(Debug)]
pub struct MissingMatchArms {
pub file: HirFileId,
pub match_expr: AstPtr<ast::Expr>,
pub arms: AstPtr<ast::MatchArmList>,
}
@ -73,7 +74,7 @@ impl Diagnostic for MissingMatchArms {
String::from("Missing match arm")
}
fn source(&self) -> InFile<SyntaxNodePtr> {
InFile { file_id: self.file, value: self.arms.into() }
InFile { file_id: self.file, value: self.match_expr.into() }
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {
self

@ -125,9 +125,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
if let Some(expr) = source_ptr.value.left() {
let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) {
if let Some(arms) = match_expr.match_arm_list() {
if let (Some(match_expr), Some(arms)) =
(match_expr.expr(), match_expr.match_arm_list())
{
self.sink.push(MissingMatchArms {
file: source_ptr.file_id,
match_expr: AstPtr::new(&match_expr),
arms: AstPtr::new(&arms),
})
}