mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 00:47:18 +00:00
Prevent renaming of aliases on usages
This commit is contained in:
parent
98395f29a4
commit
d30f2d43db
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))
|
||||
}
|
||||
ast::NameLike::NameRef(name_ref) => {
|
||||
NameRefClass::classify(sema, &name_ref).map(|class| class.referenced(sema.db))
|
||||
if let Some(def) =
|
||||
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)
|
||||
.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