mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
fix logic error: alias detection was too lenient
This commit is contained in:
parent
6cd15c296d
commit
4a1a5ff54e
1 changed files with 23 additions and 18 deletions
|
@ -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) => {
|
||||||
.map(|class| match class {
|
NameRefClass::classify(sema, name_ref)
|
||||||
NameRefClass::Definition(def) => def,
|
.map(|class| match class {
|
||||||
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
|
NameRefClass::Definition(def) => def,
|
||||||
Definition::Local(local_ref)
|
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
|
||||||
}
|
Definition::Local(local_ref)
|
||||||
})
|
}
|
||||||
.and_then(|def| {
|
})
|
||||||
// if the name differs from the definitions name it has to be an alias
|
.ok_or_else(|| format_err!("No references found at position"))
|
||||||
if def.name(sema.db).map_or(false, |it| it.to_string() != name_ref.text()) {
|
.and_then(|def| {
|
||||||
None
|
// if the name differs from the definitions name it has to be an alias
|
||||||
} else {
|
if def
|
||||||
Some((name_like.clone(), def))
|
.name(sema.db)
|
||||||
}
|
.map_or(false, |it| it.to_string() != name_ref.text())
|
||||||
})
|
{
|
||||||
.ok_or_else(|| format_err!("Renaming aliases is currently unsupported")),
|
Err(format_err!("Renaming aliases is currently unsupported"))
|
||||||
|
} else {
|
||||||
|
Ok((name_like.clone(), def))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
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() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue