Skip to content

Commit ebe1e5e

Browse files
committed
Fix locations for Path and LiteralOrConstPat
1 parent 661a4e0 commit ebe1e5e

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

rust/extractor/src/translate.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ impl CrateTranslator<'_> {
113113
pat: &ra_ap_hir_def::hir::LiteralOrConst,
114114
body: &Body,
115115
source_map: &BodySourceMap,
116+
mut emit_location: impl FnMut(&mut CrateTranslator<'_>, trap::Label) -> (),
116117
) -> trap::Label {
117118
match pat {
118119
ra_ap_hir_def::hir::LiteralOrConst::Literal(_literal) => {
119120
let expr = self.trap.emit(generated::Literal { id: TrapId::Star });
120-
self.trap.emit(generated::LiteralPat {
121+
let label = self.trap.emit(generated::LiteralPat {
121122
id: TrapId::Star,
122123
expr,
123-
})
124+
});
125+
emit_location(self, label);
126+
label
124127
}
125128
ra_ap_hir_def::hir::LiteralOrConst::Const(inner) => {
126129
self.emit_pat(*inner, body, source_map)
@@ -257,6 +260,7 @@ impl CrateTranslator<'_> {
257260
ellipsis,
258261
} => {
259262
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));
260264
let flds = args
261265
.into_iter()
262266
.map(|arg| self.emit_record_field_pat(arg, body, source_map))
@@ -269,12 +273,16 @@ impl CrateTranslator<'_> {
269273
})
270274
}
271275
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+
});
278286
self.trap.emit(generated::RangePat {
279287
id: TrapId::Star,
280288
start,
@@ -304,6 +312,8 @@ impl CrateTranslator<'_> {
304312
}
305313
ra_ap_hir_def::hir::Pat::Path(path) => {
306314
let path = self.emit_path(path);
315+
self.emit_location_for_pat(path, pat_id, source_map);
316+
307317
self.trap.emit(generated::PathPat {
308318
id: TrapId::Star,
309319
path,
@@ -330,6 +340,8 @@ impl CrateTranslator<'_> {
330340
ellipsis,
331341
} => {
332342
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+
333345
let args = args
334346
.into_iter()
335347
.map(|arg| self.emit_pat(*arg, body, source_map))
@@ -447,6 +459,8 @@ impl CrateTranslator<'_> {
447459
}
448460
ra_ap_hir_def::hir::Expr::Path(path) => {
449461
let path = self.emit_path(path);
462+
self.emit_location_for_expr(path, expr_id, source_map);
463+
450464
self.trap.emit(generated::PathExpr {
451465
id: TrapId::Star,
452466
path,
@@ -652,6 +666,8 @@ impl CrateTranslator<'_> {
652666
is_assignee_expr,
653667
} => {
654668
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+
655671
let flds = fields
656672
.into_iter()
657673
.map(|field| self.emit_record_lit_field(field, body, source_map))
@@ -871,7 +887,7 @@ impl CrateTranslator<'_> {
871887
labels: &mut Vec<trap::Label>,
872888
) {
873889
let label = match id {
874-
ModuleDef::Module(_) => self
890+
ModuleDef::Module(_module) => self
875891
.trap
876892
.emit(generated::UnimplementedDeclaration { id: TrapId::Star }),
877893
ModuleDef::Function(function) => {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 0 |
22
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 0 |
33
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 0 |
4-
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 0 |
5-
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 0 |
6-
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 0 |
74
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 1 |
5+
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 2 |
6+
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 2 |
7+
| file://:0:0:0:0 | Module | getNumberOfDeclarations: | 2 |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
| file://:0:0:0:0 | Module | 0 | file://:0:0:0:0 | UnimplementedDeclaration |
2+
| file://:0:0:0:0 | Module | 0 | file://:0:0:0:0 | UnimplementedDeclaration |
3+
| file://:0:0:0:0 | Module | 0 | file://:0:0:0:0 | UnimplementedDeclaration |
14
| file://:0:0:0:0 | Module | 0 | gen_module.rs:6:5:6:19 | baz |
5+
| file://:0:0:0:0 | Module | 1 | file://:0:0:0:0 | UnimplementedDeclaration |
6+
| file://:0:0:0:0 | Module | 1 | file://:0:0:0:0 | UnimplementedDeclaration |
7+
| file://:0:0:0:0 | Module | 1 | file://:0:0:0:0 | UnimplementedDeclaration |

0 commit comments

Comments
 (0)