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