Skip to content

Commit 61402a5

Browse files
committed
Pass HirId in save_analysis.
1 parent ff32863 commit 61402a5

File tree

2 files changed

+54
-40
lines changed

2 files changed

+54
-40
lines changed

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'l, 'tcx> DumpVisitor<'l, '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<'l, 'tcx> DumpVisitor<'l, '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);
@@ -366,7 +366,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
366366
self.nest_tables(map.local_def_id(item.hir_id), |v| {
367367
let body = map.body(body);
368368
if let Some(fn_data) = v.save_ctxt.get_item_data(item) {
369-
down_cast_data!(fn_data, DefData, item.span);
369+
down_cast_data!(fn_data, DefData, v.tcx.hir().span(item.hir_id));
370370
v.process_formals(body.params, &fn_data.qualname);
371371
v.process_generic_params(ty_params, &fn_data.qualname, item.hir_id);
372372

@@ -393,7 +393,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
393393
) {
394394
self.nest_tables(self.tcx.hir().local_def_id(item.hir_id), |v| {
395395
if let Some(var_data) = v.save_ctxt.get_item_data(item) {
396-
down_cast_data!(var_data, DefData, item.span);
396+
down_cast_data!(var_data, DefData, v.tcx.hir().span(item.hir_id));
397397
v.dumper.dump_def(&access_from!(v.save_ctxt, item, item.hir_id), var_data);
398398
}
399399
v.visit_ty(&typ);
@@ -453,7 +453,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
453453
def: &'tcx hir::VariantData<'tcx>,
454454
ty_params: &'tcx hir::Generics<'tcx>,
455455
) {
456-
debug!("process_struct {:?} {:?}", item, item.span);
456+
debug!("process_struct {:?} {:?}", item, self.tcx.hir().span(item.hir_id));
457457
let name = item.ident.to_string();
458458
let qualname = format!(
459459
"::{}",
@@ -529,7 +529,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
529529
None => return,
530530
Some(data) => data,
531531
};
532-
down_cast_data!(enum_data, DefData, item.span);
532+
down_cast_data!(enum_data, DefData, self.tcx.hir().span(item.hir_id));
533533

534534
let access = access_from!(self.save_ctxt, item, item.hir_id);
535535

@@ -630,12 +630,13 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
630630
impl_items: &'tcx [hir::ImplItemRef<'tcx>],
631631
) {
632632
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
633-
if !self.span.filter_generated(item.span) {
633+
let item_span = self.tcx.hir().span(item.hir_id);
634+
if !self.span.filter_generated(item_span) {
634635
if let super::Data::RelationData(rel, imp) = impl_data {
635636
self.dumper.dump_relation(rel);
636637
self.dumper.dump_impl(imp);
637638
} else {
638-
span_bug!(item.span, "unexpected data kind: {:?}", impl_data);
639+
span_bug!(item_span, "unexpected data kind: {:?}", impl_data);
639640
}
640641
}
641642
}
@@ -742,7 +743,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
742743
// `item` is the module in question, represented as an( item.
743744
fn process_mod(&mut self, item: &'tcx hir::Item<'tcx>) {
744745
if let Some(mod_data) = self.save_ctxt.get_item_data(item) {
745-
down_cast_data!(mod_data, DefData, item.span);
746+
down_cast_data!(mod_data, DefData, self.tcx.hir().span(item.hir_id));
746747
self.dumper.dump_def(&access_from!(self.save_ctxt, item, item.hir_id), mod_data);
747748
}
748749
}
@@ -811,8 +812,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
811812
if let hir::QPath::Resolved(_, path) = path {
812813
self.write_sub_paths_truncated(path);
813814
}
814-
down_cast_data!(struct_lit_data, RefData, ex.span);
815-
if !generated_code(ex.span) {
815+
down_cast_data!(struct_lit_data, RefData, self.tcx.hir().span(ex.hir_id));
816+
if !generated_code(self.tcx.hir().span(ex.hir_id)) {
816817
self.dumper.dump_ref(struct_lit_data);
817818
}
818819

@@ -834,10 +835,11 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
834835
seg: &'tcx hir::PathSegment<'tcx>,
835836
args: &'tcx [hir::Expr<'tcx>],
836837
) {
837-
debug!("process_method_call {:?} {:?}", ex, ex.span);
838+
let ex_span = self.tcx.hir().span(ex.hir_id);
839+
debug!("process_method_call {:?} {:?}", ex, ex_span);
838840
if let Some(mcd) = self.save_ctxt.get_expr_data(ex) {
839-
down_cast_data!(mcd, RefData, ex.span);
840-
if !generated_code(ex.span) {
841+
down_cast_data!(mcd, RefData, ex_span);
842+
if !generated_code(ex_span) {
841843
self.dumper.dump_ref(mcd);
842844
}
843845
}
@@ -961,7 +963,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
961963
/// If the span is not macro-generated, do nothing, else use callee and
962964
/// callsite spans to record macro definition and use data, using the
963965
/// mac_uses and mac_defs sets to prevent multiples.
964-
fn process_macro_use(&mut self, _span: Span) {
966+
fn process_macro_use(&mut self, _hir_id: hir::HirId) {
967+
//let span = self.tcx.hir().span(_hir_id);
968+
//
965969
// FIXME if we're not dumping the defs (see below), there is no point
966970
// dumping refs either.
967971
// let source_span = span.source_callsite();
@@ -998,8 +1002,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
9981002
}
9991003

10001004
fn process_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>, trait_id: DefId) {
1001-
self.process_macro_use(trait_item.span);
1002-
let vis_span = trait_item.span.shrink_to_lo();
1005+
self.process_macro_use(trait_item.hir_id);
1006+
let vis_span = self.tcx.hir().span(trait_item.hir_id).shrink_to_lo();
10031007
match trait_item.kind {
10041008
hir::TraitItemKind::Const(ref ty, body) => {
10051009
let body = body.map(|b| &self.tcx.hir().body(b).value);
@@ -1025,7 +1029,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
10251029
trait_item.ident,
10261030
&trait_item.generics,
10271031
&respan,
1028-
trait_item.span,
1032+
self.tcx.hir().span(trait_item.hir_id),
10291033
);
10301034
}
10311035
hir::TraitItemKind::Type(ref bounds, ref default_ty) => {
@@ -1049,7 +1053,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
10491053
span,
10501054
name,
10511055
qualname,
1052-
value: self.span.snippet(trait_item.span),
1056+
value: self.span.snippet(self.tcx.hir().span(trait_item.hir_id)),
10531057
parent: Some(id_from_def_id(trait_id)),
10541058
children: vec![],
10551059
decl_id: None,
@@ -1077,7 +1081,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
10771081
}
10781082

10791083
fn process_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>, impl_id: DefId) {
1080-
self.process_macro_use(impl_item.span);
1084+
self.process_macro_use(impl_item.hir_id);
10811085
match impl_item.kind {
10821086
hir::ImplItemKind::Const(ref ty, body) => {
10831087
let body = self.tcx.hir().body(body);
@@ -1099,7 +1103,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
10991103
impl_item.ident,
11001104
&impl_item.generics,
11011105
&impl_item.vis,
1102-
impl_item.span,
1106+
self.tcx.hir().span(impl_item.hir_id),
11031107
);
11041108
}
11051109
hir::ImplItemKind::TyAlias(ref ty) => {
@@ -1117,7 +1121,9 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11171121
format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id(id).to_def_id()));
11181122

11191123
let sm = self.tcx.sess.source_map();
1120-
let filename = sm.span_to_filename(krate.item.span);
1124+
let span = self.tcx.hir().span(hir::CRATE_HIR_ID);
1125+
let filename = sm.span_to_filename(span);
1126+
let span = self.span_from_span(span);
11211127
let data_id = id_from_hir_id(id, &self.save_ctxt);
11221128
let children = krate
11231129
.item
@@ -1126,7 +1132,6 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
11261132
.iter()
11271133
.map(|i| id_from_hir_id(i.id, &self.save_ctxt))
11281134
.collect();
1129-
let span = self.span_from_span(krate.item.span);
11301135

11311136
self.dumper.dump_def(
11321137
&Access { public: true, reachable: true },
@@ -1168,7 +1173,7 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
11681173
}
11691174

11701175
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
1171-
self.process_macro_use(item.span);
1176+
self.process_macro_use(item.hir_id);
11721177
match item.kind {
11731178
hir::ItemKind::Use(path, hir::UseKind::Single) => {
11741179
let sub_span = path.segments.last().unwrap().ident.span;
@@ -1206,10 +1211,11 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
12061211

12071212
// Otherwise it's a span with wrong macro expansion info, which
12081213
// we don't want to track anyway, since it's probably macro-internal `use`
1214+
let item_span = self.tcx.hir().span(item.hir_id);
12091215
if let Some(sub_span) =
1210-
self.span.sub_span_of_token(item.span, token::BinOp(token::Star))
1216+
self.span.sub_span_of_token(item_span, token::BinOp(token::Star))
12111217
{
1212-
if !self.span.filter_generated(item.span) {
1218+
if !self.span.filter_generated(item_span) {
12131219
let access = access_from!(self.save_ctxt, item, item.hir_id);
12141220
let span = self.span_from_span(sub_span);
12151221
let parent = self
@@ -1347,10 +1353,10 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
13471353
}
13481354

13491355
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
1350-
self.process_macro_use(t.span);
1356+
self.process_macro_use(t.hir_id);
13511357
match t.kind {
13521358
hir::TyKind::Path(ref path) => {
1353-
if generated_code(t.span) {
1359+
if generated_code(self.tcx.hir().span(t.hir_id)) {
13541360
return;
13551361
}
13561362

@@ -1389,7 +1395,7 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
13891395

13901396
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
13911397
debug!("visit_expr {:?}", ex.kind);
1392-
self.process_macro_use(ex.span);
1398+
self.process_macro_use(ex.hir_id);
13931399
match ex.kind {
13941400
hir::ExprKind::Struct(ref path, ref fields, ref base) => {
13951401
let hir_expr = self.save_ctxt.tcx.hir().expect_expr(ex.hir_id);
@@ -1410,8 +1416,9 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
14101416
self.visit_expr(&sub_ex);
14111417

14121418
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
1413-
down_cast_data!(field_data, RefData, ex.span);
1414-
if !generated_code(ex.span) {
1419+
let ex_span = self.tcx.hir().span(ex.hir_id);
1420+
down_cast_data!(field_data, RefData, ex_span);
1421+
if !generated_code(ex_span) {
14151422
self.dumper.dump_ref(field_data);
14161423
}
14171424
}
@@ -1450,7 +1457,7 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
14501457
}
14511458

14521459
fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
1453-
self.process_macro_use(p.span);
1460+
self.process_macro_use(p.hir_id);
14541461
self.process_pat(p);
14551462
}
14561463

@@ -1467,12 +1474,12 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
14671474
}
14681475

14691476
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
1470-
self.process_macro_use(s.span);
1477+
self.process_macro_use(s.hir_id);
14711478
intravisit::walk_stmt(self, s)
14721479
}
14731480

14741481
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
1475-
self.process_macro_use(l.span);
1482+
self.process_macro_use(l.hir_id);
14761483
self.process_var_decl(&l.pat);
14771484

14781485
// Just walk the initialiser and type (don't want to walk the pattern again).
@@ -1486,7 +1493,7 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
14861493
match item.kind {
14871494
hir::ForeignItemKind::Fn(decl, _, ref generics) => {
14881495
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
1489-
down_cast_data!(fn_data, DefData, item.span);
1496+
down_cast_data!(fn_data, DefData, self.tcx.hir().span(item.hir_id));
14901497

14911498
self.process_generic_params(generics, &fn_data.qualname, item.hir_id);
14921499
self.dumper.dump_def(&access, fn_data);
@@ -1502,15 +1509,15 @@ impl<'l, 'tcx> Visitor<'tcx> for DumpVisitor<'l, 'tcx> {
15021509
}
15031510
hir::ForeignItemKind::Static(ref ty, _) => {
15041511
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
1505-
down_cast_data!(var_data, DefData, item.span);
1512+
down_cast_data!(var_data, DefData, self.tcx.hir().span(item.hir_id));
15061513
self.dumper.dump_def(&access, var_data);
15071514
}
15081515

15091516
self.visit_ty(ty);
15101517
}
15111518
hir::ForeignItemKind::Type => {
15121519
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
1513-
down_cast_data!(var_data, DefData, item.span);
1520+
down_cast_data!(var_data, DefData, self.tcx.hir().span(item.hir_id));
15141521
self.dumper.dump_def(&access, var_data);
15151522
}
15161523
}

src/librustc_save_analysis/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,13 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
296296
let name = item.ident.to_string();
297297
let qualname = format!("::{}", self.tcx.def_path_str(def_id));
298298
filter!(self.span_utils, item.ident.span);
299-
let value =
300-
enum_def_to_string(def, generics, item.ident.name, item.span, &item.vis);
299+
let value = enum_def_to_string(
300+
def,
301+
generics,
302+
item.ident.name,
303+
self.tcx.hir().span(item.hir_id),
304+
&item.vis,
305+
);
301306
Some(Data::DefData(Def {
302307
kind: DefKind::Enum,
303308
id: id_from_def_id(def_id),
@@ -885,7 +890,9 @@ impl<'l> Visitor<'l> for PathCollector<'l> {
885890
hir::PatKind::Binding(bm, _, ident, _) => {
886891
debug!(
887892
"PathCollector, visit ident in pat {}: {:?} {:?}",
888-
ident, p.span, ident.span
893+
ident,
894+
self.tcx.hir().span(p.hir_id),
895+
ident.span
889896
);
890897
let immut = match bm {
891898
// Even if the ref is mut, you can't change the ref, only

0 commit comments

Comments
 (0)