@@ -24,7 +24,7 @@ use std::fmt;
24
24
25
25
use base_db:: { AnchoredPathBuf , CrateOrigin , FileId , FileRange } ;
26
26
use either:: Either ;
27
- use hir:: { FieldSource , HasSource , InFile , ModuleSource , Semantics } ;
27
+ use hir:: { Crate , FieldSource , HasCrate , HasSource , InFile , ModuleSource , Semantics } ;
28
28
use stdx:: never;
29
29
use syntax:: {
30
30
ast:: { self , HasName } ,
@@ -71,20 +71,24 @@ impl Definition {
71
71
sema : & Semantics < ' _ , RootDatabase > ,
72
72
new_name : & str ,
73
73
) -> 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
+
74
80
match * self {
75
81
Definition :: Module ( module) => rename_mod ( sema, module, new_name) ,
76
82
Definition :: BuiltinType ( _) => {
77
83
bail ! ( "Cannot rename builtin type" )
78
84
}
79
85
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" )
86
89
}
87
- rename_reference ( sema, Definition :: Adt ( hir:: Adt :: Struct ( strukt) ) , new_name)
90
+
91
+ rename_reference ( sema, Definition :: Macro ( mac) , new_name)
88
92
}
89
93
def => rename_reference ( sema, def, new_name) ,
90
94
}
0 commit comments