2
2
use either:: Either ;
3
3
4
4
use hir_def:: {
5
- child_from_source:: ChildFromSource , nameres:: ModuleSource , AstItemDef , EnumVariantId ,
6
- LocationCtx , ModuleId , VariantId ,
5
+ child_from_source:: ChildFromSource , nameres:: ModuleSource , AstItemDef , EnumVariantId , ImplId ,
6
+ LocationCtx , ModuleId , TraitId , VariantId ,
7
7
} ;
8
8
use hir_expand:: { name:: AsName , AstId , MacroDefId , MacroDefKind } ;
9
9
use ra_syntax:: {
@@ -53,24 +53,18 @@ impl FromSource for Trait {
53
53
impl FromSource for Function {
54
54
type Ast = ast:: FnDef ;
55
55
fn from_source ( db : & ( impl DefDatabase + AstDatabase ) , src : InFile < Self :: Ast > ) -> Option < Self > {
56
- match Container :: find ( db, src. as_ref ( ) . map ( |it| it. syntax ( ) ) ) ? {
57
- Container :: Trait ( it) => it. id . child_from_source ( db, src) ,
58
- Container :: ImplBlock ( it) => it. id . child_from_source ( db, src) ,
59
- Container :: Module ( it) => it. id . child_from_source ( db, src) ,
60
- }
61
- . map ( Function :: from)
56
+ Container :: find ( db, src. as_ref ( ) . map ( |it| it. syntax ( ) ) ) ?
57
+ . child_from_source ( db, src)
58
+ . map ( Function :: from)
62
59
}
63
60
}
64
61
65
62
impl FromSource for Const {
66
63
type Ast = ast:: ConstDef ;
67
64
fn from_source ( db : & ( impl DefDatabase + AstDatabase ) , src : InFile < Self :: Ast > ) -> Option < Self > {
68
- match Container :: find ( db, src. as_ref ( ) . map ( |it| it. syntax ( ) ) ) ? {
69
- Container :: Trait ( it) => it. id . child_from_source ( db, src) ,
70
- Container :: ImplBlock ( it) => it. id . child_from_source ( db, src) ,
71
- Container :: Module ( it) => it. id . child_from_source ( db, src) ,
72
- }
73
- . map ( Const :: from)
65
+ Container :: find ( db, src. as_ref ( ) . map ( |it| it. syntax ( ) ) ) ?
66
+ . child_from_source ( db, src)
67
+ . map ( Const :: from)
74
68
}
75
69
}
76
70
impl FromSource for Static {
@@ -86,12 +80,9 @@ impl FromSource for Static {
86
80
impl FromSource for TypeAlias {
87
81
type Ast = ast:: TypeAliasDef ;
88
82
fn from_source ( db : & ( impl DefDatabase + AstDatabase ) , src : InFile < Self :: Ast > ) -> Option < Self > {
89
- match Container :: find ( db, src. as_ref ( ) . map ( |it| it. syntax ( ) ) ) ? {
90
- Container :: Trait ( it) => it. id . child_from_source ( db, src) ,
91
- Container :: ImplBlock ( it) => it. id . child_from_source ( db, src) ,
92
- Container :: Module ( it) => it. id . child_from_source ( db, src) ,
93
- }
94
- . map ( TypeAlias :: from)
83
+ Container :: find ( db, src. as_ref ( ) . map ( |it| it. syntax ( ) ) ) ?
84
+ . child_from_source ( db, src)
85
+ . map ( TypeAlias :: from)
95
86
}
96
87
}
97
88
@@ -263,3 +254,22 @@ impl Container {
263
254
Some ( Container :: Module ( c) )
264
255
}
265
256
}
257
+
258
+ impl < CHILD , SOURCE > ChildFromSource < CHILD , SOURCE > for Container
259
+ where
260
+ TraitId : ChildFromSource < CHILD , SOURCE > ,
261
+ ImplId : ChildFromSource < CHILD , SOURCE > ,
262
+ ModuleId : ChildFromSource < CHILD , SOURCE > ,
263
+ {
264
+ fn child_from_source (
265
+ & self ,
266
+ db : & impl DefDatabase ,
267
+ child_source : InFile < SOURCE > ,
268
+ ) -> Option < CHILD > {
269
+ match self {
270
+ Container :: Trait ( it) => it. id . child_from_source ( db, child_source) ,
271
+ Container :: ImplBlock ( it) => it. id . child_from_source ( db, child_source) ,
272
+ Container :: Module ( it) => it. id . child_from_source ( db, child_source) ,
273
+ }
274
+ }
275
+ }
0 commit comments