@@ -97,23 +97,31 @@ impl Definition {
97
97
}
98
98
99
99
pub fn enclosing_definition ( & self , db : & RootDatabase ) -> Option < Definition > {
100
+ fn container_to_definition ( container : ItemContainer ) -> Option < Definition > {
101
+ match container {
102
+ ItemContainer :: Trait ( it) => Some ( it. into ( ) ) ,
103
+ ItemContainer :: Impl ( it) => Some ( it. into ( ) ) ,
104
+ ItemContainer :: Module ( it) => Some ( it. into ( ) ) ,
105
+ ItemContainer :: ExternBlock ( ) | ItemContainer :: Crate ( _) => None ,
106
+ }
107
+ }
100
108
match self {
101
109
Definition :: Macro ( it) => Some ( it. module ( db) . into ( ) ) ,
102
110
Definition :: Module ( it) => it. parent ( db) . map ( Definition :: Module ) ,
103
111
Definition :: Field ( it) => Some ( it. parent_def ( db) . into ( ) ) ,
104
- Definition :: Function ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
112
+ Definition :: Function ( it) => container_to_definition ( it. container ( db) ) ,
105
113
Definition :: Adt ( it) => Some ( it. module ( db) . into ( ) ) ,
106
- Definition :: Const ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
107
- Definition :: Static ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
108
- Definition :: Trait ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
109
- Definition :: TraitAlias ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
110
- Definition :: TypeAlias ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
114
+ Definition :: Const ( it) => container_to_definition ( it. container ( db) ) ,
115
+ Definition :: Static ( it) => container_to_definition ( it. container ( db) ) ,
116
+ Definition :: Trait ( it) => container_to_definition ( it. container ( db) ) ,
117
+ Definition :: TraitAlias ( it) => container_to_definition ( it. container ( db) ) ,
118
+ Definition :: TypeAlias ( it) => container_to_definition ( it. container ( db) ) ,
111
119
Definition :: Variant ( it) => Some ( Adt :: Enum ( it. parent_enum ( db) ) . into ( ) ) ,
112
120
Definition :: SelfType ( it) => Some ( it. module ( db) . into ( ) ) ,
113
121
Definition :: Local ( it) => it. parent ( db) . try_into ( ) . ok ( ) ,
114
122
Definition :: GenericParam ( it) => Some ( it. parent ( ) . into ( ) ) ,
115
123
Definition :: Label ( it) => it. parent ( db) . try_into ( ) . ok ( ) ,
116
- Definition :: ExternCrateDecl ( it) => it. container ( db) . try_into ( ) . ok ( ) ,
124
+ Definition :: ExternCrateDecl ( it) => container_to_definition ( it. container ( db) ) ,
117
125
Definition :: DeriveHelper ( it) => Some ( it. derive ( ) . module ( db) . into ( ) ) ,
118
126
Definition :: InlineAsmOperand ( it) => it. parent ( db) . try_into ( ) . ok ( ) ,
119
127
Definition :: BuiltinAttr ( _)
@@ -955,18 +963,6 @@ impl TryFrom<DefWithBody> for Definition {
955
963
}
956
964
}
957
965
958
- impl TryFrom < ItemContainer > for Definition {
959
- type Error = ( ) ;
960
- fn try_from ( container : ItemContainer ) -> Result < Self , Self :: Error > {
961
- match container {
962
- ItemContainer :: Trait ( it) => Ok ( it. into ( ) ) ,
963
- ItemContainer :: Impl ( it) => Ok ( it. into ( ) ) ,
964
- ItemContainer :: Module ( it) => Ok ( it. into ( ) ) ,
965
- ItemContainer :: ExternBlock ( ) | ItemContainer :: Crate ( _) => Err ( ( ) ) ,
966
- }
967
- }
968
- }
969
-
970
966
impl From < GenericDef > for Definition {
971
967
fn from ( def : GenericDef ) -> Self {
972
968
match def {
0 commit comments