Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r--crates/hir/src/diagnostics.rs90
1 files changed, 39 insertions, 51 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index 24c1b80bdf..2fedffe047 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -257,7 +257,7 @@ pub struct PrivateField {
#[derive(Debug)]
pub struct MissingUnsafe {
- pub expr: InFile<AstPtr<ast::Expr>>,
+ pub expr: InFile<AstPtr<Either<ast::Expr, ast::Pat>>>,
/// If true, the diagnostics is an `unsafe_op_in_unsafe_fn` lint instead of a hard error.
pub only_lint: bool,
}
@@ -398,56 +398,46 @@ impl AnyDiagnostic {
.map(|idx| variant_data.fields()[idx].name.clone())
.collect();
- match record {
- Either::Left(record_expr) => match source_map.expr_syntax(record_expr) {
- Ok(source_ptr) => {
- let root = source_ptr.file_syntax(db.upcast());
- if let ast::Expr::RecordExpr(record_expr) =
- source_ptr.value.to_node(&root)
- {
- if record_expr.record_expr_field_list().is_some() {
- let field_list_parent_path =
- record_expr.path().map(|path| AstPtr::new(&path));
- return Some(
- MissingFields {
- file: source_ptr.file_id,
- field_list_parent: AstPtr::new(&Either::Left(
- record_expr,
- )),
- field_list_parent_path,
- missed_fields,
- }
- .into(),
- );
+ let record = match record {
+ Either::Left(record_expr) => {
+ source_map.expr_syntax(record_expr).ok()?.map(AstPtr::wrap_left)
+ }
+ Either::Right(record_pat) => source_map.pat_syntax(record_pat).ok()?,
+ };
+ let file = record.file_id;
+ let root = record.file_syntax(db.upcast());
+ match record.value.to_node(&root) {
+ Either::Left(ast::Expr::RecordExpr(record_expr)) => {
+ if record_expr.record_expr_field_list().is_some() {
+ let field_list_parent_path =
+ record_expr.path().map(|path| AstPtr::new(&path));
+ return Some(
+ MissingFields {
+ file,
+ field_list_parent: AstPtr::new(&Either::Left(record_expr)),
+ field_list_parent_path,
+ missed_fields,
}
- }
+ .into(),
+ );
}
- Err(SyntheticSyntax) => (),
- },
- Either::Right(record_pat) => match source_map.pat_syntax(record_pat) {
- Ok(source_ptr) => {
- if let Some(ptr) = source_ptr.value.cast::<ast::RecordPat>() {
- let root = source_ptr.file_syntax(db.upcast());
- let record_pat = ptr.to_node(&root);
- if record_pat.record_pat_field_list().is_some() {
- let field_list_parent_path =
- record_pat.path().map(|path| AstPtr::new(&path));
- return Some(
- MissingFields {
- file: source_ptr.file_id,
- field_list_parent: AstPtr::new(&Either::Right(
- record_pat,
- )),
- field_list_parent_path,
- missed_fields,
- }
- .into(),
- );
+ }
+ Either::Right(ast::Pat::RecordPat(record_pat)) => {
+ if record_pat.record_pat_field_list().is_some() {
+ let field_list_parent_path =
+ record_pat.path().map(|path| AstPtr::new(&path));
+ return Some(
+ MissingFields {
+ file,
+ field_list_parent: AstPtr::new(&Either::Right(record_pat)),
+ field_list_parent_path,
+ missed_fields,
}
- }
+ .into(),
+ );
}
- Err(SyntheticSyntax) => (),
- },
+ }
+ _ => {}
}
}
BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => {
@@ -543,7 +533,7 @@ impl AnyDiagnostic {
};
let expr_or_pat_syntax = |id| match id {
ExprOrPatId::ExprId(expr) => expr_syntax(expr).map(|it| it.map(AstPtr::wrap_left)),
- ExprOrPatId::PatId(pat) => pat_syntax(pat).map(|it| it.map(AstPtr::wrap_right)),
+ ExprOrPatId::PatId(pat) => pat_syntax(pat),
};
Some(match d {
&InferenceDiagnostic::NoSuchField { field: expr, private, variant } => {
@@ -551,9 +541,7 @@ impl AnyDiagnostic {
ExprOrPatId::ExprId(expr) => {
source_map.field_syntax(expr).map(AstPtr::wrap_left)
}
- ExprOrPatId::PatId(pat) => {
- source_map.pat_field_syntax(pat).map(AstPtr::wrap_right)
- }
+ ExprOrPatId::PatId(pat) => source_map.pat_field_syntax(pat),
};
NoSuchField { field: expr_or_pat, private, variant }.into()
}