Skip to content

Commit fb0ab9f

Browse files
committed
Keep SyntaxNodePtr::range private
1 parent 66cea8c commit fb0ab9f

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

crates/hir_ty/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl fmt::Display for CaseType {
267267
#[derive(Debug)]
268268
pub struct IncorrectCase {
269269
pub file: HirFileId,
270-
pub ident: SyntaxNodePtr,
270+
pub ident: AstPtr<ast::Name>,
271271
pub expected_case: CaseType,
272272
pub ident_type: String,
273273
pub ident_text: String,
@@ -290,7 +290,7 @@ impl Diagnostic for IncorrectCase {
290290
}
291291

292292
fn display_source(&self) -> InFile<SyntaxNodePtr> {
293-
InFile::new(self.file, self.ident.clone())
293+
InFile::new(self.file, self.ident.clone().into())
294294
}
295295

296296
fn as_any(&self) -> &(dyn Any + Send + 'static) {

crates/hir_ty/src/diagnostics/decl_check.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,21 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
213213
for param_to_rename in fn_param_replacements {
214214
// We assume that parameters in replacement are in the same order as in the
215215
// 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 {
217217
match fn_params_iter.next() {
218218
Some(element)
219219
if pat_equals_to_name(element.pat(), &param_to_rename.current_name) =>
220220
{
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+
}
222231
}
223232
Some(_) => {}
224233
None => {

crates/ide/src/diagnostics/fixes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ impl DiagnosticWithFix for MissingOkInTailExpr {
104104

105105
impl DiagnosticWithFix for IncorrectCase {
106106
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+
107110
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();
109112
let file_position = FilePosition { file_id, offset };
110113

111114
let rename_changes = rename_with_semantics(sema, file_position, &self.suggested_text)?;

crates/syntax/src/ptr.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ impl SyntaxNodePtr {
2323
SyntaxNodePtr { range: node.text_range(), kind: node.kind() }
2424
}
2525

26-
pub fn text_range(&self) -> TextRange {
27-
self.range.clone()
28-
}
29-
3026
pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode {
3127
assert!(root.parent().is_none());
3228
successors(Some(root.clone()), |node| {

0 commit comments

Comments
 (0)