Skip to content

Commit 43edb51

Browse files
committed
Generalize disallowing of definition renaming
1 parent 7ae70a0 commit 43edb51

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

crates/ide-db/src/rename.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,24 @@ impl Definition {
7171
sema: &Semantics<'_, RootDatabase>,
7272
new_name: &str,
7373
) -> Result<SourceChange> {
74+
if let Some(krate) = self.krate(sema.db) {
75+
if !matches!(krate.origin(sema.db), CrateOrigin::Local { .. }) {
76+
bail!("Cannot rename a non-local definition.")
77+
}
78+
}
79+
7480
match *self {
7581
Definition::Module(module) => rename_mod(sema, module, new_name),
7682
Definition::BuiltinType(_) => {
7783
bail!("Cannot rename builtin type")
7884
}
7985
Definition::SelfType(_) => bail!("Cannot rename `Self`"),
80-
Definition::Adt(hir::Adt::Struct(strukt)) => {
81-
if !matches!(
82-
strukt.module(sema.db).krate().origin(sema.db),
83-
CrateOrigin::Local { .. }
84-
) {
85-
bail!("Cannot rename a non-local struct.")
86+
Definition::Macro(mac) => {
87+
if mac.is_builtin_derive(sema.db) {
88+
bail!("Cannot rename builtin macro")
8689
}
87-
rename_reference(sema, Definition::Adt(hir::Adt::Struct(strukt)), new_name)
90+
91+
rename_reference(sema, Definition::Macro(mac), new_name)
8892
}
8993
def => rename_reference(sema, def, new_name),
9094
}

crates/ide/src/rename.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ use qux as frob;
26392639
=======
26402640

26412641
#[test]
2642-
fn disallow_renaming_for_non_local_struct() {
2642+
fn disallow_renaming_for_non_local_definition() {
26432643
check(
26442644
"Baz",
26452645
r#"
@@ -2648,7 +2648,7 @@ pub struct S$0;
26482648
//- /main.rs crate:main deps:lib new_source_root:local
26492649
use lib::S;
26502650
"#,
2651-
"error: Cannot rename a non-local struct.",
2651+
"error: Cannot rename a non-local definition.",
26522652
);
26532653
}
26542654
>>>>>>> 948d9f274 (Disallow renaming of non-local structs)

0 commit comments

Comments
 (0)