aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/diagnostics.rs6
-rw-r--r--crates/ra_hir_def/src/nameres.rs3
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs3
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs24
-rw-r--r--crates/ra_hir_ty/src/expr.rs14
-rw-r--r--crates/ra_hir_ty/src/infer.rs9
6 files changed, 8 insertions, 51 deletions
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs
index 2ee28fbaa..510c5e064 100644
--- a/crates/ra_hir_def/src/diagnostics.rs
+++ b/crates/ra_hir_def/src/diagnostics.rs
@@ -4,7 +4,7 @@ use std::any::Any;
4 4
5use hir_expand::diagnostics::Diagnostic; 5use hir_expand::diagnostics::Diagnostic;
6use ra_db::RelativePathBuf; 6use ra_db::RelativePathBuf;
7use ra_syntax::{ast, AstPtr, SyntaxNodePtr, TextRange}; 7use ra_syntax::{ast, AstPtr, SyntaxNodePtr};
8 8
9use hir_expand::{HirFileId, InFile}; 9use hir_expand::{HirFileId, InFile};
10 10
@@ -12,7 +12,6 @@ use hir_expand::{HirFileId, InFile};
12pub struct UnresolvedModule { 12pub struct UnresolvedModule {
13 pub file: HirFileId, 13 pub file: HirFileId,
14 pub decl: AstPtr<ast::Module>, 14 pub decl: AstPtr<ast::Module>,
15 pub highlight_range: TextRange,
16 pub candidate: RelativePathBuf, 15 pub candidate: RelativePathBuf,
17} 16}
18 17
@@ -20,9 +19,6 @@ impl Diagnostic for UnresolvedModule {
20 fn message(&self) -> String { 19 fn message(&self) -> String {
21 "unresolved module".to_string() 20 "unresolved module".to_string()
22 } 21 }
23 fn highlight_range(&self) -> InFile<TextRange> {
24 InFile::new(self.file, self.highlight_range)
25 }
26 fn source(&self) -> InFile<SyntaxNodePtr> { 22 fn source(&self) -> InFile<SyntaxNodePtr> {
27 InFile::new(self.file, self.decl.clone().into()) 23 InFile::new(self.file, self.decl.clone().into())
28 } 24 }
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 4a5a93dad..f279c2ad4 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -297,7 +297,7 @@ pub enum ModuleSource {
297mod diagnostics { 297mod diagnostics {
298 use hir_expand::diagnostics::DiagnosticSink; 298 use hir_expand::diagnostics::DiagnosticSink;
299 use ra_db::RelativePathBuf; 299 use ra_db::RelativePathBuf;
300 use ra_syntax::{ast, AstNode, AstPtr}; 300 use ra_syntax::{ast, AstPtr};
301 301
302 use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId}; 302 use crate::{db::DefDatabase, diagnostics::UnresolvedModule, nameres::LocalModuleId, AstId};
303 303
@@ -326,7 +326,6 @@ mod diagnostics {
326 sink.push(UnresolvedModule { 326 sink.push(UnresolvedModule {
327 file: declaration.file_id, 327 file: declaration.file_id,
328 decl: AstPtr::new(&decl), 328 decl: AstPtr::new(&decl),
329 highlight_range: decl.syntax().text_range(),
330 candidate: candidate.clone(), 329 candidate: candidate.clone(),
331 }) 330 })
332 } 331 }
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs
index 813fbf0e2..99209c6e8 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -16,13 +16,12 @@
16 16
17use std::{any::Any, fmt}; 17use std::{any::Any, fmt};
18 18
19use ra_syntax::{SyntaxNode, SyntaxNodePtr, TextRange}; 19use ra_syntax::{SyntaxNode, SyntaxNodePtr};
20 20
21use crate::{db::AstDatabase, InFile}; 21use crate::{db::AstDatabase, InFile};
22 22
23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { 23pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static {
24 fn message(&self) -> String; 24 fn message(&self) -> String;
25 fn highlight_range(&self) -> InFile<TextRange>;
26 fn source(&self) -> InFile<SyntaxNodePtr>; 25 fn source(&self) -> InFile<SyntaxNodePtr>;
27 fn as_any(&self) -> &(dyn Any + Send + 'static); 26 fn as_any(&self) -> &(dyn Any + Send + 'static);
28} 27}
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 018c2ad3f..c8fd54861 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -3,7 +3,7 @@
3use std::any::Any; 3use std::any::Any;
4 4
5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile}; 5use hir_expand::{db::AstDatabase, name::Name, HirFileId, InFile};
6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr, TextRange}; 6use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr};
7use stdx::format_to; 7use stdx::format_to;
8 8
9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm}; 9pub use hir_def::{diagnostics::UnresolvedModule, expr::MatchArm};
@@ -13,7 +13,6 @@ pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink};
13pub struct NoSuchField { 13pub struct NoSuchField {
14 pub file: HirFileId, 14 pub file: HirFileId,
15 pub field: AstPtr<ast::RecordField>, 15 pub field: AstPtr<ast::RecordField>,
16 pub highlight_range: TextRange,
17} 16}
18 17
19impl Diagnostic for NoSuchField { 18impl Diagnostic for NoSuchField {
@@ -21,10 +20,6 @@ impl Diagnostic for NoSuchField {
21 "no such field".to_string() 20 "no such field".to_string()
22 } 21 }
23 22
24 fn highlight_range(&self) -> InFile<TextRange> {
25 InFile::new(self.file, self.highlight_range)
26 }
27
28 fn source(&self) -> InFile<SyntaxNodePtr> { 23 fn source(&self) -> InFile<SyntaxNodePtr> {
29 InFile::new(self.file, self.field.clone().into()) 24 InFile::new(self.file, self.field.clone().into())
30 } 25 }
@@ -38,7 +33,6 @@ impl Diagnostic for NoSuchField {
38pub struct MissingFields { 33pub struct MissingFields {
39 pub file: HirFileId, 34 pub file: HirFileId,
40 pub field_list: AstPtr<ast::RecordFieldList>, 35 pub field_list: AstPtr<ast::RecordFieldList>,
41 pub highlight_range: TextRange,
42 pub missed_fields: Vec<Name>, 36 pub missed_fields: Vec<Name>,
43} 37}
44 38
@@ -50,10 +44,6 @@ impl Diagnostic for MissingFields {
50 } 44 }
51 buf 45 buf
52 } 46 }
53 fn highlight_range(&self) -> InFile<TextRange> {
54 InFile::new(self.file, self.highlight_range)
55 }
56
57 fn source(&self) -> InFile<SyntaxNodePtr> { 47 fn source(&self) -> InFile<SyntaxNodePtr> {
58 InFile { file_id: self.file, value: self.field_list.clone().into() } 48 InFile { file_id: self.file, value: self.field_list.clone().into() }
59 } 49 }
@@ -76,7 +66,6 @@ impl AstDiagnostic for MissingFields {
76pub struct MissingPatFields { 66pub struct MissingPatFields {
77 pub file: HirFileId, 67 pub file: HirFileId,
78 pub field_list: AstPtr<ast::RecordFieldPatList>, 68 pub field_list: AstPtr<ast::RecordFieldPatList>,
79 pub highlight_range: TextRange,
80 pub missed_fields: Vec<Name>, 69 pub missed_fields: Vec<Name>,
81} 70}
82 71
@@ -88,9 +77,6 @@ impl Diagnostic for MissingPatFields {
88 } 77 }
89 buf 78 buf
90 } 79 }
91 fn highlight_range(&self) -> InFile<TextRange> {
92 InFile::new(self.file, self.highlight_range)
93 }
94 fn source(&self) -> InFile<SyntaxNodePtr> { 80 fn source(&self) -> InFile<SyntaxNodePtr> {
95 InFile { file_id: self.file, value: self.field_list.clone().into() } 81 InFile { file_id: self.file, value: self.field_list.clone().into() }
96 } 82 }
@@ -104,16 +90,12 @@ pub struct MissingMatchArms {
104 pub file: HirFileId, 90 pub file: HirFileId,
105 pub match_expr: AstPtr<ast::Expr>, 91 pub match_expr: AstPtr<ast::Expr>,
106 pub arms: AstPtr<ast::MatchArmList>, 92 pub arms: AstPtr<ast::MatchArmList>,
107 pub highlight_range: TextRange,
108} 93}
109 94
110impl Diagnostic for MissingMatchArms { 95impl Diagnostic for MissingMatchArms {
111 fn message(&self) -> String { 96 fn message(&self) -> String {
112 String::from("Missing match arm") 97 String::from("Missing match arm")
113 } 98 }
114 fn highlight_range(&self) -> InFile<TextRange> {
115 InFile::new(self.file, self.highlight_range)
116 }
117 fn source(&self) -> InFile<SyntaxNodePtr> { 99 fn source(&self) -> InFile<SyntaxNodePtr> {
118 InFile { file_id: self.file, value: self.match_expr.clone().into() } 100 InFile { file_id: self.file, value: self.match_expr.clone().into() }
119 } 101 }
@@ -126,16 +108,12 @@ impl Diagnostic for MissingMatchArms {
126pub struct MissingOkInTailExpr { 108pub struct MissingOkInTailExpr {
127 pub file: HirFileId, 109 pub file: HirFileId,
128 pub expr: AstPtr<ast::Expr>, 110 pub expr: AstPtr<ast::Expr>,
129 pub highlight_range: TextRange,
130} 111}
131 112
132impl Diagnostic for MissingOkInTailExpr { 113impl Diagnostic for MissingOkInTailExpr {
133 fn message(&self) -> String { 114 fn message(&self) -> String {
134 "wrap return expression in Ok".to_string() 115 "wrap return expression in Ok".to_string()
135 } 116 }
136 fn highlight_range(&self) -> InFile<TextRange> {
137 InFile::new(self.file, self.highlight_range)
138 }
139 fn source(&self) -> InFile<SyntaxNodePtr> { 117 fn source(&self) -> InFile<SyntaxNodePtr> {
140 InFile { file_id: self.file, value: self.expr.clone().into() } 118 InFile { file_id: self.file, value: self.expr.clone().into() }
141 } 119 }
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 1d3950b70..fd59f4320 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
4 4
5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId}; 5use hir_def::{path::path, resolver::HasResolver, AdtId, FunctionId};
6use hir_expand::diagnostics::DiagnosticSink; 6use hir_expand::diagnostics::DiagnosticSink;
7use ra_syntax::{ast, AstNode, AstPtr}; 7use ra_syntax::{ast, AstPtr};
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
9 9
10use crate::{ 10use crate::{
@@ -100,7 +100,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
100 self.sink.push(MissingFields { 100 self.sink.push(MissingFields {
101 file: source_ptr.file_id, 101 file: source_ptr.file_id,
102 field_list: AstPtr::new(&field_list), 102 field_list: AstPtr::new(&field_list),
103 highlight_range: field_list.syntax().text_range(),
104 missed_fields, 103 missed_fields,
105 }) 104 })
106 } 105 }
@@ -131,7 +130,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
131 self.sink.push(MissingPatFields { 130 self.sink.push(MissingPatFields {
132 file: source_ptr.file_id, 131 file: source_ptr.file_id,
133 field_list: AstPtr::new(&field_list), 132 field_list: AstPtr::new(&field_list),
134 highlight_range: field_list.syntax().text_range(),
135 missed_fields, 133 missed_fields,
136 }) 134 })
137 } 135 }
@@ -215,7 +213,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
215 file: source_ptr.file_id, 213 file: source_ptr.file_id,
216 match_expr: AstPtr::new(&match_expr), 214 match_expr: AstPtr::new(&match_expr),
217 arms: AstPtr::new(&arms), 215 arms: AstPtr::new(&arms),
218 highlight_range: match_expr.syntax().text_range(),
219 }) 216 })
220 } 217 }
221 } 218 }
@@ -247,13 +244,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
247 let (_, source_map) = db.body_with_source_map(self.func.into()); 244 let (_, source_map) = db.body_with_source_map(self.func.into());
248 245
249 if let Ok(source_ptr) = source_map.expr_syntax(id) { 246 if let Ok(source_ptr) = source_map.expr_syntax(id) {
250 let root = source_ptr.file_syntax(db.upcast()); 247 self.sink
251 let highlight_range = source_ptr.value.to_node(&root).syntax().text_range(); 248 .push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value });
252 self.sink.push(MissingOkInTailExpr {
253 file: source_ptr.file_id,
254 expr: source_ptr.value,
255 highlight_range,
256 });
257 } 249 }
258 } 250 }
259 } 251 }
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs
index 7e6cdefe4..b6d9b3438 100644
--- a/crates/ra_hir_ty/src/infer.rs
+++ b/crates/ra_hir_ty/src/infer.rs
@@ -665,7 +665,6 @@ impl Expectation {
665mod diagnostics { 665mod diagnostics {
666 use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup}; 666 use hir_def::{expr::ExprId, src::HasSource, FunctionId, Lookup};
667 use hir_expand::diagnostics::DiagnosticSink; 667 use hir_expand::diagnostics::DiagnosticSink;
668 use ra_syntax::AstNode;
669 668
670 use crate::{db::HirDatabase, diagnostics::NoSuchField}; 669 use crate::{db::HirDatabase, diagnostics::NoSuchField};
671 670
@@ -686,13 +685,7 @@ mod diagnostics {
686 let source = owner.lookup(db.upcast()).source(db.upcast()); 685 let source = owner.lookup(db.upcast()).source(db.upcast());
687 let (_, source_map) = db.body_with_source_map(owner.into()); 686 let (_, source_map) = db.body_with_source_map(owner.into());
688 let field = source_map.field_syntax(*expr, *field); 687 let field = source_map.field_syntax(*expr, *field);
689 let root = field.file_syntax(db.upcast()); 688 sink.push(NoSuchField { file: source.file_id, field: field.value })
690 let highlight_range = field.value.to_node(&root).syntax().text_range();
691 sink.push(NoSuchField {
692 file: source.file_id,
693 field: field.value,
694 highlight_range,
695 })
696 } 689 }
697 } 690 }
698 } 691 }