Skip to content

Commit 4a1a5ff

Browse files
author
Anatol Ulrich
committed
fix logic error: alias detection was too lenient
1 parent 6cd15c2 commit 4a1a5ff

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

crates/ide/src/rename.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,27 @@ fn find_definitions(
147147
})
148148
.map(|def| (name_like.clone(), def))
149149
.ok_or_else(|| format_err!("No references found at position")),
150-
ast::NameLike::NameRef(name_ref) => NameRefClass::classify(sema, name_ref)
151-
.map(|class| match class {
152-
NameRefClass::Definition(def) => def,
153-
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
154-
Definition::Local(local_ref)
155-
}
156-
})
157-
.and_then(|def| {
158-
// if the name differs from the definitions name it has to be an alias
159-
if def.name(sema.db).map_or(false, |it| it.to_string() != name_ref.text()) {
160-
None
161-
} else {
162-
Some((name_like.clone(), def))
163-
}
164-
})
165-
.ok_or_else(|| format_err!("Renaming aliases is currently unsupported")),
150+
ast::NameLike::NameRef(name_ref) => {
151+
NameRefClass::classify(sema, name_ref)
152+
.map(|class| match class {
153+
NameRefClass::Definition(def) => def,
154+
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
155+
Definition::Local(local_ref)
156+
}
157+
})
158+
.ok_or_else(|| format_err!("No references found at position"))
159+
.and_then(|def| {
160+
// if the name differs from the definitions name it has to be an alias
161+
if def
162+
.name(sema.db)
163+
.map_or(false, |it| it.to_string() != name_ref.text())
164+
{
165+
Err(format_err!("Renaming aliases is currently unsupported"))
166+
} else {
167+
Ok((name_like.clone(), def))
168+
}
169+
})
170+
}
166171
ast::NameLike::Lifetime(lifetime) => {
167172
NameRefClass::classify_lifetime(sema, lifetime)
168173
.and_then(|class| match class {
@@ -183,8 +188,8 @@ fn find_definitions(
183188
});
184189

185190
// TODO avoid collect() somehow?
186-
let v: RenameResult<Vec<(ast::NameLike, Definition)>> = symbols.collect();
187-
match v {
191+
let res: RenameResult<Vec<(ast::NameLike, Definition)>> = symbols.collect();
192+
match res {
188193
// remove duplicates
189194
Ok(v) => {
190195
if v.is_empty() {

0 commit comments

Comments
 (0)