Skip to content

Commit 27ddf2c

Browse files
committed
rustc: replace node_path_str with uses of def_path_str.
1 parent 36f64f1 commit 27ddf2c

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,8 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
13511351
// the user-friendly path, otherwise fall back to stringifying DefPath.
13521352
crate::ty::tls::with_opt(|tcx| {
13531353
if let Some(tcx) = tcx {
1354-
tcx.node_path_str(id)
1354+
let def_id = map.local_def_id(id);
1355+
tcx.def_path_str(def_id)
13551356
} else if let Some(path) = map.def_path_from_id(id) {
13561357
path.data.into_iter().map(|elem| {
13571358
elem.data.to_string()

src/librustc/ty/print.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
44
use crate::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable};
55
use crate::ty::subst::{Kind, Subst, SubstsRef, UnpackedKind};
66
use crate::middle::cstore::{ExternCrate, ExternCrateSource};
7-
use syntax::ast;
87
use syntax::symbol::{keywords, Symbol};
98

109
use rustc_data_structures::fx::FxHashSet;
@@ -217,12 +216,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
217216
.print_def_path(def_id, None, ns, iter::empty());
218217
s
219218
}
220-
221-
/// Returns a string identifying this local node-id.
222-
// FIXME(eddyb) remove in favor of calling `def_path_str` directly.
223-
pub fn node_path_str(self, id: ast::NodeId) -> String {
224-
self.def_path_str(self.hir().local_def_id(id))
225-
}
226219
}
227220

228221
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
@@ -471,7 +471,7 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> {
471471
}
472472

473473
fn node_path(&self, id: ast::NodeId) -> Option<String> {
474-
Some(self.tcx.node_path_str(id))
474+
Some(self.tcx.def_path_str(self.tcx.hir().local_def_id(id)))
475475
}
476476
}
477477

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
429429
vis: ast::Visibility,
430430
attrs: &'l [Attribute],
431431
) {
432-
let qualname = format!("::{}", self.tcx.node_path_str(id));
432+
let qualname = format!("::{}",
433+
self.tcx.def_path_str(self.tcx.hir().local_def_id(id)));
433434

434435
if !self.span.filter_generated(ident.span) {
435436
let sig = sig::assoc_const_signature(id, ident.name, typ, expr, &self.save_ctxt);
@@ -470,7 +471,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
470471
) {
471472
debug!("process_struct {:?} {:?}", item, item.span);
472473
let name = item.ident.to_string();
473-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
474+
let qualname = format!("::{}",
475+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
474476

475477
let kind = match item.node {
476478
ast::ItemKind::Struct(_, _) => DefKind::Struct,
@@ -682,7 +684,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
682684
methods: &'l [ast::TraitItem],
683685
) {
684686
let name = item.ident.to_string();
685-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
687+
let qualname = format!("::{}",
688+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
686689
let mut val = name.clone();
687690
if !generics.params.is_empty() {
688691
val.push_str(&generic_params_to_string(&generics.params));
@@ -1093,7 +1096,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10931096
ast::TraitItemKind::Type(ref bounds, ref default_ty) => {
10941097
// FIXME do something with _bounds (for type refs)
10951098
let name = trait_item.ident.name.to_string();
1096-
let qualname = format!("::{}", self.tcx.node_path_str(trait_item.id));
1099+
let qualname = format!("::{}",
1100+
self.tcx.def_path_str(self.tcx.hir().local_def_id(trait_item.id)));
10971101

10981102
if !self.span.filter_generated(trait_item.ident.span) {
10991103
let span = self.span_from_span(trait_item.ident.span);
@@ -1300,7 +1304,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13001304
// only get called for the root module of a crate.
13011305
assert_eq!(id, ast::CRATE_NODE_ID);
13021306

1303-
let qualname = format!("::{}", self.tcx.node_path_str(id));
1307+
let qualname = format!("::{}",
1308+
self.tcx.def_path_str(self.tcx.hir().local_def_id(id)));
13041309

13051310
let cm = self.tcx.sess.source_map();
13061311
let filename = cm.span_to_filename(span);
@@ -1389,7 +1394,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13891394
self.nest_scope(item.id, |v| visit::walk_mod(v, m));
13901395
}
13911396
Ty(ref ty, ref ty_params) => {
1392-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
1397+
let qualname = format!("::{}",
1398+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
13931399
let value = ty_to_string(&ty);
13941400
if !self.span.filter_generated(item.ident.span) {
13951401
let span = self.span_from_span(item.ident.span);
@@ -1418,7 +1424,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14181424
self.process_generic_params(ty_params, &qualname, item.id);
14191425
}
14201426
Existential(ref _bounds, ref ty_params) => {
1421-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
1427+
let qualname = format!("::{}",
1428+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
14221429
// FIXME do something with _bounds
14231430
let value = String::new();
14241431
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
@@ -134,7 +134,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
134134
}
135135

136136
pub fn get_extern_item_data(&self, item: &ast::ForeignItem) -> Option<Data> {
137-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
137+
let qualname = format!("::{}",
138+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
138139
match item.node {
139140
ast::ForeignItemKind::Fn(ref decl, ref generics) => {
140141
filter!(self.span_utils, item.ident.span);
@@ -184,7 +185,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
184185
pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
185186
match item.node {
186187
ast::ItemKind::Fn(ref decl, .., ref generics, _) => {
187-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
188+
let qualname = format!("::{}",
189+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
188190
filter!(self.span_utils, item.ident.span);
189191
Some(Data::DefData(Def {
190192
kind: DefKind::Function,
@@ -202,7 +204,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
202204
}))
203205
}
204206
ast::ItemKind::Static(ref typ, ..) => {
205-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
207+
let qualname = format!("::{}",
208+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
206209

207210
filter!(self.span_utils, item.ident.span);
208211

@@ -225,7 +228,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
225228
}))
226229
}
227230
ast::ItemKind::Const(ref typ, _) => {
228-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
231+
let qualname = format!("::{}",
232+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
229233
filter!(self.span_utils, item.ident.span);
230234

231235
let id = id_from_node_id(item.id, self);
@@ -247,7 +251,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
247251
}))
248252
}
249253
ast::ItemKind::Mod(ref m) => {
250-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
254+
let qualname = format!("::{}",
255+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
251256

252257
let cm = self.tcx.sess.source_map();
253258
let filename = cm.span_to_filename(m.inner);
@@ -274,7 +279,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
274279
}
275280
ast::ItemKind::Enum(ref def, _) => {
276281
let name = item.ident.to_string();
277-
let qualname = format!("::{}", self.tcx.node_path_str(item.id));
282+
let qualname = format!("::{}",
283+
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.id)));
278284
filter!(self.span_utils, item.ident.span);
279285
let variants_str = def.variants
280286
.iter()
@@ -358,7 +364,9 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
358364
pub fn get_field_data(&self, field: &ast::StructField, scope: NodeId) -> Option<Def> {
359365
if let Some(ident) = field.ident {
360366
let name = ident.to_string();
361-
let qualname = format!("::{}::{}", self.tcx.node_path_str(scope), ident);
367+
let qualname = format!("::{}::{}",
368+
self.tcx.def_path_str(self.tcx.hir().local_def_id(scope)),
369+
ident);
362370
filter!(self.span_utils, ident.span);
363371
let def_id = self.tcx.hir().local_def_id(field.id);
364372
let typ = self.tcx.type_of(def_id).to_string();

0 commit comments

Comments
 (0)