@@ -97,23 +97,31 @@ impl Definition {
9797 }
9898
9999 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+ }
100108 match self {
101109 Definition :: Macro ( it) => Some ( it. module ( db) . into ( ) ) ,
102110 Definition :: Module ( it) => it. parent ( db) . map ( Definition :: Module ) ,
103111 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) ) ,
105113 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) ) ,
111119 Definition :: Variant ( it) => Some ( Adt :: Enum ( it. parent_enum ( db) ) . into ( ) ) ,
112120 Definition :: SelfType ( it) => Some ( it. module ( db) . into ( ) ) ,
113121 Definition :: Local ( it) => it. parent ( db) . try_into ( ) . ok ( ) ,
114122 Definition :: GenericParam ( it) => Some ( it. parent ( ) . into ( ) ) ,
115123 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) ) ,
117125 Definition :: DeriveHelper ( it) => Some ( it. derive ( ) . module ( db) . into ( ) ) ,
118126 Definition :: InlineAsmOperand ( it) => it. parent ( db) . try_into ( ) . ok ( ) ,
119127 Definition :: BuiltinAttr ( _)
@@ -955,18 +963,6 @@ impl TryFrom<DefWithBody> for Definition {
955963 }
956964}
957965
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-
970966impl From < GenericDef > for Definition {
971967 fn from ( def : GenericDef ) -> Self {
972968 match def {
0 commit comments