fix logic error: alias detection was too lenient

This commit is contained in:
Anatol Ulrich 2021-10-27 17:20:12 +02:00
parent 6cd15c296d
commit 4a1a5ff54e

View file

@ -147,22 +147,27 @@ fn find_definitions(
}) })
.map(|def| (name_like.clone(), def)) .map(|def| (name_like.clone(), def))
.ok_or_else(|| format_err!("No references found at position")), .ok_or_else(|| format_err!("No references found at position")),
ast::NameLike::NameRef(name_ref) => NameRefClass::classify(sema, name_ref) ast::NameLike::NameRef(name_ref) => {
NameRefClass::classify(sema, name_ref)
.map(|class| match class { .map(|class| match class {
NameRefClass::Definition(def) => def, NameRefClass::Definition(def) => def,
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => { NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
Definition::Local(local_ref) Definition::Local(local_ref)
} }
}) })
.ok_or_else(|| format_err!("No references found at position"))
.and_then(|def| { .and_then(|def| {
// if the name differs from the definitions name it has to be an alias // if the name differs from the definitions name it has to be an alias
if def.name(sema.db).map_or(false, |it| it.to_string() != name_ref.text()) { if def
None .name(sema.db)
.map_or(false, |it| it.to_string() != name_ref.text())
{
Err(format_err!("Renaming aliases is currently unsupported"))
} else { } else {
Some((name_like.clone(), def)) Ok((name_like.clone(), def))
} }
}) })
.ok_or_else(|| format_err!("Renaming aliases is currently unsupported")), }
ast::NameLike::Lifetime(lifetime) => { ast::NameLike::Lifetime(lifetime) => {
NameRefClass::classify_lifetime(sema, lifetime) NameRefClass::classify_lifetime(sema, lifetime)
.and_then(|class| match class { .and_then(|class| match class {
@ -183,8 +188,8 @@ fn find_definitions(
}); });
// TODO avoid collect() somehow? // TODO avoid collect() somehow?
let v: RenameResult<Vec<(ast::NameLike, Definition)>> = symbols.collect(); let res: RenameResult<Vec<(ast::NameLike, Definition)>> = symbols.collect();
match v { match res {
// remove duplicates // remove duplicates
Ok(v) => { Ok(v) => {
if v.is_empty() { if v.is_empty() {