HirIdification: replace NodeId method calls
This commit is contained in:
parent
88f755f8a8
commit
cd06038b54
69 changed files with 336 additions and 339 deletions
|
|
@ -3,7 +3,7 @@ use rustc::traits::auto_trait as auto;
|
|||
use rustc::ty::{self, TypeFoldable};
|
||||
use std::fmt::Debug;
|
||||
|
||||
use self::def_ctor::{get_def_from_def_id, get_def_from_node_id};
|
||||
use self::def_ctor::{get_def_from_def_id, get_def_from_hir_id};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
|
@ -25,9 +25,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec<Item> {
|
||||
get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| {
|
||||
let did = self.cx.tcx.hir().local_def_id(id);
|
||||
pub fn get_with_hir_id(&self, id: hir::HirId, name: String) -> Vec<Item> {
|
||||
get_def_from_hir_id(&self.cx, id, name, &|def_ctor, name| {
|
||||
let did = self.cx.tcx.hir().local_def_id_from_hir_id(id);
|
||||
self.get_auto_trait_impls(did, &def_ctor, Some(name))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::core::DocAccessLevels;
|
|||
|
||||
use super::*;
|
||||
|
||||
use self::def_ctor::{get_def_from_def_id, get_def_from_node_id};
|
||||
use self::def_ctor::{get_def_from_def_id, get_def_from_hir_id};
|
||||
|
||||
pub struct BlanketImplFinder<'a, 'tcx: 'a, 'rcx: 'a> {
|
||||
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>,
|
||||
|
|
@ -26,9 +26,9 @@ impl<'a, 'tcx, 'rcx> BlanketImplFinder <'a, 'tcx, 'rcx> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec<Item> {
|
||||
get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| {
|
||||
let did = self.cx.tcx.hir().local_def_id(id);
|
||||
pub fn get_with_hir_id(&self, id: hir::HirId, name: String) -> Vec<Item> {
|
||||
get_def_from_hir_id(&self.cx, id, name, &|def_ctor, name| {
|
||||
let did = self.cx.tcx.hir().local_def_id_from_hir_id(id);
|
||||
self.get_blanket_impls(did, &def_ctor, Some(name))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,13 +38,13 @@ where F: Fn(& dyn Fn(DefId) -> Def) -> Vec<Item> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_def_from_node_id<F>(cx: &DocContext<'_, '_, '_>,
|
||||
id: ast::NodeId,
|
||||
name: String,
|
||||
callback: &F,
|
||||
pub fn get_def_from_hir_id<F>(cx: &DocContext<'_, '_, '_>,
|
||||
id: hir::HirId,
|
||||
name: String,
|
||||
callback: &F,
|
||||
) -> Vec<Item>
|
||||
where F: Fn(& dyn Fn(DefId) -> Def, String) -> Vec<Item> {
|
||||
let item = &cx.tcx.hir().expect_item(id).node;
|
||||
let item = &cx.tcx.hir().expect_item_by_hir_id(id).node;
|
||||
|
||||
callback(&match *item {
|
||||
hir::ItemKind::Struct(_, _) => Def::Struct,
|
||||
|
|
|
|||
|
|
@ -422,8 +422,8 @@ fn build_module(
|
|||
}
|
||||
|
||||
pub fn print_inlined_const(cx: &DocContext<'_, '_, '_>, did: DefId) -> String {
|
||||
if let Some(node_id) = cx.tcx.hir().as_local_node_id(did) {
|
||||
cx.tcx.hir().node_to_pretty_string(node_id)
|
||||
if let Some(node_id) = cx.tcx.hir().as_local_hir_id(did) {
|
||||
cx.tcx.hir().hir_to_pretty_string(node_id)
|
||||
} else {
|
||||
cx.tcx.rendered_const(did)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1847,7 +1847,7 @@ impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl, A)
|
|||
impl<'a, 'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
|
||||
fn clean(&self, cx: &DocContext<'_, '_, '_>) -> FnDecl {
|
||||
let (did, sig) = *self;
|
||||
let mut names = if cx.tcx.hir().as_local_node_id(did).is_some() {
|
||||
let mut names = if cx.tcx.hir().as_local_hir_id(did).is_some() {
|
||||
vec![].into_iter()
|
||||
} else {
|
||||
cx.tcx.fn_arg_names(did).into_iter()
|
||||
|
|
@ -3541,13 +3541,13 @@ pub struct Impl {
|
|||
pub blanket_impl: Option<Type>,
|
||||
}
|
||||
|
||||
pub fn get_auto_traits_with_node_id(
|
||||
pub fn get_auto_traits_with_hir_id(
|
||||
cx: &DocContext<'_, '_, '_>,
|
||||
id: ast::NodeId,
|
||||
id: hir::HirId,
|
||||
name: String
|
||||
) -> Vec<Item> {
|
||||
let finder = AutoTraitFinder::new(cx);
|
||||
finder.get_with_node_id(id, name)
|
||||
finder.get_with_hir_id(id, name)
|
||||
}
|
||||
|
||||
pub fn get_auto_traits_with_def_id(
|
||||
|
|
@ -3559,13 +3559,13 @@ pub fn get_auto_traits_with_def_id(
|
|||
finder.get_with_def_id(id)
|
||||
}
|
||||
|
||||
pub fn get_blanket_impls_with_node_id(
|
||||
pub fn get_blanket_impls_with_hir_id(
|
||||
cx: &DocContext<'_, '_, '_>,
|
||||
id: ast::NodeId,
|
||||
id: hir::HirId,
|
||||
name: String
|
||||
) -> Vec<Item> {
|
||||
let finder = BlanketImplFinder::new(cx);
|
||||
finder.get_with_node_id(id, name)
|
||||
finder.get_with_hir_id(id, name)
|
||||
}
|
||||
|
||||
pub fn get_blanket_impls_with_def_id(
|
||||
|
|
@ -3902,8 +3902,8 @@ fn name_from_pat(p: &hir::Pat) -> String {
|
|||
fn print_const(cx: &DocContext<'_, '_, '_>, n: ty::LazyConst<'_>) -> String {
|
||||
match n {
|
||||
ty::LazyConst::Unevaluated(def_id, _) => {
|
||||
if let Some(node_id) = cx.tcx.hir().as_local_node_id(def_id) {
|
||||
print_const_expr(cx, cx.tcx.hir().body_owned_by(node_id))
|
||||
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(def_id) {
|
||||
print_const_expr(cx, cx.tcx.hir().body_owned_by(hir_id))
|
||||
} else {
|
||||
inline::print_inlined_const(cx, def_id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use rustc_driver::{driver, abort_on_err};
|
|||
use rustc::session::{self, config};
|
||||
use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CrateNum, LOCAL_CRATE};
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::{self, HirVec};
|
||||
use rustc::hir::{self, HirId, HirVec};
|
||||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::ty::{self, TyCtxt, AllArenas};
|
||||
|
|
@ -17,7 +17,7 @@ use rustc_metadata::creader::CrateLoader;
|
|||
use rustc_metadata::cstore::CStore;
|
||||
use rustc_target::spec::TargetTriple;
|
||||
|
||||
use syntax::ast::{self, Ident, NodeId};
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::source_map;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use syntax::json::JsonEmitter;
|
||||
|
|
@ -159,7 +159,7 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> {
|
|||
|
||||
/// Like the function of the same name on the HIR map, but skips calling it on fake DefIds.
|
||||
/// (This avoids a slice-index-out-of-bounds panic.)
|
||||
pub fn as_local_node_id(&self, def_id: DefId) -> Option<NodeId> {
|
||||
pub fn as_local_node_id(&self, def_id: DefId) -> Option<ast::NodeId> {
|
||||
if self.all_fake_def_ids.borrow().contains(&def_id) {
|
||||
None
|
||||
} else {
|
||||
|
|
@ -167,6 +167,15 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME(@ljedrz): remove the NodeId variant
|
||||
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<HirId> {
|
||||
if self.all_fake_def_ids.borrow().contains(&def_id) {
|
||||
None
|
||||
} else {
|
||||
self.tcx.hir().as_local_hir_id(def_id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_real_ty<F>(&self,
|
||||
def_id: DefId,
|
||||
def_ctor: &F,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use rustc::hir::def::Def;
|
|||
use rustc::hir::def_id::DefId;
|
||||
use rustc::ty;
|
||||
use syntax;
|
||||
use syntax::ast::{self, Ident, NodeId};
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax_pos::DUMMY_SP;
|
||||
|
|
@ -49,7 +49,7 @@ enum PathKind {
|
|||
|
||||
struct LinkCollector<'a, 'tcx: 'a, 'rcx: 'a> {
|
||||
cx: &'a DocContext<'a, 'tcx, 'rcx>,
|
||||
mod_ids: Vec<NodeId>,
|
||||
mod_ids: Vec<ast::NodeId>,
|
||||
is_nightly_build: bool,
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> {
|
|||
path_str: &str,
|
||||
is_val: bool,
|
||||
current_item: &Option<String>,
|
||||
parent_id: Option<NodeId>)
|
||||
parent_id: Option<ast::NodeId>)
|
||||
-> Result<(Def, Option<String>), ()>
|
||||
{
|
||||
let cx = self.cx;
|
||||
|
|
@ -220,8 +220,8 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> {
|
|||
|
||||
impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
|
||||
fn fold_item(&mut self, mut item: Item) -> Option<Item> {
|
||||
let item_node_id = if item.is_mod() {
|
||||
if let Some(id) = self.cx.tcx.hir().as_local_node_id(item.def_id) {
|
||||
let item_hir_id = if item.is_mod() {
|
||||
if let Some(id) = self.cx.tcx.hir().as_local_hir_id(item.def_id) {
|
||||
Some(id)
|
||||
} else {
|
||||
debug!("attempting to fold on a non-local item: {:?}", item);
|
||||
|
|
@ -248,14 +248,14 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
|
|||
let current_item = match item.inner {
|
||||
ModuleItem(..) => {
|
||||
if item.attrs.inner_docs {
|
||||
if item_node_id.unwrap() != NodeId::from_u32(0) {
|
||||
if item_hir_id.unwrap() != hir::CRATE_HIR_ID {
|
||||
item.name.clone()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
match parent_node.or(self.mod_ids.last().cloned()) {
|
||||
Some(parent) if parent != NodeId::from_u32(0) => {
|
||||
Some(parent) if parent != ast::CRATE_NODE_ID => {
|
||||
// FIXME: can we pull the parent module's name from elsewhere?
|
||||
Some(self.cx.tcx.hir().name(parent).to_string())
|
||||
}
|
||||
|
|
@ -274,7 +274,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
|
|||
};
|
||||
|
||||
if item.is_mod() && item.attrs.inner_docs {
|
||||
self.mod_ids.push(item_node_id.unwrap());
|
||||
self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap()));
|
||||
}
|
||||
|
||||
let cx = self.cx;
|
||||
|
|
@ -421,7 +421,7 @@ impl<'a, 'tcx, 'rcx> DocFolder for LinkCollector<'a, 'tcx, 'rcx> {
|
|||
}
|
||||
|
||||
if item.is_mod() && !item.attrs.inner_docs {
|
||||
self.mod_ids.push(item_node_id.unwrap());
|
||||
self.mod_ids.push(self.cx.tcx.hir().hir_to_node_id(item_hir_id.unwrap()));
|
||||
}
|
||||
|
||||
if item.is_mod() {
|
||||
|
|
|
|||
|
|
@ -155,11 +155,11 @@ impl<'a, 'tcx, 'rcx> SyntheticImplCollector<'a, 'tcx, 'rcx> {
|
|||
impl<'a, 'tcx, 'rcx> DocFolder for SyntheticImplCollector<'a, 'tcx, 'rcx> {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
if i.is_struct() || i.is_enum() || i.is_union() {
|
||||
if let (Some(node_id), Some(name)) =
|
||||
(self.cx.tcx.hir().as_local_node_id(i.def_id), i.name.clone())
|
||||
if let (Some(hir_id), Some(name)) =
|
||||
(self.cx.tcx.hir().as_local_hir_id(i.def_id), i.name.clone())
|
||||
{
|
||||
self.impls.extend(get_auto_traits_with_node_id(self.cx, node_id, name.clone()));
|
||||
self.impls.extend(get_blanket_impls_with_node_id(self.cx, node_id, name));
|
||||
self.impls.extend(get_auto_traits_with_hir_id(self.cx, hir_id, name.clone()));
|
||||
self.impls.extend(get_blanket_impls_with_hir_id(self.cx, hir_id, name));
|
||||
} else {
|
||||
self.impls.extend(get_auto_traits_with_def_id(self.cx, i.def_id));
|
||||
self.impls.extend(get_blanket_impls_with_def_id(self.cx, i.def_id));
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ pub fn look_for_tests<'a, 'tcx: 'a, 'rcx: 'a>(
|
|||
item: &Item,
|
||||
check_missing_code: bool,
|
||||
) {
|
||||
if cx.as_local_node_id(item.def_id).is_none() {
|
||||
if cx.as_local_hir_id(item.def_id).is_none() {
|
||||
// If non-local, no need to check anything.
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue