mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
missing match arms diagnostic change source to match expression
This commit is contained in:
parent
5fe608fb31
commit
da6752d5f9
3 changed files with 7 additions and 3 deletions
|
@ -545,7 +545,7 @@ mod tests {
|
||||||
|
|
||||||
assert_snapshot!(
|
assert_snapshot!(
|
||||||
check_diagnostic_message(content),
|
check_diagnostic_message(content),
|
||||||
@"\"{\\n }\": Missing match arm\n"
|
@"\"()\": Missing match arm\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ impl AstDiagnostic for MissingFields {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MissingMatchArms {
|
pub struct MissingMatchArms {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
|
pub match_expr: AstPtr<ast::Expr>,
|
||||||
pub arms: AstPtr<ast::MatchArmList>,
|
pub arms: AstPtr<ast::MatchArmList>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ impl Diagnostic for MissingMatchArms {
|
||||||
String::from("Missing match arm")
|
String::from("Missing match arm")
|
||||||
}
|
}
|
||||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
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) {
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||||
self
|
self
|
||||||
|
|
|
@ -125,9 +125,12 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
|
||||||
if let Some(expr) = source_ptr.value.left() {
|
if let Some(expr) = source_ptr.value.left() {
|
||||||
let root = source_ptr.file_syntax(db.upcast());
|
let root = source_ptr.file_syntax(db.upcast());
|
||||||
if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) {
|
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 {
|
self.sink.push(MissingMatchArms {
|
||||||
file: source_ptr.file_id,
|
file: source_ptr.file_id,
|
||||||
|
match_expr: AstPtr::new(&match_expr),
|
||||||
arms: AstPtr::new(&arms),
|
arms: AstPtr::new(&arms),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue