@@ -113,14 +113,17 @@ impl CrateTranslator<'_> {
113
113
pat : & ra_ap_hir_def:: hir:: LiteralOrConst ,
114
114
body : & Body ,
115
115
source_map : & BodySourceMap ,
116
+ mut emit_location : impl FnMut ( & mut CrateTranslator < ' _ > , trap:: Label ) -> ( ) ,
116
117
) -> trap:: Label {
117
118
match pat {
118
119
ra_ap_hir_def:: hir:: LiteralOrConst :: Literal ( _literal) => {
119
120
let expr = self . trap . emit ( generated:: Literal { id : TrapId :: Star } ) ;
120
- self . trap . emit ( generated:: LiteralPat {
121
+ let label = self . trap . emit ( generated:: LiteralPat {
121
122
id : TrapId :: Star ,
122
123
expr,
123
- } )
124
+ } ) ;
125
+ emit_location ( self , label) ;
126
+ label
124
127
}
125
128
ra_ap_hir_def:: hir:: LiteralOrConst :: Const ( inner) => {
126
129
self . emit_pat ( * inner, body, source_map)
@@ -257,6 +260,7 @@ impl CrateTranslator<'_> {
257
260
ellipsis,
258
261
} => {
259
262
let path = path. as_ref ( ) . map ( |path| self . emit_path ( path) ) ;
263
+ path. map ( |p| self . emit_location_for_pat ( p, pat_id, source_map) ) ;
260
264
let flds = args
261
265
. into_iter ( )
262
266
. map ( |arg| self . emit_record_field_pat ( arg, body, source_map) )
@@ -269,12 +273,16 @@ impl CrateTranslator<'_> {
269
273
} )
270
274
}
271
275
ra_ap_hir_def:: hir:: Pat :: Range { start, end } => {
272
- let start = start
273
- . as_ref ( )
274
- . map ( |x| self . emit_literal_or_const_pat ( x, body, source_map) ) ;
275
- let end = end
276
- . as_ref ( )
277
- . map ( |x| self . emit_literal_or_const_pat ( x, body, source_map) ) ;
276
+ let emit_location_for_const = |trans : & mut CrateTranslator < ' _ > , label| {
277
+ trans. emit_location_for_pat ( label, pat_id, source_map)
278
+ } ;
279
+ let start = start. as_ref ( ) . map ( |x| {
280
+ self . emit_literal_or_const_pat ( x, body, source_map, emit_location_for_const)
281
+ } ) ;
282
+
283
+ let end = end. as_ref ( ) . map ( |x| {
284
+ self . emit_literal_or_const_pat ( x, body, source_map, emit_location_for_const)
285
+ } ) ;
278
286
self . trap . emit ( generated:: RangePat {
279
287
id : TrapId :: Star ,
280
288
start,
@@ -304,6 +312,8 @@ impl CrateTranslator<'_> {
304
312
}
305
313
ra_ap_hir_def:: hir:: Pat :: Path ( path) => {
306
314
let path = self . emit_path ( path) ;
315
+ self . emit_location_for_pat ( path, pat_id, source_map) ;
316
+
307
317
self . trap . emit ( generated:: PathPat {
308
318
id : TrapId :: Star ,
309
319
path,
@@ -330,6 +340,8 @@ impl CrateTranslator<'_> {
330
340
ellipsis,
331
341
} => {
332
342
let path = path. as_ref ( ) . map ( |path| self . emit_path ( path) ) ;
343
+ path. map ( |p| self . emit_location_for_pat ( p, pat_id, source_map) ) ;
344
+
333
345
let args = args
334
346
. into_iter ( )
335
347
. map ( |arg| self . emit_pat ( * arg, body, source_map) )
@@ -447,6 +459,8 @@ impl CrateTranslator<'_> {
447
459
}
448
460
ra_ap_hir_def:: hir:: Expr :: Path ( path) => {
449
461
let path = self . emit_path ( path) ;
462
+ self . emit_location_for_expr ( path, expr_id, source_map) ;
463
+
450
464
self . trap . emit ( generated:: PathExpr {
451
465
id : TrapId :: Star ,
452
466
path,
@@ -652,6 +666,8 @@ impl CrateTranslator<'_> {
652
666
is_assignee_expr,
653
667
} => {
654
668
let path = path. as_ref ( ) . map ( |path| self . emit_path ( path) ) ;
669
+ path. map ( |p| self . emit_location_for_expr ( p, expr_id, source_map) ) ;
670
+
655
671
let flds = fields
656
672
. into_iter ( )
657
673
. map ( |field| self . emit_record_lit_field ( field, body, source_map) )
@@ -871,7 +887,7 @@ impl CrateTranslator<'_> {
871
887
labels : & mut Vec < trap:: Label > ,
872
888
) {
873
889
let label = match id {
874
- ModuleDef :: Module ( _ ) => self
890
+ ModuleDef :: Module ( _module ) => self
875
891
. trap
876
892
. emit ( generated:: UnimplementedDeclaration { id : TrapId :: Star } ) ,
877
893
ModuleDef :: Function ( function) => {
0 commit comments