diff --git a/crates/ide-db/src/rename.rs b/crates/ide-db/src/rename.rs index 27add0ad371..adb9e55613f 100644 --- a/crates/ide-db/src/rename.rs +++ b/crates/ide-db/src/rename.rs @@ -71,20 +71,24 @@ pub fn rename( sema: &Semantics<'_, RootDatabase>, new_name: &str, ) -> Result { + 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), } diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs index 3017ca75366..5a6742d5c84 100644 --- a/crates/ide/src/rename.rs +++ b/crates/ide/src/rename.rs @@ -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)