mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
Merge #9148
9148: minor: Prevent renaming of aliases on usages r=Veykril a=Veykril Otherwise trying to rename a usage that goes through an alias will still rename the aliased item instead, cc https://github.com/rust-analyzer/rust-analyzer/issues/5671 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
4c54ec1c3c
1 changed files with 32 additions and 1 deletions
|
@ -170,7 +170,17 @@ fn find_definition(
|
||||||
NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db))
|
NameClass::classify(sema, &name).map(|class| class.referenced_or_defined(sema.db))
|
||||||
}
|
}
|
||||||
ast::NameLike::NameRef(name_ref) => {
|
ast::NameLike::NameRef(name_ref) => {
|
||||||
|
if let Some(def) =
|
||||||
NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db))
|
NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db))
|
||||||
|
{
|
||||||
|
// 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()) {
|
||||||
|
bail!("Renaming aliases is currently unsupported");
|
||||||
|
}
|
||||||
|
Some(def)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime)
|
ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime)
|
||||||
.map(|class| NameRefClass::referenced(class, sema.db))
|
.map(|class| NameRefClass::referenced(class, sema.db))
|
||||||
|
@ -1907,4 +1917,25 @@ impl Fo0 where Self: {}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rename_fails_on_aliases() {
|
||||||
|
check(
|
||||||
|
"Baz",
|
||||||
|
r#"
|
||||||
|
struct Foo;
|
||||||
|
use Foo as Bar$0;
|
||||||
|
"#,
|
||||||
|
"error: Renaming aliases is currently unsupported",
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
"Baz",
|
||||||
|
r#"
|
||||||
|
struct Foo;
|
||||||
|
use Foo as Bar;
|
||||||
|
use Bar$0;
|
||||||
|
"#,
|
||||||
|
"error: Renaming aliases is currently unsupported",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue