Skip to content

Commit 973d19b

Browse files
committed
Pass HirId in save_analysis.
1 parent 3947c9e commit 973d19b

File tree

2 files changed

+54
-40
lines changed

2 files changed

+54
-40
lines changed

compiler/rustc_save_analysis/src/dump_visitor.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'tcx> DumpVisitor<'tcx> {
128128
self.save_ctxt.lookup_def_id(ref_id)
129129
}
130130

131-
pub fn dump_crate_info(&mut self, name: &str, krate: &hir::Crate<'_>) {
131+
pub fn dump_crate_info(&mut self, name: &str, _krate: &hir::Crate<'_>) {
132132
let source_file = self.tcx.sess.local_crate_source_file.as_ref();
133133
let crate_root = source_file.map(|source_file| {
134134
let source_file = Path::new(source_file);
@@ -151,7 +151,7 @@ impl<'tcx> DumpVisitor<'tcx> {
151151
},
152152
crate_root: crate_root.unwrap_or_else(|| "<no source>".to_owned()),
153153
external_crates: self.save_ctxt.get_external_crates(),
154-
span: self.span_from_span(krate.item.span),
154+
span: self.span_from_span(self.tcx.hir().span(hir::CRATE_HIR_ID)),
155155
};
156156

157157
self.dumper.crate_prelude(data);
@@ -376,7 +376,7 @@ impl<'tcx> DumpVisitor<'tcx> {
376376
self.nest_typeck_results(map.local_def_id(item.hir_id), |v| {
377377
let body = map.body(body);
378378
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
379-
down_cast_data!(fn_data, DefData, item.span);
379+
down_cast_data!(fn_data, DefData, v.tcx.hir().span(item.hir_id));
380380
v.process_formals(body.params, &fn_data.qualname);
381381
v.process_generic_params(ty_params, &fn_data.qualname, item.hir_id);
382382

@@ -403,7 +403,7 @@ impl<'tcx> DumpVisitor<'tcx> {
403403
) {
404404
self.nest_typeck_results(self.tcx.hir().local_def_id(item.hir_id), |v| {
405405
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
406-
down_cast_data!(var_data, DefData, item.span);
406+
down_cast_data!(var_data, DefData, v.tcx.hir().span(item.hir_id));
407407
v.dumper.dump_def(&access_from!(v.save_ctxt, item, item.hir_id), var_data);
408408
}
409409
v.visit_ty(&typ);
@@ -463,7 +463,7 @@ impl<'tcx> DumpVisitor<'tcx> {
463463
def: &'tcx hir::VariantData<'tcx>,
464464
ty_params: &'tcx hir::Generics<'tcx>,
465465
) {
466-
debug!("process_struct {:?} {:?}", item, item.span);
466+
debug!("process_struct {:?} {:?}", item, self.tcx.hir().span(item.hir_id));
467467
let name = item.ident.to_string();
468468
let qualname = format!(
469469
"::{}",
@@ -539,7 +539,7 @@ impl<'tcx> DumpVisitor<'tcx> {
539539
None => return,
540540
Some(data) => data,
541541
};
542-
down_cast_data!(enum_data, DefData, item.span);
542+
down_cast_data!(enum_data, DefData, self.tcx.hir().span(item.hir_id));
543543

544544
let access = access_from!(self.save_ctxt, item, item.hir_id);
545545

@@ -640,12 +640,13 @@ impl<'tcx> DumpVisitor<'tcx> {
640640
impl_items: &'tcx [hir::ImplItemRef<'tcx>],
641641
) {
642642
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
643-
if !self.span.filter_generated(item.span) {
643+
let item_span = self.tcx.hir().span(item.hir_id);
644+
if !self.span.filter_generated(item_span) {
644645
if let super::Data::RelationData(rel, imp) = impl_data {
645646
self.dumper.dump_relation(rel);
646647
self.dumper.dump_impl(imp);
647648
} else {
648-
span_bug!(item.span, "unexpected data kind: {:?}", impl_data);
649+
span_bug!(item_span, "unexpected data kind: {:?}", impl_data);
649650
}
650651
}
651652
}
@@ -756,7 +757,7 @@ impl<'tcx> DumpVisitor<'tcx> {
756757
// `item` is the module in question, represented as an( item.
757758
fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) {
758759
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
759-
down_cast_data!(mod_data, DefData, item.span);
760+
down_cast_data!(mod_data, DefData, self.tcx.hir().span(item.hir_id));
760761
self.dumper.dump_def(&access_from!(self.save_ctxt, item, item.hir_id), mod_data);
761762
}
762763
}
@@ -822,8 +823,8 @@ impl<'tcx> DumpVisitor<'tcx> {
822823
if let hir::QPath::Resolved(_, path) = path {
823824
self.write_sub_paths_truncated(path);
824825
}
825-
down_cast_data!(struct_lit_data, RefData, ex.span);
826-
if !generated_code(ex.span) {
826+
down_cast_data!(struct_lit_data, RefData, self.tcx.hir().span(ex.hir_id));
827+
if !generated_code(self.tcx.hir().span(ex.hir_id)) {
827828
self.dumper.dump_ref(struct_lit_data);
828829
}
829830

@@ -847,10 +848,11 @@ impl<'tcx> DumpVisitor<'tcx> {
847848
seg: &'tcx hir::PathSegment<'tcx>,
848849
args: &'tcx [hir::Expr<'tcx>],
849850
) {
850-
debug!("process_method_call {:?} {:?}", ex, ex.span);
851+
let ex_span = self.tcx.hir().span(ex.hir_id);
852+
debug!("process_method_call {:?} {:?}", ex, ex_span);
851853
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
852-
down_cast_data!(mcd, RefData, ex.span);
853-
if !generated_code(ex.span) {
854+
down_cast_data!(mcd, RefData, ex_span);
855+
if !generated_code(ex_span) {
854856
self.dumper.dump_ref(mcd);
855857
}
856858
}
@@ -974,7 +976,9 @@ impl<'tcx> DumpVisitor<'tcx> {
974976
/// If the span is not macro-generated, do nothing, else use callee and
975977
/// callsite spans to record macro definition and use data, using the
976978
/// mac_uses and mac_defs sets to prevent multiples.
977-
fn process_macro_use(&mut self, _span: Span) {
979+
fn process_macro_use(&mut self, _hir_id: hir::HirId) {
980+
//let span = self.tcx.hir().span(_hir_id);
981+
//
978982
// FIXME if we're not dumping the defs (see below), there is no point
979983
// dumping refs either.
980984
// let source_span = span.source_callsite();
@@ -1011,8 +1015,8 @@ impl<'tcx> DumpVisitor<'tcx> {
10111015
}
10121016

10131017
fn process_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>, trait_id: DefId) {
1014-
self.process_macro_use(trait_item.span);
1015-
let vis_span = trait_item.span.shrink_to_lo();
1018+
self.process_macro_use(trait_item.hir_id);
1019+
let vis_span = self.tcx.hir().span(trait_item.hir_id).shrink_to_lo();
10161020
match trait_item.kind {
10171021
hir::TraitItemKind::Const(ref ty, body) => {
10181022
let body = body.map(|b| &self.tcx.hir().body(b).value);
@@ -1038,7 +1042,7 @@ impl<'tcx> DumpVisitor<'tcx> {
10381042
trait_item.ident,
10391043
&trait_item.generics,
10401044
&respan,
1041-
trait_item.span,
1045+
self.tcx.hir().span(trait_item.hir_id),
10421046
);
10431047
}
10441048
hir::TraitItemKind::Type(ref bounds, ref default_ty) => {
@@ -1062,7 +1066,7 @@ impl<'tcx> DumpVisitor<'tcx> {
10621066
span,
10631067
name,
10641068
qualname,
1065-
value: self.span.snippet(trait_item.span),
1069+
value: self.span.snippet(self.tcx.hir().span(trait_item.hir_id)),
10661070
parent: Some(id_from_def_id(trait_id)),
10671071
children: vec![],
10681072
decl_id: None,
@@ -1090,7 +1094,7 @@ impl<'tcx> DumpVisitor<'tcx> {
10901094
}
10911095

10921096
fn process_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>, impl_id: DefId) {
1093-
self.process_macro_use(impl_item.span);
1097+
self.process_macro_use(impl_item.hir_id);
10941098
match impl_item.kind {
10951099
hir::ImplItemKind::Const(ref ty, body) => {
10961100
let body = self.tcx.hir().body(body);
@@ -1112,7 +1116,7 @@ impl<'tcx> DumpVisitor<'tcx> {
11121116
impl_item.ident,
11131117
&impl_item.generics,
11141118
&impl_item.vis,
1115-
impl_item.span,
1119+
self.tcx.hir().span(impl_item.hir_id),
11161120
);
11171121
}
11181122
hir::ImplItemKind::TyAlias(ref ty) => {
@@ -1130,7 +1134,9 @@ impl<'tcx> DumpVisitor<'tcx> {
11301134
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
11311135

11321136
let sm = self.tcx.sess.source_map();
1133-
let filename = sm.span_to_filename(krate.item.span);
1137+
let span = self.tcx.hir().span(hir::CRATE_HIR_ID);
1138+
let filename = sm.span_to_filename(span);
1139+
let span = self.span_from_span(span);
11341140
let data_id = id_from_hir_id(id, &self.save_ctxt);
11351141
let children = krate
11361142
.item
@@ -1139,7 +1145,6 @@ impl<'tcx> DumpVisitor<'tcx> {
11391145
.iter()
11401146
.map(|i| id_from_hir_id(i.id, &self.save_ctxt))
11411147
.collect();
1142-
let span = self.span_from_span(krate.item.span);
11431148

11441149
self.dumper.dump_def(
11451150
&Access { public: true, reachable: true },
@@ -1181,7 +1186,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
11811186
}
11821187

11831188
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
1184-
self.process_macro_use(item.span);
1189+
self.process_macro_use(item.hir_id);
11851190
match item.kind {
11861191
hir::ItemKind::Use(path, hir::UseKind::Single) => {
11871192
let sub_span = path.segments.last().unwrap().ident.span;
@@ -1219,8 +1224,9 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
12191224

12201225
// Otherwise it's a span with wrong macro expansion info, which
12211226
// we don't want to track anyway, since it's probably macro-internal `use`
1222-
if let Some(sub_span) = self.span.sub_span_of_star(item.span) {
1223-
if !self.span.filter_generated(item.span) {
1227+
let item_span = self.tcx.hir().span(item.hir_id);
1228+
if let Some(sub_span) = self.span.sub_span_of_star(item_span) {
1229+
if !self.span.filter_generated(item_span) {
12241230
let access = access_from!(self.save_ctxt, item, item.hir_id);
12251231
let span = self.span_from_span(sub_span);
12261232
let parent = self
@@ -1361,10 +1367,10 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
13611367
}
13621368

13631369
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
1364-
self.process_macro_use(t.span);
1370+
self.process_macro_use(t.hir_id);
13651371
match t.kind {
13661372
hir::TyKind::Path(ref path) => {
1367-
if generated_code(t.span) {
1373+
if generated_code(self.tcx.hir().span(t.hir_id)) {
13681374
return;
13691375
}
13701376

@@ -1402,7 +1408,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
14021408

14031409
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
14041410
debug!("visit_expr {:?}", ex.kind);
1405-
self.process_macro_use(ex.span);
1411+
self.process_macro_use(ex.hir_id);
14061412
match ex.kind {
14071413
hir::ExprKind::Struct(ref path, ref fields, ref rest) => {
14081414
let hir_expr = self.save_ctxt.tcx.hir().expect_expr(ex.hir_id);
@@ -1423,8 +1429,9 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
14231429
self.visit_expr(&sub_ex);
14241430

14251431
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
1426-
down_cast_data!(field_data, RefData, ex.span);
1427-
if !generated_code(ex.span) {
1432+
let ex_span = self.tcx.hir().span(ex.hir_id);
1433+
down_cast_data!(field_data, RefData, ex_span);
1434+
if !generated_code(ex_span) {
14281435
self.dumper.dump_ref(field_data);
14291436
}
14301437
}
@@ -1463,7 +1470,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
14631470
}
14641471

14651472
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
1466-
self.process_macro_use(p.span);
1473+
self.process_macro_use(p.hir_id);
14671474
self.process_pat(p);
14681475
}
14691476

@@ -1480,12 +1487,12 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
14801487
}
14811488

14821489
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
1483-
self.process_macro_use(s.span);
1490+
self.process_macro_use(s.hir_id);
14841491
intravisit::walk_stmt(self, s)
14851492
}
14861493

14871494
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
1488-
self.process_macro_use(l.span);
1495+
self.process_macro_use(l.hir_id);
14891496
self.process_var_decl(&l.pat);
14901497

14911498
// Just walk the initialiser and type (don't want to walk the pattern again).
@@ -1499,7 +1506,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
14991506
match item.kind {
15001507
hir::ForeignItemKind::Fn(decl, _, ref generics) => {
15011508
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
1502-
down_cast_data!(fn_data, DefData, item.span);
1509+
down_cast_data!(fn_data, DefData, self.tcx.hir().span(item.hir_id));
15031510

15041511
self.process_generic_params(generics, &fn_data.qualname, item.hir_id);
15051512
self.dumper.dump_def(&access, fn_data);
@@ -1515,15 +1522,15 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
15151522
}
15161523
hir::ForeignItemKind::Static(ref ty, _) => {
15171524
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
1518-
down_cast_data!(var_data, DefData, item.span);
1525+
down_cast_data!(var_data, DefData, self.tcx.hir().span(item.hir_id));
15191526
self.dumper.dump_def(&access, var_data);
15201527
}
15211528

15221529
self.visit_ty(ty);
15231530
}
15241531
hir::ForeignItemKind::Type => {
15251532
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
1526-
down_cast_data!(var_data, DefData, item.span);
1533+
down_cast_data!(var_data, DefData, self.tcx.hir().span(item.hir_id));
15271534
self.dumper.dump_def(&access, var_data);
15281535
}
15291536
}

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,13 @@ impl<'tcx> SaveContext<'tcx> {
301301
let name = item.ident.to_string();
302302
let qualname = format!("::{}", self.tcx.def_path_str(def_id));
303303
filter!(self.span_utils, item.ident.span);
304-
let value =
305-
enum_def_to_string(def, generics, item.ident.name, item.span, &item.vis);
304+
let value = enum_def_to_string(
305+
def,
306+
generics,
307+
item.ident.name,
308+
self.tcx.hir().span(item.hir_id),
309+
&item.vis,
310+
);
306311
Some(Data::DefData(Def {
307312
kind: DefKind::Enum,
308313
id: id_from_def_id(def_id),
@@ -892,7 +897,9 @@ impl<'l> Visitor<'l> for PathCollector<'l> {
892897
hir::PatKind::Binding(bm, _, ident, _) => {
893898
debug!(
894899
"PathCollector, visit ident in pat {}: {:?} {:?}",
895-
ident, p.span, ident.span
900+
ident,
901+
self.tcx.hir().span(p.hir_id),
902+
ident.span
896903
);
897904
let immut = match bm {
898905
// Even if the ref is mut, you can't change the ref, only

0 commit comments

Comments
 (0)