@@ -40,6 +40,28 @@ struct Extractor<'a> {
40
40
steps : Vec < ExtractionStep > ,
41
41
}
42
42
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
+ . location_label ( codeql_extractor:: trap:: Location {
51
+ file_label,
52
+ start_line : 0 ,
53
+ start_column : 0 ,
54
+ end_line : 0 ,
55
+ end_column : 0 ,
56
+ } ) ;
57
+ if fresh {
58
+ panic ! ( "empty location not populated" ) ;
59
+ }
60
+ trap. writer . add_tuple (
61
+ "locatable_locations" ,
62
+ vec ! [ entity_label. into( ) , location_label. into( ) ] ,
63
+ ) ;
64
+ }
43
65
fn emit_hir_path (
44
66
trap : & mut TrapFile ,
45
67
path : & ra_ap_hir_def:: path:: Path ,
@@ -49,7 +71,9 @@ fn emit_hir_path(
49
71
id : trap:: TrapId :: Star ,
50
72
text : Some ( segment. name . as_str ( ) . to_owned ( ) ) ,
51
73
} ) ;
52
- trap. emit ( generated:: PathSegment {
74
+ emit_empty_location ( trap, name_ref) ;
75
+
76
+ let label = trap. emit ( generated:: PathSegment {
53
77
id : trap:: TrapId :: Star ,
54
78
generic_arg_list : None ,
55
79
name_ref : Some ( name_ref) ,
@@ -58,17 +82,21 @@ fn emit_hir_path(
58
82
ret_type : None ,
59
83
return_type_syntax : None ,
60
84
type_repr : None ,
61
- } )
85
+ } ) ;
86
+ emit_empty_location ( trap, label) ;
87
+ label
62
88
} ) ;
63
89
let qualifier = path
64
90
. mod_path ( )
65
91
. filter ( |p| !p. segments ( ) . is_empty ( ) )
66
92
. and_then ( |_| path. qualifier ( ) . as_ref ( ) . map ( |p| emit_hir_path ( trap, p) ) ) ;
67
- trap. emit ( generated:: Path {
93
+ let label = trap. emit ( generated:: Path {
68
94
id : trap:: TrapId :: Star ,
69
95
qualifier,
70
96
part,
71
- } )
97
+ } ) ;
98
+ emit_empty_location ( trap, label) ;
99
+ label
72
100
}
73
101
fn emit_hir_fn (
74
102
trap : & mut TrapFile ,
@@ -85,46 +113,55 @@ fn emit_hir_fn(
85
113
id : trap:: TrapId :: Star ,
86
114
type_repr : ret,
87
115
} ) ;
116
+ emit_empty_location ( trap, ret) ;
117
+
88
118
let self_param = self_type. map ( |ty| {
89
119
let type_repr = emit_hir_typeref ( trap, ty) ;
90
- trap. emit ( generated:: SelfParam {
120
+ let label = trap. emit ( generated:: SelfParam {
91
121
id : trap:: TrapId :: Star ,
92
122
attrs : vec ! [ ] ,
93
123
type_repr,
94
124
is_mut : false ,
95
125
lifetime : None ,
96
126
name : None ,
97
- } )
127
+ } ) ;
128
+ emit_empty_location ( trap, label) ;
129
+ label
98
130
} ) ;
99
131
let params = params
100
132
. iter ( )
101
133
. map ( |t| {
102
134
let type_repr = emit_hir_typeref ( trap, t) ;
103
- trap. emit ( generated:: Param {
135
+ let label = trap. emit ( generated:: Param {
104
136
id : trap:: TrapId :: Star ,
105
137
attrs : vec ! [ ] ,
106
138
type_repr,
107
139
pat : None ,
108
- } )
140
+ } ) ;
141
+ emit_empty_location ( trap, label) ;
142
+ label
109
143
} )
110
144
. collect ( ) ;
111
145
let params = trap. emit ( generated:: ParamList {
112
146
id : trap:: TrapId :: Star ,
113
147
params,
114
148
self_param,
115
149
} ) ;
116
- trap. emit ( generated:: FnPtrTypeRepr {
150
+ emit_empty_location ( trap, params) ;
151
+ let label = trap. emit ( generated:: FnPtrTypeRepr {
117
152
id : trap:: TrapId :: Star ,
118
153
abi : None ,
119
154
is_async,
120
155
is_const,
121
156
is_unsafe,
122
157
param_list : Some ( params) ,
123
158
ret_type : Some ( ret) ,
124
- } )
159
+ } ) ;
160
+ emit_empty_location ( trap, label) ;
161
+ label
125
162
}
126
163
fn emit_hir_typeref ( trap : & mut TrapFile , ty : & TypeRef ) -> Option < trap:: Label < generated:: TypeRepr > > {
127
- match ty {
164
+ let maybe_label = match ty {
128
165
TypeRef :: Never => Some (
129
166
trap. emit ( generated:: NeverTypeRepr {
130
167
id : trap:: TrapId :: Star ,
@@ -234,7 +271,10 @@ fn emit_hir_typeref(trap: &mut TrapFile, ty: &TypeRef) -> Option<trap::Label<gen
234
271
TypeRef :: DynTrait ( _) => None , // TODO handle dyn
235
272
TypeRef :: Macro ( _) => None ,
236
273
TypeRef :: Error => None ,
237
- }
274
+ } ;
275
+ maybe_label. inspect ( |& label| {
276
+ emit_empty_location ( trap, label) ;
277
+ } )
238
278
}
239
279
240
280
fn emit_variant_data (
0 commit comments