Skip to content

Commit a70ca27

Browse files
committed
rustc: replace node_path_str with uses of def_path_str.
1 parent 534afff commit a70ca27

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
11891189
// the user-friendly path, otherwise fall back to stringifying DefPath.
11901190
::ty::tls::with_opt(|tcx| {
11911191
if let Some(tcx) = tcx {
1192-
tcx.node_path_str(id)
1192+
let def_id = map.local_def_id(id);
1193+
tcx.def_path_str(def_id)
11931194
} else if let Some(path) = map.def_path_from_id(id) {
11941195
path.data.into_iter().map(|elem| {
11951196
elem.data.to_string()

src/librustc/ty/print.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
216216
.print_def_path(def_id, None, ns, iter::empty());
217217
s
218218
}
219-
220-
/// Returns a string identifying this local node-id.
221-
// FIXME(eddyb) remove in favor of calling `def_path_str` directly.
222-
pub fn node_path_str(self, id: ast::NodeId) -> String {
223-
self.def_path_str(self.hir().local_def_id(id))
224-
}
225219
}
226220

227221
impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
489489
}
490490

491491
fn node_path(&self, id: ast::NodeId) -> Option<String> {
492-
Some(self.tcx.node_path_str(id))
492+
Some(self.tcx.def_path_str(self.tcx.hir().local_def_id(id)))
493493
}
494494
}
495495

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
423423
vis: ast::Visibility,
424424
attrs: &'l [Attribute],
425425
) {
426-
let qualname = format!("::{}", self.tcx.node_path_str(id));
426+
let qualname = format!("::{}",
427+
self.tcx.def_path_str(self.tcx.hir().local_def_id(id)));
427428

428429
if !self.span.filter_generated(ident.span) {
429430
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
@@ -464,7 +465,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
464465
) {
465466
debug!("process_struct {:?} {:?}", item, item.span);
466467
let name = item.ident.to_string();
467-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
468+
let qualname = format!("::{}",
469+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
468470

469471
let kind = match item.node {
470472
ast::ItemKind::Struct(_, _) => DefKind::Struct,
@@ -676,7 +678,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
676678
methods: &'l [ast::TraitItem],
677679
) {
678680
let name = item.ident.to_string();
679-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
681+
let qualname = format!("::{}",
682+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
680683
let mut val = name.clone();
681684
if !generics.params.is_empty() {
682685
val.push_str(&generic_params_to_string(&generics.params));
@@ -1087,7 +1090,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10871090
ast::TraitItemKind::Type(ref bounds, ref default_ty) => {
10881091
// FIXME do something with _bounds (for type refs)
10891092
let name = trait_item.ident.name.to_string();
1090-
let qualname = format!("::{}", self.tcx.node_path_str(trait_item.id));
1093+
let qualname = format!("::{}",
1094+
self.tcx.def_path_str(self.tcx.hir().local_def_id(trait_item.id)));
10911095

10921096
if !self.span.filter_generated(trait_item.ident.span) {
10931097
let span = self.span_from_span(trait_item.ident.span);
@@ -1294,7 +1298,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
12941298
// only get called for the root module of a crate.
12951299
assert_eq!(id, ast::CRATE_NODE_ID);
12961300

1297-
let qualname = format!("::{}", self.tcx.node_path_str(id));
1301+
let qualname = format!("::{}",
1302+
self.tcx.def_path_str(self.tcx.hir().local_def_id(id)));
12981303

12991304
let cm = self.tcx.sess.source_map();
13001305
let filename = cm.span_to_filename(span);
@@ -1383,7 +1388,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13831388
self.nest_scope(item.id, |v| visit::walk_mod(v, m));
13841389
}
13851390
Ty(ref ty, ref ty_params) => {
1386-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
1391+
let qualname = format!("::{}",
1392+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
13871393
let value = ty_to_string(&ty);
13881394
if !self.span.filter_generated(item.ident.span) {
13891395
let span = self.span_from_span(item.ident.span);
@@ -1412,7 +1418,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14121418
self.process_generic_params(ty_params, &qualname, item.id);
14131419
}
14141420
Existential(ref _bounds, ref ty_params) => {
1415-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
1421+
let qualname = format!("::{}",
1422+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
14161423
// FIXME do something with _bounds
14171424
let value = String::new();
14181425
if !self.span.filter_generated(item.ident.span) {

src/librustc_save_analysis/lib.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
149149
}
150150

151151
pub fn get_extern_item_data(&self, item: &ast::ForeignItem) -> Option<Data> {
152-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
152+
let qualname = format!("::{}",
153+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
153154
match item.node {
154155
ast::ForeignItemKind::Fn(ref decl, ref generics) => {
155156
filter!(self.span_utils, item.ident.span);
@@ -199,7 +200,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
199200
pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
200201
match item.node {
201202
ast::ItemKind::Fn(ref decl, .., ref generics, _) => {
202-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
203+
let qualname = format!("::{}",
204+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
203205
filter!(self.span_utils, item.ident.span);
204206
Some(Data::DefData(Def {
205207
kind: DefKind::Function,
@@ -217,7 +219,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
217219
}))
218220
}
219221
ast::ItemKind::Static(ref typ, ..) => {
220-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
222+
let qualname = format!("::{}",
223+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
221224

222225
filter!(self.span_utils, item.ident.span);
223226

@@ -240,7 +243,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
240243
}))
241244
}
242245
ast::ItemKind::Const(ref typ, _) => {
243-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
246+
let qualname = format!("::{}",
247+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
244248
filter!(self.span_utils, item.ident.span);
245249

246250
let id = id_from_node_id(item.id, self);
@@ -262,7 +266,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
262266
}))
263267
}
264268
ast::ItemKind::Mod(ref m) => {
265-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
269+
let qualname = format!("::{}",
270+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
266271

267272
let cm = self.tcx.sess.source_map();
268273
let filename = cm.span_to_filename(m.inner);
@@ -289,7 +294,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
289294
}
290295
ast::ItemKind::Enum(ref def, _) => {
291296
let name = item.ident.to_string();
292-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
297+
let qualname = format!("::{}",
298+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
293299
filter!(self.span_utils, item.ident.span);
294300
let variants_str = def.variants
295301
.iter()
@@ -373,7 +379,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
373379
pub fn get_field_data(&self, field: &ast::StructField, scope: NodeId) -> Option<Def> {
374380
if let Some(ident) = field.ident {
375381
let name = ident.to_string();
376-
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
382+
let qualname = format!("::{}::{}",
383+
self.tcx.def_path_str(self.tcx.hir().local_def_id(scope)),
384+
ident);
377385
filter!(self.span_utils, ident.span);
378386
let def_id = self.tcx.hir().local_def_id(field.id);
379387
let typ = self.tcx.type_of(def_id).to_string();

0 commit comments

Comments
 (0)