diff options
-rw-r--r-- | crates/hir_ty/src/diagnostics.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/decl_check.rs | 13 | ||||
-rw-r--r-- | crates/ide/src/diagnostics/fixes.rs | 5 | ||||
-rw-r--r-- | crates/syntax/src/ptr.rs | 4 |
4 files changed, 17 insertions, 9 deletions
diff --git a/crates/hir_ty/src/diagnostics.rs b/crates/hir_ty/src/diagnostics.rs index f2e06495e..dfe98571e 100644 --- a/crates/hir_ty/src/diagnostics.rs +++ b/crates/hir_ty/src/diagnostics.rs | |||
@@ -267,7 +267,7 @@ impl fmt::Display for CaseType { | |||
267 | #[derive(Debug)] | 267 | #[derive(Debug)] |
268 | pub struct IncorrectCase { | 268 | pub struct IncorrectCase { |
269 | pub file: HirFileId, | 269 | pub file: HirFileId, |
270 | pub ident: SyntaxNodePtr, | 270 | pub ident: AstPtr<ast::Name>, |
271 | pub expected_case: CaseType, | 271 | pub expected_case: CaseType, |
272 | pub ident_type: String, | 272 | pub ident_type: String, |
273 | pub ident_text: String, | 273 | pub ident_text: String, |
@@ -290,7 +290,7 @@ impl Diagnostic for IncorrectCase { | |||
290 | } | 290 | } |
291 | 291 | ||
292 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | 292 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
293 | InFile::new(self.file, self.ident.clone()) | 293 | InFile::new(self.file, self.ident.clone().into()) |
294 | } | 294 | } |
295 | 295 | ||
296 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 296 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index 1f9386b75..f987636fe 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs | |||
@@ -213,12 +213,21 @@ impl<'a, 'b> DeclValidator<'a, 'b> { | |||
213 | for param_to_rename in fn_param_replacements { | 213 | for param_to_rename in fn_param_replacements { |
214 | // We assume that parameters in replacement are in the same order as in the | 214 | // We assume that parameters in replacement are in the same order as in the |
215 | // actual params list, but just some of them (ones that named correctly) are skipped. | 215 | // actual params list, but just some of them (ones that named correctly) are skipped. |
216 | let ast_ptr = loop { | 216 | let ast_ptr: ast::Name = loop { |
217 | match fn_params_iter.next() { | 217 | match fn_params_iter.next() { |
218 | Some(element) | 218 | Some(element) |
219 | if pat_equals_to_name(element.pat(), ¶m_to_rename.current_name) => | 219 | if pat_equals_to_name(element.pat(), ¶m_to_rename.current_name) => |
220 | { | 220 | { |
221 | break element.pat().unwrap() | 221 | if let ast::Pat::IdentPat(pat) = element.pat().unwrap() { |
222 | break pat.name().unwrap(); | ||
223 | } else { | ||
224 | // This is critical. If we consider this parameter the expected one, | ||
225 | // it **must** have a name. | ||
226 | panic!( | ||
227 | "Pattern {:?} equals to expected replacement {:?}, but has no name", | ||
228 | element, param_to_rename | ||
229 | ); | ||
230 | } | ||
222 | } | 231 | } |
223 | Some(_) => {} | 232 | Some(_) => {} |
224 | None => { | 233 | None => { |
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 286ef0785..b47fe0469 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -104,8 +104,11 @@ impl DiagnosticWithFix for MissingOkInTailExpr { | |||
104 | 104 | ||
105 | impl DiagnosticWithFix for IncorrectCase { | 105 | impl DiagnosticWithFix for IncorrectCase { |
106 | fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> { | 106 | fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> { |
107 | let root = sema.db.parse_or_expand(self.file)?; | ||
108 | let name_node = self.ident.to_node(&root); | ||
109 | |||
107 | let file_id = self.file.original_file(sema.db); | 110 | let file_id = self.file.original_file(sema.db); |
108 | let offset = self.ident.text_range().start(); | 111 | let offset = name_node.syntax().text_range().start(); |
109 | let file_position = FilePosition { file_id, offset }; | 112 | let file_position = FilePosition { file_id, offset }; |
110 | 113 | ||
111 | let rename_changes = rename_with_semantics(sema, file_position, &self.suggested_text)?; | 114 | let rename_changes = rename_with_semantics(sema, file_position, &self.suggested_text)?; |
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs index 34e20464a..d3fb7a5d9 100644 --- a/crates/syntax/src/ptr.rs +++ b/crates/syntax/src/ptr.rs | |||
@@ -23,10 +23,6 @@ impl SyntaxNodePtr { | |||
23 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } | 23 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } |
24 | } | 24 | } |
25 | 25 | ||
26 | pub fn text_range(&self) -> TextRange { | ||
27 | self.range.clone() | ||
28 | } | ||
29 | |||
30 | pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { | 26 | pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { |
31 | assert!(root.parent().is_none()); | 27 | assert!(root.parent().is_none()); |
32 | successors(Some(root.clone()), |node| { | 28 | successors(Some(root.clone()), |node| { |