Skip to content

Commit f357d55

Browse files
committed
Replace get_item_path[-1] with get_item_name
1 parent 1db1417 commit f357d55

File tree

7 files changed

+23
-37
lines changed

7 files changed

+23
-37
lines changed

src/librustc/metadata/csearch.rs

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem>
9595
})
9696
}
9797

98+
pub fn get_item_name(tcx: &ty::ctxt, def: ast::DefId) -> ast::Name {
99+
let cstore = &tcx.sess.cstore;
100+
let cdata = cstore.get_crate_data(def.krate);
101+
decoder::get_item_name(&cstore.intr, &cdata, def.node)
102+
}
103+
98104
pub enum FoundAst<'ast> {
99105
Found(&'ast ast::InlinedItem),
100106
FoundParent(ast::DefId, &'ast ast::InlinedItem),

src/librustc/metadata/decoder.rs

+4
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec<ast_map::PathElem> {
770770
item_path(lookup_item(id, cdata.data()))
771771
}
772772

773+
pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId) -> ast::Name {
774+
item_name(intr, lookup_item(id, cdata.data()))
775+
}
776+
773777
pub type DecodeInlinedItem<'a> =
774778
Box<for<'tcx> FnMut(Cmd,
775779
&ty::ctxt<'tcx>,

src/librustc/middle/intrinsicck.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use ast_map::NodeForeignItem;
12-
use metadata::csearch;
1311
use middle::def::DefFn;
1412
use middle::subst::{Subst, Substs, EnumeratedItems};
1513
use middle::ty::{TransmuteRestriction, ctxt, TyBareFn};
@@ -57,21 +55,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
5755
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
5856
_ => return false
5957
};
60-
if def_id.krate == ast::LOCAL_CRATE {
61-
match self.tcx.map.get(def_id.node) {
62-
NodeForeignItem(ref item) if intrinsic => {
63-
item.ident.name == "transmute"
64-
}
65-
_ => false,
66-
}
67-
} else {
68-
match csearch::get_item_path(self.tcx, def_id).last() {
69-
Some(ref last) if intrinsic => {
70-
last.name() == "transmute"
71-
}
72-
_ => false,
73-
}
74-
}
58+
intrinsic && self.tcx.item_name(def_id) == "transmute"
7559
}
7660

7761
fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>, id: ast::NodeId) {

src/librustc/middle/ty.rs

+8
Original file line numberDiff line numberDiff line change
@@ -5927,6 +5927,14 @@ impl<'tcx> ctxt<'tcx> {
59275927
}
59285928
}
59295929

5930+
pub fn item_name(&self, id: ast::DefId) -> ast::Name {
5931+
if id.krate == ast::LOCAL_CRATE {
5932+
self.map.get_path_elem(id.node).name()
5933+
} else {
5934+
csearch::get_item_name(self, id)
5935+
}
5936+
}
5937+
59305938
/// Returns `(normalized_type, ty)`, where `normalized_type` is the
59315939
/// IntType representation of one of {i64,i32,i16,i8,u64,u32,u16,u8},
59325940
/// and `ty` is the original type (i.e. may include `isize` or

src/librustc_trans/trans/debuginfo/metadata.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use super::{declare_local, VariableKind, VariableAccess};
2323
use llvm::{self, ValueRef};
2424
use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor, DICompositeType};
2525

26-
use metadata::csearch;
2726
use middle::pat_util;
2827
use middle::subst::{self, Substs};
2928
use rustc::ast_map;
@@ -1686,13 +1685,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
16861685
fn get_enum_discriminant_name(cx: &CrateContext,
16871686
def_id: ast::DefId)
16881687
-> token::InternedString {
1689-
let name = if def_id.krate == ast::LOCAL_CRATE {
1690-
cx.tcx().map.get_path_elem(def_id.node).name()
1691-
} else {
1692-
csearch::get_item_path(cx.tcx(), def_id).last().unwrap().name()
1693-
};
1694-
1695-
name.as_str()
1688+
cx.tcx().item_name(def_id).as_str()
16961689
}
16971690
}
16981691

src/librustc_trans/trans/meth.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ use arena::TypedArena;
1212
use back::abi;
1313
use back::link;
1414
use llvm::{ValueRef, get_params};
15-
use metadata::csearch;
1615
use middle::subst::{Subst, Substs};
1716
use middle::subst::VecPerParamSpace;
1817
use middle::subst;
1918
use middle::traits;
20-
use rustc::ast_map;
2119
use trans::base::*;
2220
use trans::build::*;
2321
use trans::callee::*;
@@ -165,14 +163,8 @@ pub fn trans_static_method_callee<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
165163
tcx.item_path_str(trait_id),
166164
expr_id);
167165

168-
let mname = if method_id.krate == ast::LOCAL_CRATE {
169-
match tcx.map.get(method_id.node) {
170-
ast_map::NodeTraitItem(trait_item) => trait_item.ident.name,
171-
_ => panic!("callee is not a trait method")
172-
}
173-
} else {
174-
csearch::get_item_path(tcx, method_id).last().unwrap().name()
175-
};
166+
let mname = tcx.item_name(method_id);
167+
176168
debug!("trans_static_method_callee: method_id={:?}, expr_id={}, \
177169
name={}", method_id, expr_id, mname);
178170

src/librustdoc/clean/inline.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,10 @@ fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
113113
}
114114
_ => return None,
115115
};
116-
let fqn = csearch::get_item_path(tcx, did);
117116
cx.inlined.borrow_mut().as_mut().unwrap().insert(did);
118117
ret.push(clean::Item {
119118
source: clean::Span::empty(),
120-
name: Some(fqn.last().unwrap().to_string()),
119+
name: Some(tcx.item_name(did).to_string()),
121120
attrs: load_attrs(cx, tcx, did),
122121
inner: inner,
123122
visibility: Some(ast::Public),

0 commit comments

Comments
 (0)