aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 18:32:54 +0100
committerAleksey Kladov <[email protected]>2021-06-13 18:32:54 +0100
commitde1fc70ccd3bf7a0850e036a12cf866a80d46458 (patch)
treed93cc6be7678b8be01a5162e80bb3f8df84e8c50 /crates/hir/src
parent24262f9ff6ae9ea326fa35d238704d18e99d52a1 (diff)
internal: refactor find_map diagnostic
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/diagnostics.rs19
-rw-r--r--crates/hir/src/lib.rs11
2 files changed, 8 insertions, 22 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs
index 9afee0b90..c294a803b 100644
--- a/crates/hir/src/diagnostics.rs
+++ b/crates/hir/src/diagnostics.rs
@@ -41,6 +41,7 @@ diagnostics![
41 MissingUnsafe, 41 MissingUnsafe,
42 NoSuchField, 42 NoSuchField,
43 RemoveThisSemicolon, 43 RemoveThisSemicolon,
44 ReplaceFilterMapNextWithFindMap,
44 UnimplementedBuiltinMacro, 45 UnimplementedBuiltinMacro,
45 UnresolvedExternCrate, 46 UnresolvedExternCrate,
46 UnresolvedImport, 47 UnresolvedImport,
@@ -121,9 +122,6 @@ pub struct MissingFields {
121 pub missed_fields: Vec<Name>, 122 pub missed_fields: Vec<Name>,
122} 123}
123 124
124// Diagnostic: replace-filter-map-next-with-find-map
125//
126// This diagnostic is triggered when `.filter_map(..).next()` is used, rather than the more concise `.find_map(..)`.
127#[derive(Debug)] 125#[derive(Debug)]
128pub struct ReplaceFilterMapNextWithFindMap { 126pub struct ReplaceFilterMapNextWithFindMap {
129 pub file: HirFileId, 127 pub file: HirFileId,
@@ -131,21 +129,6 @@ pub struct ReplaceFilterMapNextWithFindMap {
131 pub next_expr: AstPtr<ast::Expr>, 129 pub next_expr: AstPtr<ast::Expr>,
132} 130}
133 131
134impl Diagnostic for ReplaceFilterMapNextWithFindMap {
135 fn code(&self) -> DiagnosticCode {
136 DiagnosticCode("replace-filter-map-next-with-find-map")
137 }
138 fn message(&self) -> String {
139 "replace filter_map(..).next() with find_map(..)".to_string()
140 }
141 fn display_source(&self) -> InFile<SyntaxNodePtr> {
142 InFile { file_id: self.file, value: self.next_expr.clone().into() }
143 }
144 fn as_any(&self) -> &(dyn Any + Send + 'static) {
145 self
146 }
147}
148
149#[derive(Debug)] 132#[derive(Debug)]
150pub struct MismatchedArgCount { 133pub struct MismatchedArgCount {
151 pub call_expr: InFile<AstPtr<ast::Expr>>, 134 pub call_expr: InFile<AstPtr<ast::Expr>>,
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index aaab5336a..b2731b62f 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -1168,10 +1168,13 @@ impl Function {
1168 } 1168 }
1169 BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => { 1169 BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { method_call_expr } => {
1170 if let Ok(next_source_ptr) = source_map.expr_syntax(method_call_expr) { 1170 if let Ok(next_source_ptr) = source_map.expr_syntax(method_call_expr) {
1171 sink.push(ReplaceFilterMapNextWithFindMap { 1171 acc.push(
1172 file: next_source_ptr.file_id, 1172 ReplaceFilterMapNextWithFindMap {
1173 next_expr: next_source_ptr.value, 1173 file: next_source_ptr.file_id,
1174 }); 1174 next_expr: next_source_ptr.value,
1175 }
1176 .into(),
1177 );
1175 } 1178 }
1176 } 1179 }
1177 BodyValidationDiagnostic::MismatchedArgCount { call_expr, expected, found } => { 1180 BodyValidationDiagnostic::MismatchedArgCount { call_expr, expected, found } => {