@@ -40,6 +40,22 @@ struct Extractor<'a> {
4040 steps : Vec < ExtractionStep > ,
4141}
4242
43+ fn emit_empty_location < E : trap:: TrapClass > ( trap : & mut TrapFile , entity_label : trap:: Label < E > ) {
44+ let ( file_label, fresh) = trap. writer . global_id ( "empty;sourcefile" ) ;
45+ if fresh {
46+ panic ! ( "empty file not populated" ) ;
47+ }
48+ let ( location_label, fresh) = trap
49+ . writer
50+ . global_id ( & format ! ( "loc,{{{}}},{},{},{},{}" , file_label, 0 , 0 , 0 , 0 ) ) ;
51+ if fresh {
52+ panic ! ( "empty location not populated" ) ;
53+ }
54+ trap. writer . add_tuple (
55+ "locatable_locations" ,
56+ vec ! [ entity_label. into( ) , location_label. into( ) ] ,
57+ ) ;
58+ }
4359fn emit_hir_path (
4460 trap : & mut TrapFile ,
4561 path : & ra_ap_hir_def:: path:: Path ,
@@ -49,7 +65,9 @@ fn emit_hir_path(
4965 id : trap:: TrapId :: Star ,
5066 text : Some ( segment. name . as_str ( ) . to_owned ( ) ) ,
5167 } ) ;
52- trap. emit ( generated:: PathSegment {
68+ emit_empty_location ( trap, name_ref) ;
69+
70+ let label = trap. emit ( generated:: PathSegment {
5371 id : trap:: TrapId :: Star ,
5472 generic_arg_list : None ,
5573 name_ref : Some ( name_ref) ,
@@ -58,17 +76,21 @@ fn emit_hir_path(
5876 ret_type : None ,
5977 return_type_syntax : None ,
6078 type_repr : None ,
61- } )
79+ } ) ;
80+ emit_empty_location ( trap, label) ;
81+ label
6282 } ) ;
6383 let qualifier = path
6484 . mod_path ( )
6585 . filter ( |p| !p. segments ( ) . is_empty ( ) )
6686 . and_then ( |_| path. qualifier ( ) . as_ref ( ) . map ( |p| emit_hir_path ( trap, p) ) ) ;
67- trap. emit ( generated:: Path {
87+ let label = trap. emit ( generated:: Path {
6888 id : trap:: TrapId :: Star ,
6989 qualifier,
7090 part,
71- } )
91+ } ) ;
92+ emit_empty_location ( trap, label) ;
93+ label
7294}
7395fn emit_hir_fn (
7496 trap : & mut TrapFile ,
@@ -85,46 +107,55 @@ fn emit_hir_fn(
85107 id : trap:: TrapId :: Star ,
86108 type_repr : ret,
87109 } ) ;
110+ emit_empty_location ( trap, ret) ;
111+
88112 let self_param = self_type. map ( |ty| {
89113 let type_repr = emit_hir_typeref ( trap, ty) ;
90- trap. emit ( generated:: SelfParam {
114+ let label = trap. emit ( generated:: SelfParam {
91115 id : trap:: TrapId :: Star ,
92116 attrs : vec ! [ ] ,
93117 type_repr,
94118 is_mut : false ,
95119 lifetime : None ,
96120 name : None ,
97- } )
121+ } ) ;
122+ emit_empty_location ( trap, label) ;
123+ label
98124 } ) ;
99125 let params = params
100126 . iter ( )
101127 . map ( |t| {
102128 let type_repr = emit_hir_typeref ( trap, t) ;
103- trap. emit ( generated:: Param {
129+ let label = trap. emit ( generated:: Param {
104130 id : trap:: TrapId :: Star ,
105131 attrs : vec ! [ ] ,
106132 type_repr,
107133 pat : None ,
108- } )
134+ } ) ;
135+ emit_empty_location ( trap, label) ;
136+ label
109137 } )
110138 . collect ( ) ;
111139 let params = trap. emit ( generated:: ParamList {
112140 id : trap:: TrapId :: Star ,
113141 params,
114142 self_param,
115143 } ) ;
116- trap. emit ( generated:: FnPtrTypeRepr {
144+ emit_empty_location ( trap, params) ;
145+ let label = trap. emit ( generated:: FnPtrTypeRepr {
117146 id : trap:: TrapId :: Star ,
118147 abi : None ,
119148 is_async,
120149 is_const,
121150 is_unsafe,
122151 param_list : Some ( params) ,
123152 ret_type : Some ( ret) ,
124- } )
153+ } ) ;
154+ emit_empty_location ( trap, label) ;
155+ label
125156}
126157fn emit_hir_typeref ( trap : & mut TrapFile , ty : & TypeRef ) -> Option < trap:: Label < generated:: TypeRepr > > {
127- match ty {
158+ let maybe_label = match ty {
128159 TypeRef :: Never => Some (
129160 trap. emit ( generated:: NeverTypeRepr {
130161 id : trap:: TrapId :: Star ,
@@ -234,7 +265,10 @@ fn emit_hir_typeref(trap: &mut TrapFile, ty: &TypeRef) -> Option<trap::Label<gen
234265 TypeRef :: DynTrait ( _) => None , // TODO handle dyn
235266 TypeRef :: Macro ( _) => None ,
236267 TypeRef :: Error => None ,
237- }
268+ } ;
269+ maybe_label. inspect ( |& label| {
270+ emit_empty_location ( trap, label) ;
271+ } )
238272}
239273
240274fn emit_variant_data (
0 commit comments