Generalize disallowing of definition renaming
This commit is contained in:
parent
7ae70a06ce
commit
43edb51b21
@ -71,20 +71,24 @@ pub fn rename(
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
new_name: &str,
|
||||
) -> Result<SourceChange> {
|
||||
if let Some(krate) = self.krate(sema.db) {
|
||||
if !matches!(krate.origin(sema.db), CrateOrigin::Local { .. }) {
|
||||
bail!("Cannot rename a non-local definition.")
|
||||
}
|
||||
}
|
||||
|
||||
match *self {
|
||||
Definition::Module(module) => rename_mod(sema, module, new_name),
|
||||
Definition::BuiltinType(_) => {
|
||||
bail!("Cannot rename builtin type")
|
||||
}
|
||||
Definition::SelfType(_) => bail!("Cannot rename `Self`"),
|
||||
Definition::Adt(hir::Adt::Struct(strukt)) => {
|
||||
if !matches!(
|
||||
strukt.module(sema.db).krate().origin(sema.db),
|
||||
CrateOrigin::Local { .. }
|
||||
) {
|
||||
bail!("Cannot rename a non-local struct.")
|
||||
Definition::Macro(mac) => {
|
||||
if mac.is_builtin_derive(sema.db) {
|
||||
bail!("Cannot rename builtin macro")
|
||||
}
|
||||
rename_reference(sema, Definition::Adt(hir::Adt::Struct(strukt)), new_name)
|
||||
|
||||
rename_reference(sema, Definition::Macro(mac), new_name)
|
||||
}
|
||||
def => rename_reference(sema, def, new_name),
|
||||
}
|
||||
|
@ -2639,7 +2639,7 @@ fn extern_crate_self_rename() {
|
||||
=======
|
||||
|
||||
#[test]
|
||||
fn disallow_renaming_for_non_local_struct() {
|
||||
fn disallow_renaming_for_non_local_definition() {
|
||||
check(
|
||||
"Baz",
|
||||
r#"
|
||||
@ -2648,7 +2648,7 @@ fn disallow_renaming_for_non_local_struct() {
|
||||
//- /main.rs crate:main deps:lib new_source_root:local
|
||||
use lib::S;
|
||||
"#,
|
||||
"error: Cannot rename a non-local struct.",
|
||||
"error: Cannot rename a non-local definition.",
|
||||
);
|
||||
}
|
||||
>>>>>>> 948d9f274 (Disallow renaming of non-local structs)
|
||||
|
Loading…
Reference in New Issue
Block a user