Replace get_item_path[-1] with get_item_name

This commit is contained in:
mitaa 2015-08-12 20:22:25 +02:00
parent 1db1417736
commit f357d559ca
7 changed files with 23 additions and 37 deletions

View file

@ -95,6 +95,12 @@ pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem>
})
}
pub fn get_item_name(tcx: &ty::ctxt, def: ast::DefId) -> ast::Name {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_item_name(&cstore.intr, &cdata, def.node)
}
pub enum FoundAst<'ast> {
Found(&'ast ast::InlinedItem),
FoundParent(ast::DefId, &'ast ast::InlinedItem),

View file

@ -770,6 +770,10 @@ pub fn get_item_path(cdata: Cmd, id: ast::NodeId) -> Vec<ast_map::PathElem> {
item_path(lookup_item(id, cdata.data()))
}
pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId) -> ast::Name {
item_name(intr, lookup_item(id, cdata.data()))
}
pub type DecodeInlinedItem<'a> =
Box<for<'tcx> FnMut(Cmd,
&ty::ctxt<'tcx>,

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use ast_map::NodeForeignItem;
use metadata::csearch;
use middle::def::DefFn;
use middle::subst::{Subst, Substs, EnumeratedItems};
use middle::ty::{TransmuteRestriction, ctxt, TyBareFn};
@ -57,21 +55,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
ty::TyBareFn(_, ref bfty) => bfty.abi == RustIntrinsic,
_ => return false
};
if def_id.krate == ast::LOCAL_CRATE {
match self.tcx.map.get(def_id.node) {
NodeForeignItem(ref item) if intrinsic => {
item.ident.name == "transmute"
}
_ => false,
}
} else {
match csearch::get_item_path(self.tcx, def_id).last() {
Some(ref last) if intrinsic => {
last.name() == "transmute"
}
_ => false,
}
}
intrinsic && self.tcx.item_name(def_id) == "transmute"
}
fn check_transmute(&self, span: Span, from: Ty<'tcx>, to: Ty<'tcx>, id: ast::NodeId) {

View file

@ -5927,6 +5927,14 @@ impl<'tcx> ctxt<'tcx> {
}
}
pub fn item_name(&self, id: ast::DefId) -> ast::Name {
if id.krate == ast::LOCAL_CRATE {
self.map.get_path_elem(id.node).name()
} else {
csearch::get_item_name(self, id)
}
}
/// Returns `(normalized_type, ty)`, where `normalized_type` is the
/// IntType representation of one of {i64,i32,i16,i8,u64,u32,u16,u8},
/// and `ty` is the original type (i.e. may include `isize` or