Rollup merge of #61836 - ljedrz:i_still_hate_node_ids, r=ljedrz

Replace some uses of NodeId with HirId

We are still using `NodeId` in some spots where we could use `HirId` instead; this PR targets some of these spots and removes some of the associated `hir::map` functions.
This commit is contained in:
Mazdak Farrokhzad 2019-06-17 20:55:57 +02:00 committed by GitHub
commit 0800b6ee20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 270 additions and 378 deletions

View file

@ -42,7 +42,7 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG {
let body_exit;
// Find the tables for this body.
let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id()));
let owner_def_id = tcx.hir().body_owner_def_id(body.id());
let tables = tcx.typeck_tables_of(owner_def_id);
let mut cfg_builder = CFGBuilder {
@ -357,7 +357,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
args: I) -> CFGIndex {
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id);
let m = self.tcx.hir().get_module_parent(call_expr.hir_id);
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
self.add_unreachable_node()
} else {

View file

@ -22,11 +22,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
assert!(self.cfg.owner_def_id.is_local());
let node_id = self.tcx.hir().hir_to_node_id(hir::HirId {
let hir_id = hir::HirId {
owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
local_id
});
let s = self.tcx.hir().node_to_string(node_id);
};
let s = self.tcx.hir().node_to_string(hir_id);
// Replacing newlines with \\l causes each line to be left-aligned,
// improving presentation of (long) pretty-printed expressions.

View file

@ -171,7 +171,7 @@ pub trait Visitor<'v> : Sized {
/// but cannot supply a `Map`; see `nested_visit_map` for advice.
#[allow(unused_variables)]
fn visit_nested_item(&mut self, id: ItemId) {
let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item_by_hir_id(id.id));
let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item(id.id));
if let Some(item) = opt_item {
self.visit_item(item);
}

View file

@ -1,6 +1,5 @@
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
use crate::hir::{self, intravisit, HirId, ItemLocalId};
use syntax::ast::NodeId;
use crate::hir::itemlikevisit::ItemLikeVisitor;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter};
@ -112,19 +111,9 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
trace!("missing hir id {:#?}", hir_id);
// We are already in ICE mode here, so doing a linear search
// should be fine.
let (node_id, _) = self.hir_map
.definitions()
.node_to_hir_id
.iter()
.enumerate()
.find(|&(_, &entry)| hir_id == entry)
.expect("no node_to_hir_id entry");
let node_id = NodeId::from_usize(node_id);
missing_items.push(format!("[local_id: {}, node:{}]",
local_id,
self.hir_map.node_to_string(node_id)));
self.hir_map.node_to_string(hir_id)));
}
self.error(|| format!(
"ItemLocalIds not assigned densely in {}. \
@ -138,7 +127,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
owner: owner_def_index,
local_id,
})
.map(|h| format!("({:?} {})", h, self.hir_map.hir_to_string(h)))
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
.collect::<Vec<_>>()));
}
}
@ -156,14 +145,14 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
if hir_id == hir::DUMMY_HIR_ID {
self.error(|| format!("HirIdValidator: HirId {:?} is invalid",
self.hir_map.hir_to_string(hir_id)));
self.hir_map.node_to_string(hir_id)));
return;
}
if owner != hir_id.owner {
self.error(|| format!(
"HirIdValidator: The recorded owner of {} is {} instead of {}",
self.hir_map.hir_to_string(hir_id),
self.hir_map.node_to_string(hir_id),
self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(),
self.hir_map.def_path(DefId::local(owner)).to_string_no_crate()));
}

View file

@ -35,7 +35,7 @@ mod def_collector;
pub mod definitions;
mod hir_id_validator;
/// Represents an entry and its parent `NodeId`.
/// Represents an entry and its parent `HirId`.
#[derive(Copy, Clone, Debug)]
pub struct Entry<'hir> {
parent: HirId,
@ -200,7 +200,7 @@ impl<'hir> Map<'hir> {
/// "reveals" the content of a node to the caller (who might not
/// otherwise have had access to those contents, and hence needs a
/// read recorded). If the function just returns a DefId or
/// NodeId, no actual content was returned, so no read is needed.
/// HirId, no actual content was returned, so no read is needed.
pub fn read(&self, hir_id: HirId) {
if let Some(entry) = self.lookup(hir_id) {
self.dep_graph.read_index(entry.dep_node);
@ -286,21 +286,11 @@ impl<'hir> Map<'hir> {
self.definitions.def_index_to_hir_id(def_index)
}
#[inline]
pub fn def_index_to_node_id(&self, def_index: DefIndex) -> NodeId {
self.definitions.def_index_to_node_id(def_index)
}
#[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
self.definitions.def_index_to_hir_id(def_id.to_def_id().index)
}
#[inline]
pub fn local_def_id_to_node_id(&self, def_id: LocalDefId) -> NodeId {
self.definitions.as_local_node_id(def_id.to_def_id()).unwrap()
}
fn def_kind(&self, node_id: NodeId) -> Option<DefKind> {
let node = if let Some(node) = self.find(node_id) {
node
@ -422,12 +412,6 @@ impl<'hir> Map<'hir> {
self.forest.krate.body(id)
}
pub fn fn_decl(&self, node_id: ast::NodeId) -> Option<FnDecl> {
let hir_id = self.node_to_hir_id(node_id);
self.fn_decl_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option<FnDecl> {
if let Some(entry) = self.find_entry(hir_id) {
entry.fn_decl().cloned()
@ -436,28 +420,22 @@ impl<'hir> Map<'hir> {
}
}
/// Returns the `NodeId` that corresponds to the definition of
/// Returns the `HirId` that corresponds to the definition of
/// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId {
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
let parent = self.get_parent_node_by_hir_id(hir_id);
assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id)));
self.hir_to_node_id(parent)
parent
}
pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
self.local_def_id(self.body_owner(id))
self.local_def_id_from_hir_id(self.body_owner(id))
}
/// Given a `NodeId`, returns the `BodyId` associated with it,
/// Given a `HirId`, returns the `BodyId` associated with it,
/// if the node is a body owner, otherwise returns `None`.
pub fn maybe_body_owned_by(&self, id: NodeId) -> Option<BodyId> {
let hir_id = self.node_to_hir_id(id);
self.maybe_body_owned_by_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn maybe_body_owned_by_by_hir_id(&self, hir_id: HirId) -> Option<BodyId> {
pub fn maybe_body_owned_by(&self, hir_id: HirId) -> Option<BodyId> {
if let Some(entry) = self.find_entry(hir_id) {
if self.dep_graph.is_fully_enabled() {
let hir_id_owner = hir_id.owner;
@ -473,19 +451,13 @@ impl<'hir> Map<'hir> {
/// Given a body owner's id, returns the `BodyId` associated with it.
pub fn body_owned_by(&self, id: HirId) -> BodyId {
self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| {
span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body",
self.hir_to_string(id));
self.maybe_body_owned_by(id).unwrap_or_else(|| {
span_bug!(self.span(id), "body_owned_by: {} has no associated body",
self.node_to_string(id));
})
}
pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind {
let hir_id = self.node_to_hir_id(id);
self.body_owner_kind_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind {
pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind {
match self.get_by_hir_id(id) {
Node::Item(&Item { node: ItemKind::Const(..), .. }) |
Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) |
@ -514,7 +486,7 @@ impl<'hir> Map<'hir> {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id))
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
}
}
@ -523,7 +495,7 @@ impl<'hir> Map<'hir> {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper,
Node::GenericParam(param) => param.name.ident().name,
_ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)),
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
}
}
@ -576,7 +548,7 @@ impl<'hir> Map<'hir> {
let module = &self.forest.krate.modules[&node_id];
for id in &module.items {
visitor.visit_item(self.expect_item_by_hir_id(*id));
visitor.visit_item(self.expect_item(*id));
}
for id in &module.trait_items {
@ -709,7 +681,7 @@ impl<'hir> Map<'hir> {
/// If there is some error when walking the parents (e.g., a node does not
/// have a parent in the map or a node can't be found), then we return the
/// last good `NodeId` we found. Note that reaching the crate root (`id == 0`),
/// last good `HirId` we found. Note that reaching the crate root (`id == 0`),
/// is not an error, since items in the crate module have the crate root as
/// parent.
fn walk_parent_nodes<F, F2>(&self,
@ -745,7 +717,7 @@ impl<'hir> Map<'hir> {
}
}
/// Retrieves the `NodeId` for `id`'s enclosing method, unless there's a
/// Retrieves the `HirId` for `id`'s enclosing method, unless there's a
/// `while` or `loop` before reaching it, as block tail returns are not
/// available in them.
///
@ -753,7 +725,7 @@ impl<'hir> Map<'hir> {
/// fn foo(x: usize) -> bool {
/// if x == 1 {
/// true // `get_return_block` gets passed the `id` corresponding
/// } else { // to this, it will return `foo`'s `NodeId`.
/// } else { // to this, it will return `foo`'s `HirId`.
/// false
/// }
/// }
@ -793,17 +765,10 @@ impl<'hir> Map<'hir> {
self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok()
}
/// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no
/// Retrieves the `HirId` for `id`'s parent item, or `id` itself if no
/// parent item is in this map. The "parent item" is the closest parent node
/// in the HIR which is recorded by the map and is an item, either an item
/// in a module, trait, or impl.
pub fn get_parent(&self, id: NodeId) -> NodeId {
let hir_id = self.node_to_hir_id(id);
let parent_hir_id = self.get_parent_item(hir_id);
self.hir_to_node_id(parent_hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn get_parent_item(&self, hir_id: HirId) -> HirId {
match self.walk_parent_nodes(hir_id, |node| match *node {
Node::Item(_) |
@ -819,13 +784,7 @@ impl<'hir> Map<'hir> {
/// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map.
pub fn get_module_parent(&self, id: NodeId) -> DefId {
let hir_id = self.node_to_hir_id(id);
self.get_module_parent_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId {
pub fn get_module_parent(&self, id: HirId) -> DefId {
self.local_def_id_from_hir_id(self.get_module_parent_node(id))
}
@ -901,23 +860,11 @@ impl<'hir> Map<'hir> {
Some(scope)
}
pub fn get_parent_did(&self, id: NodeId) -> DefId {
let hir_id = self.node_to_hir_id(id);
self.get_parent_did_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId {
pub fn get_parent_did(&self, id: HirId) -> DefId {
self.local_def_id_from_hir_id(self.get_parent_item(id))
}
pub fn get_foreign_abi(&self, id: NodeId) -> Abi {
let hir_id = self.node_to_hir_id(id);
self.get_foreign_abi_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn get_foreign_abi_by_hir_id(&self, hir_id: HirId) -> Abi {
pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi {
let parent = self.get_parent_item(hir_id);
if let Some(entry) = self.find_entry(parent) {
if let Entry {
@ -927,33 +874,27 @@ impl<'hir> Map<'hir> {
return nm.abi;
}
}
bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent))
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
}
pub fn expect_item(&self, id: NodeId) -> &'hir Item {
let hir_id = self.node_to_hir_id(id);
self.expect_item_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item {
pub fn expect_item(&self, id: HirId) -> &'hir Item {
match self.find_by_hir_id(id) { // read recorded by `find`
Some(Node::Item(item)) => item,
_ => bug!("expected item, found {}", self.hir_to_string(id))
_ => bug!("expected item, found {}", self.node_to_string(id))
}
}
pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem {
match self.find_by_hir_id(id) {
Some(Node::ImplItem(item)) => item,
_ => bug!("expected impl item, found {}", self.hir_to_string(id))
_ => bug!("expected impl item, found {}", self.node_to_string(id))
}
}
pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem {
match self.find_by_hir_id(id) {
Some(Node::TraitItem(item)) => item,
_ => bug!("expected trait item, found {}", self.hir_to_string(id))
_ => bug!("expected trait item, found {}", self.node_to_string(id))
}
}
@ -963,26 +904,26 @@ impl<'hir> Map<'hir> {
match i.node {
ItemKind::Struct(ref struct_def, _) |
ItemKind::Union(ref struct_def, _) => struct_def,
_ => bug!("struct ID bound to non-struct {}", self.hir_to_string(id))
_ => bug!("struct ID bound to non-struct {}", self.node_to_string(id))
}
}
Some(Node::Variant(variant)) => &variant.node.data,
Some(Node::Ctor(data)) => data,
_ => bug!("expected struct or variant, found {}", self.hir_to_string(id))
_ => bug!("expected struct or variant, found {}", self.node_to_string(id))
}
}
pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
match self.find_by_hir_id(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.hir_to_string(id)),
_ => bug!("expected variant, found {}", self.node_to_string(id)),
}
}
pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
match self.find_by_hir_id(id) {
Some(Node::ForeignItem(item)) => item,
_ => bug!("expected foreign item, found {}", self.hir_to_string(id))
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
}
}
@ -995,7 +936,7 @@ impl<'hir> Map<'hir> {
pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr {
match self.find_by_hir_id(id) { // read recorded by find
Some(Node::Expr(expr)) => expr,
_ => bug!("expected expr, found {}", self.hir_to_string(id))
_ => bug!("expected expr, found {}", self.node_to_string(id))
}
}
@ -1018,19 +959,13 @@ impl<'hir> Map<'hir> {
Node::GenericParam(param) => param.name.ident().name,
Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name,
Node::Ctor(..) => self.name_by_hir_id(self.get_parent_item(id)),
_ => bug!("no name for {}", self.hir_to_string(id))
_ => bug!("no name for {}", self.node_to_string(id))
}
}
/// Given a node ID, gets a list of attributes associated with the AST
/// corresponding to the node-ID.
pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] {
let hir_id = self.node_to_hir_id(id);
self.attrs_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] {
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
self.read(id); // reveals attributes on the node
let attrs = match self.find_entry(id).map(|entry| entry.node) {
Some(Node::Local(l)) => Some(&l.attrs[..]),
@ -1046,7 +981,7 @@ impl<'hir> Map<'hir> {
Some(Node::GenericParam(param)) => Some(&param.attrs[..]),
// Unit/tuple structs/variants take the attributes straight from
// the struct/variant definition.
Some(Node::Ctor(..)) => return self.attrs_by_hir_id(self.get_parent_item(id)),
Some(Node::Ctor(..)) => return self.attrs(self.get_parent_item(id)),
Some(Node::Crate) => Some(&self.forest.krate.attrs[..]),
_ => None
};
@ -1093,13 +1028,7 @@ impl<'hir> Map<'hir> {
})
}
pub fn span(&self, id: NodeId) -> Span {
let hir_id = self.node_to_hir_id(id);
self.span_by_hir_id(hir_id)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn span_by_hir_id(&self, hir_id: HirId) -> Span {
pub fn span(&self, hir_id: HirId) -> Span {
self.read(hir_id); // reveals span from node
match self.find_entry(hir_id).map(|entry| entry.node) {
Some(Node::Item(item)) => item.span,
@ -1139,32 +1068,17 @@ impl<'hir> Map<'hir> {
}
pub fn span_if_local(&self, id: DefId) -> Option<Span> {
self.as_local_node_id(id).map(|id| self.span(id))
self.as_local_hir_id(id).map(|id| self.span(id))
}
pub fn node_to_string(&self, id: NodeId) -> String {
hir_id_to_string(self, self.node_to_hir_id(id), true)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn hir_to_string(&self, id: HirId) -> String {
pub fn node_to_string(&self, id: HirId) -> String {
hir_id_to_string(self, id, true)
}
pub fn node_to_user_string(&self, id: NodeId) -> String {
hir_id_to_string(self, self.node_to_hir_id(id), false)
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn hir_to_user_string(&self, id: HirId) -> String {
hir_id_to_string(self, id, false)
}
pub fn node_to_pretty_string(&self, id: NodeId) -> String {
print::to_string(self, |s| s.print_node(self.get(id)))
}
// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn hir_to_pretty_string(&self, id: HirId) -> String {
print::to_string(self, |s| s.print_node(self.get_by_hir_id(id)))
}
@ -1307,7 +1221,7 @@ pub fn map_crate<'hir>(sess: &crate::session::Session,
impl<'hir> print::PpAnn for Map<'hir> {
fn nested(&self, state: &mut print::State<'_>, nested: print::Nested) -> io::Result<()> {
match nested {
Nested::Item(id) => state.print_item(self.expect_item_by_hir_id(id.id)),
Nested::Item(id) => state.print_item(self.expect_item(id.id)),
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)),
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
Nested::Body(id) => state.print_expr(&self.body(id).value),

View file

@ -2177,8 +2177,8 @@ pub enum UseKind {
/// References to traits in impls.
///
/// `resolve` maps each `TraitRef`'s `ref_id` to its defining trait; that's all
/// that the `ref_id` is for. Note that `ref_id`'s value is not the `NodeId` of the
/// trait being referred to but just a unique `NodeId` that serves as a key
/// that the `ref_id` is for. Note that `ref_id`'s value is not the `HirId` of the
/// trait being referred to but just a unique `HirId` that serves as a key
/// within the resolution map.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct TraitRef {

View file

@ -14,8 +14,8 @@ pub fn provide(providers: &mut Providers<'_>) {
return None;
}
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(node_id)?);
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(hir_id)?);
let mut local_collector = LocalCollector::default();
local_collector.visit_body(body);

View file

@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> {
)
};
let span = scope.span(self, region_scope_tree);
let tag = match self.hir().find(scope.node_id(self, region_scope_tree)) {
let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) {
Some(Node::Block(_)) => "block",
Some(Node::Expr(expr)) => match expr.node {
hir::ExprKind::Call(..) => "call",
@ -191,7 +191,7 @@ impl<'tcx> TyCtxt<'tcx> {
};
let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
let mut sp = cm.def_span(self.hir().span(node));
if let Some(param) = self.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(br.name))
@ -204,7 +204,7 @@ impl<'tcx> TyCtxt<'tcx> {
bound_region: ty::BoundRegion::BrNamed(_, name),
..
}) => {
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
let mut sp = cm.def_span(self.hir().span(node));
if let Some(param) = self.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(name))
@ -216,11 +216,11 @@ impl<'tcx> TyCtxt<'tcx> {
ty::ReFree(ref fr) => match fr.bound_region {
ty::BrAnon(idx) => (
format!("the anonymous lifetime #{} defined on", idx + 1),
self.hir().span_by_hir_id(node),
self.hir().span(node),
),
_ => (
format!("the lifetime {} as defined on", region),
cm.def_span(self.hir().span_by_hir_id(node)),
cm.def_span(self.hir().span(node)),
),
},
_ => bug!(),
@ -1330,12 +1330,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if !param.is_self() {
let type_param = generics.type_param(param, self.tcx);
let hir = &self.tcx.hir();
hir.as_local_node_id(type_param.def_id).map(|id| {
hir.as_local_hir_id(type_param.def_id).map(|id| {
// Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case.
let mut has_bounds = false;
if let Node::GenericParam(ref param) = hir.get(id) {
if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) {
has_bounds = !param.bounds.is_empty();
}
let sp = hir.span(id);

View file

@ -28,8 +28,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
) -> Option<(&hir::Ty, &hir::FnDecl)> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let def_id = anon_reg.def_id;
if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) {
let fndecl = match self.tcx().hir().get(node_id) {
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) {
let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) {
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(ref fndecl, ..),
..

View file

@ -48,11 +48,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
let hir = &self.tcx().hir();
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
if let Some(hir_id) = hir.as_local_hir_id(free_region.scope) {
if let Node::Expr(Expr {
node: Closure(_, _, _, closure_span, None),
..
}) = hir.get(node_id) {
}) = hir.get_by_hir_id(hir_id) {
let sup_sp = sup_origin.span();
let origin_sp = origin.span();
let mut err = self.tcx().sess.struct_span_err(

View file

@ -51,11 +51,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
};
let hir = &self.tcx().hir();
if let Some(node_id) = hir.as_local_node_id(id) {
if let Some(body_id) = hir.maybe_body_owned_by(node_id) {
if let Some(hir_id) = hir.as_local_hir_id(id) {
if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
let body = hir.body(body_id);
let owner_id = hir.body_owner(body_id);
let fn_decl = hir.fn_decl(owner_id).unwrap();
let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap();
if let Some(tables) = self.tables {
body.arguments
.iter()
@ -63,7 +63,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
.filter_map(|(index, arg)| {
// May return None; sometimes the tables are not yet populated.
let ty_hir_id = fn_decl.inputs[index].hir_id;
let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id));
let arg_ty_span = hir.span(ty_hir_id);
let ty = tables.node_type_opt(arg.hir_id)?;
let mut found_anon_region = false;
let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {

View file

@ -819,7 +819,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
},
_ => bug!(
"expected (impl) item, found {}",
tcx.hir().hir_to_string(opaque_hir_id),
tcx.hir().node_to_string(opaque_hir_id),
),
};
if in_definition_scope {

View file

@ -1399,7 +1399,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
// Visit the crate attributes
if hir_id == hir::CRATE_HIR_ID {
walk_list!(cx, visit_attribute, tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID));
walk_list!(cx, visit_attribute, tcx.hir().attrs(hir::CRATE_HIR_ID));
}
}

View file

@ -762,7 +762,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
}
pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
let attrs = tcx.hir().attrs_by_hir_id(id);
let attrs = tcx.hir().attrs(id);
attrs.iter().any(|attr| Level::from_symbol(attr.name_or_empty()).is_some())
}

View file

@ -292,7 +292,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
match ty.node {
TyKind::Def(item_id, _) => {
let item = self.tcx.hir().expect_item_by_hir_id(item_id.id);
let item = self.tcx.hir().expect_item(item_id.id);
intravisit::walk_item(self, item);
}
_ => ()

View file

@ -1171,7 +1171,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
hir::ExprKind::Call(ref f, ref args) => {
let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id);
let m = self.ir.tcx.hir().get_module_parent(expr.hir_id);
let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) {
self.s.exit_ln
} else {
@ -1182,7 +1182,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
hir::ExprKind::MethodCall(.., ref args) => {
let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id);
let m = self.ir.tcx.hir().get_module_parent(expr.hir_id);
let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) {
self.s.exit_ln
} else {

View file

@ -342,9 +342,9 @@ impl MutabilityCategory {
fn from_local(
tcx: TyCtxt<'_>,
tables: &ty::TypeckTables<'_>,
id: ast::NodeId,
id: hir::HirId,
) -> MutabilityCategory {
let ret = match tcx.hir().get(id) {
let ret = match tcx.hir().get_by_hir_id(id) {
Node::Binding(p) => match p.node {
PatKind::Binding(..) => {
let bm = *tables.pat_binding_modes()
@ -500,7 +500,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
// FIXME
None if self.is_tainted_by_errors() => Err(()),
None => {
let id = self.tcx.hir().hir_to_node_id(id);
bug!("no type for node {}: {} in mem_categorization",
id, self.tcx.hir().node_to_string(id));
}
@ -753,15 +752,14 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
}
Res::Local(var_id) => {
let var_nid = self.tcx.hir().hir_to_node_id(var_id);
if self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
self.cat_upvar(hir_id, span, var_nid)
self.cat_upvar(hir_id, span, var_id)
} else {
Ok(cmt_ {
hir_id,
span,
cat: Categorization::Local(var_id),
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_nid),
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_id),
ty: expr_ty,
note: NoteNone
})
@ -778,7 +776,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
&self,
hir_id: hir::HirId,
span: Span,
var_id: ast::NodeId,
var_id: hir::HirId,
) -> McResult<cmt_<'tcx>> {
// An upvar can have up to 3 components. We translate first to a
// `Categorization::Upvar`, which is itself a fiction -- it represents the reference to the
@ -828,13 +826,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),
};
let var_hir_id = self.tcx.hir().node_to_hir_id(var_id);
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
var_path: ty::UpvarPath { hir_id: var_id },
closure_expr_id: closure_expr_def_id.to_local(),
};
let var_ty = self.node_ty(var_hir_id)?;
let var_ty = self.node_ty(var_id)?;
// Mutability of original variable itself
let var_mutbl = MutabilityCategory::from_local(self.tcx, self.tables, var_id);

View file

@ -174,12 +174,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
} else {
let impl_did = self.tcx
.hir()
.get_parent_did_by_hir_id(hir_id);
.get_parent_did(hir_id);
// Check the impl. If the generics on the self
// type of the impl require inlining, this method
// does too.
let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap();
match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node {
match self.tcx.hir().expect_item(impl_hir_id).node {
hir::ItemKind::Impl(..) => {
let generics = self.tcx.generics_of(impl_did);
generics.requires_monomorphization(self.tcx)
@ -296,7 +296,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
self.visit_nested_body(body);
}
hir::ImplItemKind::Method(_, body) => {
let did = self.tcx.hir().get_parent_did_by_hir_id(search_item);
let did = self.tcx.hir().get_parent_did(search_item);
if method_might_be_inlined(self.tcx, impl_item, did) {
self.visit_nested_body(body)
}
@ -318,7 +318,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
_ => {
bug!(
"found unexpected node kind in worklist: {} ({:?})",
self.tcx.hir().hir_to_string(search_item),
self.tcx.hir().node_to_string(search_item),
node,
);
}

View file

@ -14,7 +14,6 @@ use std::mem;
use std::fmt;
use rustc_macros::HashStable;
use syntax::source_map;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
use crate::ty::{DefIdTree, TyCtxt};
use crate::ty::query::Providers;
@ -169,15 +168,15 @@ impl Scope {
self.id
}
pub fn node_id(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> ast::NodeId {
pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId {
match scope_tree.root_body {
Some(hir_id) => {
tcx.hir().hir_to_node_id(hir::HirId {
hir::HirId {
owner: hir_id.owner,
local_id: self.item_local_id()
})
}
}
None => ast::DUMMY_NODE_ID
None => hir::DUMMY_HIR_ID
}
}
@ -185,13 +184,13 @@ impl Scope {
/// returned span may not correspond to the span of any `NodeId` in
/// the AST.
pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span {
let node_id = self.node_id(tcx, scope_tree);
if node_id == ast::DUMMY_NODE_ID {
let hir_id = self.hir_id(scope_tree);
if hir_id == hir::DUMMY_HIR_ID {
return DUMMY_SP;
}
let span = tcx.hir().span(node_id);
let span = tcx.hir().span(hir_id);
if let ScopeData::Remainder(first_statement_index) = self.data {
if let Node::Block(ref blk) = tcx.hir().get(node_id) {
if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) {
// Want span for scope starting after the
// indexed statement and ending at end of
// `blk`; reuse span of `blk` and shift `lo`
@ -650,7 +649,7 @@ impl<'tcx> ScopeTree {
let param_owner = tcx.parent(br.def_id).unwrap();
let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap();
let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| {
let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| {
tcx.hir().body(body_id).value.hir_id.local_id
}).unwrap_or_else(|| {
// The lifetime was defined on node that doesn't own a body,
@ -1337,7 +1336,7 @@ fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ScopeTree
}
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by_by_hir_id(id) {
let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) {
let mut visitor = RegionResolutionVisitor {
tcx,
scope_tree: ScopeTree::default(),

View file

@ -625,7 +625,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// `abstract type MyAnonTy<'b>: MyTrait<'b>;`
// ^ ^ this gets resolved in the scope of
// the exist_ty generics
let (generics, bounds) = match self.tcx.hir().expect_item_by_hir_id(item_id.id).node
let (generics, bounds) = match self.tcx.hir().expect_item(item_id.id).node
{
// named existential types are reached via TyKind::Path
// this arm is for `impl Trait` in the types of statics, constants and locals
@ -1236,7 +1236,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
signal_shadowing_problem(
tcx,
label.name,
original_lifetime(tcx.hir().span_by_hir_id(hir_id)),
original_lifetime(tcx.hir().span(hir_id)),
shadower_label(label.span),
);
return;
@ -1590,7 +1590,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if let Some(parent_hir_id) = self.tcx.hir()
.as_local_hir_id(parent_def_id) {
// lifetimes in `derive` expansions don't count (Issue #53738)
if self.tcx.hir().attrs_by_hir_id(parent_hir_id).iter()
if self.tcx.hir().attrs(parent_hir_id).iter()
.any(|attr| attr.check_name(sym::automatically_derived)) {
continue;
}
@ -1690,7 +1690,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// Find the start of nested early scopes, e.g., in methods.
let mut index = 0;
if let Some(parent_id) = parent_id {
let parent = self.tcx.hir().expect_item_by_hir_id(parent_id);
let parent = self.tcx.hir().expect_item(parent_id);
if sub_items_have_self_param(&parent.node) {
index += 1; // Self comes before lifetimes
}
@ -1823,7 +1823,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
// Do not free early-bound regions, only late-bound ones.
} else if let Some(body_id) = outermost_body {
let fn_id = self.tcx.hir().body_owner(body_id);
match self.tcx.hir().get(fn_id) {
match self.tcx.hir().get_by_hir_id(fn_id) {
Node::Item(&hir::Item {
node: hir::ItemKind::Fn(..),
..
@ -1836,7 +1836,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
node: hir::ImplItemKind::Method(..),
..
}) => {
let scope = self.tcx.hir().local_def_id(fn_id);
let scope = self.tcx.hir().local_def_id_from_hir_id(fn_id);
def = Region::Free(scope, def.id().unwrap());
}
_ => {}
@ -2065,7 +2065,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}) => {
if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx
.hir()
.expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent))
.expect_item(self.tcx.hir().get_parent_item(parent))
.node
{
assoc_item_kind = trait_items
@ -2085,7 +2085,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}) => {
if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx
.hir()
.expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent))
.expect_item(self.tcx.hir().get_parent_item(parent))
.node
{
impl_self = Some(self_ty);
@ -2629,7 +2629,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
signal_shadowing_problem(
self.tcx,
param.name.ident().name,
original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)),
original_lifetime(self.tcx.hir().span(hir_id)),
shadower_lifetime(&param),
);
return;
@ -2696,7 +2696,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
debug!(
"insert_lifetime: {} resolved to {:?} span={:?}",
self.tcx.hir().hir_to_string(lifetime_ref.hir_id),
self.tcx.hir().node_to_string(lifetime_ref.hir_id),
def,
self.tcx.sess.source_map().span_to_string(lifetime_ref.span)
);

View file

@ -2565,7 +2565,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
format!("[closure@{:?}]", hir_id)
} else {
format!("[closure@{:?}]", tcx.hir().span_by_hir_id(hir_id))
format!("[closure@{:?}]", tcx.hir().span(hir_id))
};
let mut struct_fmt = fmt.debug_struct(&name);
@ -2585,7 +2585,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
let name = format!("[generator@{:?}]",
tcx.hir().span_by_hir_id(hir_id));
tcx.hir().span(hir_id));
let mut struct_fmt = fmt.debug_struct(&name);
if let Some(upvars) = tcx.upvars(def_id) {

View file

@ -218,7 +218,7 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::GlobalAsm(hir_id) => {
Some(hir_id)
}
}.map(|hir_id| tcx.hir().span_by_hir_id(hir_id))
}.map(|hir_id| tcx.hir().span(hir_id))
}
}

View file

@ -1013,10 +1013,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
) {
let hir = self.tcx.hir();
let parent_node = hir.get_parent_node(
hir.hir_to_node_id(obligation.cause.body_id),
);
let node = hir.find(parent_node);
let parent_node = hir.get_parent_node_by_hir_id(obligation.cause.body_id);
let node = hir.find_by_hir_id(parent_node);
if let Some(hir::Node::Item(hir::Item {
node: hir::ItemKind::Fn(decl, _, _, body_id),
..
@ -1098,7 +1096,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
Node::Ctor(ref variant_data) => {
let span = variant_data.ctor_hir_id()
.map(|hir_id| self.tcx.hir().span_by_hir_id(hir_id))
.map(|hir_id| self.tcx.hir().span(hir_id))
.unwrap_or(DUMMY_SP);
let span = self.tcx.sess.source_map().def_span(span);

View file

@ -654,7 +654,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn impl_is_default(self, node_item_def_id: DefId) -> bool {
match self.hir().as_local_hir_id(node_item_def_id) {
Some(hir_id) => {
let item = self.hir().expect_item_by_hir_id(hir_id);
let item = self.hir().expect_item(hir_id);
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node {
defaultness.is_default()
} else {

View file

@ -250,11 +250,9 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
if let Some(local_id_root) = local_id_root {
if hir_id.owner != local_id_root.index {
ty::tls::with(|tcx| {
let node_id = tcx.hir().hir_to_node_id(hir_id);
bug!("node {} with HirId::owner {:?} cannot be placed in \
TypeckTables with local_id_root {:?}",
tcx.hir().node_to_string(node_id),
tcx.hir().node_to_string(hir_id),
DefId::local(hir_id.owner),
local_id_root)
});
@ -556,7 +554,7 @@ impl<'tcx> TypeckTables<'tcx> {
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
self.node_type_opt(id).unwrap_or_else(||
bug!("node_type: no type for node `{}`",
tls::with(|tcx| tcx.hir().hir_to_string(id)))
tls::with(|tcx| tcx.hir().node_to_string(id)))
)
}

View file

@ -277,7 +277,7 @@ impl Visibility {
def => Visibility::Restricted(def.def_id()),
},
hir::VisibilityKind::Inherited => {
Visibility::Restricted(tcx.hir().get_module_parent_by_hir_id(id))
Visibility::Restricted(tcx.hir().get_module_parent(id))
}
}
}
@ -3016,7 +3016,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Gets the attributes of a definition.
pub fn get_attrs(self, did: DefId) -> Attributes<'tcx> {
if let Some(id) = self.hir().as_local_hir_id(did) {
Attributes::Borrowed(self.hir().attrs_by_hir_id(id))
Attributes::Borrowed(self.hir().attrs(id))
} else {
Attributes::Owned(self.item_attrs(did))
}
@ -3068,7 +3068,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn span_of_impl(self, impl_did: DefId) -> Result<Span, Symbol> {
if impl_did.is_local() {
let hir_id = self.hir().as_local_hir_id(impl_did).unwrap();
Ok(self.hir().span_by_hir_id(hir_id))
Ok(self.hir().span(hir_id))
} else {
Err(self.crate_name(impl_did.krate))
}
@ -3103,7 +3103,7 @@ impl<'tcx> TyCtxt<'tcx> {
let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
Some(actual_expansion) =>
self.hir().definitions().parent_module_of_macro_def(actual_expansion),
None => self.hir().get_module_parent_by_hir_id(block),
None => self.hir().get_module_parent(block),
};
(ident, scope)
}
@ -3129,7 +3129,7 @@ fn associated_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AssocItem {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let parent_id = tcx.hir().get_parent_item(id);
let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id);
let parent_item = tcx.hir().expect_item_by_hir_id(parent_id);
let parent_item = tcx.hir().expect_item(parent_id);
match parent_item.node {
hir::ItemKind::Impl(.., ref impl_item_refs) => {
if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.hir_id == id) {
@ -3186,7 +3186,7 @@ fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AdtSizedConst
fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [DefId] {
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(id);
let item = tcx.hir().expect_item(id);
match item.node {
hir::ItemKind::Trait(.., ref trait_item_refs) => {
tcx.arena.alloc_from_iter(
@ -3266,7 +3266,7 @@ fn param_env<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ParamEnv<'tcx> {
);
let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| {
tcx.hir().maybe_body_owned_by_by_hir_id(id).map_or(id, |body| body.hir_id)
tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id)
});
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)

View file

@ -589,7 +589,7 @@ pub trait PrettyPrinter<'tcx>:
// FIXME(eddyb) should use `def_span`.
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id)));
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
let mut sep = " ";
for (&var_id, upvar_ty) in self.tcx().upvars(did)
.as_ref()
@ -631,7 +631,7 @@ pub trait PrettyPrinter<'tcx>:
if self.tcx().sess.opts.debugging_opts.span_free_formats {
p!(write("@{:?}", hir_id));
} else {
p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id)));
p!(write("@{:?}", self.tcx().hir().span(hir_id)));
}
let mut sep = " ";
for (&var_id, upvar_ty) in self.tcx().upvars(did)

View file

@ -88,7 +88,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
}
}
if let NoteClosureEnv(upvar_id) = error.move_from.note {
err.span_label(bccx.tcx.hir().span_by_hir_id(upvar_id.var_path.hir_id),
err.span_label(bccx.tcx.hir().span(upvar_id.var_path.hir_id),
"captured outer variable");
}
err.emit();

View file

@ -198,7 +198,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
cfg: &cfg::CFG,
) -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>) {
let owner_id = tcx.hir().body_owner(body_id);
let owner_def_id = tcx.hir().local_def_id(owner_id);
let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_id);
let tables = tcx.typeck_tables_of(owner_def_id);
let region_scope_tree = tcx.region_scope_tree(owner_def_id);
let body = tcx.hir().body(body_id);
@ -389,8 +389,8 @@ pub enum LoanPathElem<'tcx> {
}
fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_>) -> HirId {
let closure_id = tcx.hir().local_def_id_to_node_id(closure_id);
match tcx.hir().get(closure_id) {
let closure_id = tcx.hir().local_def_id_to_hir_id(closure_id);
match tcx.hir().get_by_hir_id(closure_id) {
Node::Expr(expr) => match expr.node {
hir::ExprKind::Closure(.., body_id, _, _) => {
body_id.hir_id
@ -699,7 +699,7 @@ impl BorrowckCtxt<'_, 'tcx> {
}
move_data::MoveExpr |
move_data::MovePat => (self.tcx.hir().span_by_hir_id(hir_id), ""),
move_data::MovePat => (self.tcx.hir().span(hir_id), ""),
move_data::Captured =>
(match self.tcx.hir().expect_expr_by_hir_id(hir_id).node {
@ -828,7 +828,7 @@ impl BorrowckCtxt<'_, 'tcx> {
let mut db = self.cannot_assign(error_span, &descr, Origin::Ast);
if let mc::NoteClosureEnv(upvar_id) = err.cmt.note {
let hir_id = upvar_id.var_path.hir_id;
let sp = self.tcx.hir().span_by_hir_id(hir_id);
let sp = self.tcx.hir().span(hir_id);
let fn_closure_msg = "`Fn` closures cannot capture their enclosing \
environment for modifications";
match (self.tcx.sess.source_map().span_to_snippet(sp), &err.cmt.cat) {
@ -896,8 +896,7 @@ impl BorrowckCtxt<'_, 'tcx> {
// to implement two traits for "one operator" is not very intuitive for
// many programmers.
if err.cmt.note == mc::NoteIndex {
let node_id = self.tcx.hir().hir_to_node_id(err.cmt.hir_id);
let node = self.tcx.hir().get(node_id);
let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id);
// This pattern probably always matches.
if let Node::Expr(
@ -1022,8 +1021,8 @@ impl BorrowckCtxt<'_, 'tcx> {
}
if let ty::ReScope(scope) = *super_scope {
let node_id = scope.node_id(self.tcx, &self.region_scope_tree);
match self.tcx.hir().find(node_id) {
let hir_id = scope.hir_id(&self.region_scope_tree);
match self.tcx.hir().find_by_hir_id(hir_id) {
Some(Node::Stmt(_)) => {
if *sub_scope != ty::ReStatic {
db.note("consider using a `let` binding to increase its lifetime");
@ -1118,7 +1117,7 @@ impl BorrowckCtxt<'_, 'tcx> {
"consider changing this closure to take self by mutable reference"
};
let hir_id = self.tcx.hir().local_def_id_to_hir_id(id);
let help_span = self.tcx.hir().span_by_hir_id(hir_id);
let help_span = self.tcx.hir().span(hir_id);
self.cannot_act_on_capture_in_sharable_fn(span,
prefix,
(help_span, help_msg),
@ -1224,7 +1223,7 @@ impl BorrowckCtxt<'_, 'tcx> {
Some(ImmutabilityBlame::LocalDeref(hir_id)) => {
match self.local_binding_mode(hir_id) {
ty::BindByReference(..) => {
let let_span = self.tcx.hir().span_by_hir_id(hir_id);
let let_span = self.tcx.hir().span(hir_id);
let suggestion = suggest_ref_mut(self.tcx, let_span);
if let Some(replace_str) = suggestion {
db.span_suggestion(
@ -1272,7 +1271,7 @@ impl BorrowckCtxt<'_, 'tcx> {
db: &mut DiagnosticBuilder<'_>,
borrowed_hir_id: hir::HirId,
binding_hir_id: hir::HirId) {
let let_span = self.tcx.hir().span_by_hir_id(binding_hir_id);
let let_span = self.tcx.hir().span(binding_hir_id);
if let ty::BindByValue(..) = self.local_binding_mode(binding_hir_id) {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(let_span) {
let (ty, is_implicit_self) = self.local_ty(binding_hir_id);
@ -1290,7 +1289,7 @@ impl BorrowckCtxt<'_, 'tcx> {
{
let borrow_expr_id = self.tcx.hir().get_parent_node_by_hir_id(borrowed_hir_id);
db.span_suggestion(
self.tcx.hir().span_by_hir_id(borrow_expr_id),
self.tcx.hir().span(borrow_expr_id),
"consider removing the `&mut`, as it is an \
immutable binding to a mutable reference",
snippet,
@ -1361,7 +1360,7 @@ impl BorrowckCtxt<'_, 'tcx> {
if *kind == ty::ClosureKind::Fn {
let closure_hir_id =
self.tcx.hir().local_def_id_to_hir_id(upvar_id.closure_expr_id);
db.span_help(self.tcx.hir().span_by_hir_id(closure_hir_id),
db.span_help(self.tcx.hir().span(closure_hir_id),
"consider changing this closure to take \
self by mutable reference");
}
@ -1370,7 +1369,7 @@ impl BorrowckCtxt<'_, 'tcx> {
if let Categorization::Deref(..) = err.cmt.cat {
db.span_label(*error_span, "cannot borrow as mutable");
} else if let Categorization::Local(local_id) = err.cmt.cat {
let span = self.tcx.hir().span_by_hir_id(local_id);
let span = self.tcx.hir().span(local_id);
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
if snippet.starts_with("ref mut ") || snippet.starts_with("&mut ") {
db.span_label(*error_span, "cannot reborrow mutably");
@ -1509,13 +1508,12 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
LpVar(id) => {
write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().hir_to_string(id)))
write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_string(id)))
}
LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => {
let s = ty::tls::with(|tcx| {
let var_node_id = tcx.hir().hir_to_node_id(var_id);
tcx.hir().node_to_string(var_node_id)
tcx.hir().node_to_string(var_id)
});
write!(f, "$({} captured by id={:?})", s, closure_expr_id)
}
@ -1549,8 +1547,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> {
LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => {
let s = ty::tls::with(|tcx| {
let var_node_id = tcx.hir().hir_to_node_id(hir_id);
tcx.hir().node_to_string(var_node_id)
tcx.hir().node_to_string(hir_id)
});
write!(f, "$({} captured by closure)", s)
}

View file

@ -29,7 +29,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
}
MonoItem::GlobalAsm(hir_id) => {
let item = cx.tcx().hir().expect_item_by_hir_id(hir_id);
let item = cx.tcx().hir().expect_item(hir_id);
if let hir::ItemKind::GlobalAsm(ref ga) = item.node {
cx.codegen_global_asm(ga);
} else {

View file

@ -922,7 +922,8 @@ fn print_with_analysis<'tcx>(
got {:?}",
node);
tcx.sess.span_fatal(tcx.hir().span(nodeid), &message)
let hir_id = tcx.hir().node_to_hir_id(nodeid);
tcx.sess.span_fatal(tcx.hir().span(hir_id), &message)
}
}
}

View file

@ -254,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
Some(Ident::from_str(name))
} else {
attr::find_by_name(&cx.tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID), sym::crate_name)
attr::find_by_name(&cx.tcx.hir().attrs(hir::CRATE_HIR_ID), sym::crate_name)
.and_then(|attr| attr.meta())
.and_then(|meta| {
meta.name_value_literal().and_then(|lit| {

View file

@ -921,7 +921,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes {
fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) {
let mut vis = ImproperCTypesVisitor { cx };
let abi = cx.tcx.hir().get_foreign_abi_by_hir_id(it.hir_id);
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id);
if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic {
match it.node {
hir::ForeignItemKind::Fn(ref decl, _, _) => {

View file

@ -136,7 +136,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
descr_post_path: &str,
) -> bool {
if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(
cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty)
cx.tcx.hir().get_module_parent(expr.hir_id), ty)
{
return true;
}

View file

@ -579,7 +579,7 @@ impl EncodeContext<'tcx> {
};
let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap();
let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis;
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
Entry {
kind: EntryKind::Variant(self.lazy(&data)),
@ -632,7 +632,7 @@ impl EncodeContext<'tcx> {
// Variant constructors have the same visibility as the parent enums, unless marked as
// non-exhaustive, in which case they are lowered to `pub(crate)`.
let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap();
let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis;
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx);
if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public {
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
@ -751,7 +751,7 @@ impl EncodeContext<'tcx> {
};
let struct_id = tcx.hir().as_local_hir_id(adt_def_id).unwrap();
let struct_vis = &tcx.hir().expect_item_by_hir_id(struct_id).vis;
let struct_vis = &tcx.hir().expect_item(struct_id).vis;
let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx);
for field in &variant.fields {
if ctor_vis.is_at_least(field.vis, tcx) {

View file

@ -177,7 +177,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
));
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure();
let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure();
let borrow_set = Rc::new(BorrowSet::build(
tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));

View file

@ -422,7 +422,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let upvar = &self.upvars[upvar_field.unwrap().index()];
let upvar_hir_id = upvar.var_hir_id;
let upvar_name = upvar.name;
let upvar_span = self.infcx.tcx.hir().span_by_hir_id(upvar_hir_id);
let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id);
let place_name = self.describe_place(move_place).unwrap();

View file

@ -304,8 +304,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(span, format!("cannot {ACT}", ACT = act));
let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id;
let upvar_node_id = self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id);
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_node_id) {
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find_by_hir_id(upvar_hir_id)
{
if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated,
_,

View file

@ -230,14 +230,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
},
ty::BoundRegion::BrEnv => {
let mir_node_id = tcx.hir()
.as_local_node_id(mir_def_id)
.expect("non-local mir");
let mir_hir_id = tcx.hir()
.as_local_hir_id(mir_def_id)
.expect("non-local mir");
let def_ty = self.universal_regions.defining_ty;
if let DefiningTy::Closure(def_id, substs) = def_ty {
let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) =
tcx.hir().expect_expr(mir_node_id).node
tcx.hir().expect_expr_by_hir_id(mir_hir_id).node
{
span
} else {
@ -310,7 +310,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let scope = error_region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(node));
let span = tcx.sess.source_map().def_span(tcx.hir().span(node));
if let Some(param) = tcx.hir()
.get_generics(scope)
.and_then(|generics| generics.get_named(name))
@ -367,8 +367,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
argument_index: usize,
counter: &mut usize,
) -> Option<RegionName> {
let mir_node_id = infcx.tcx.hir().as_local_node_id(mir_def_id)?;
let fn_decl = infcx.tcx.hir().fn_decl(mir_node_id)?;
let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?;
let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?;
let argument_hir_ty: &hir::Ty = &fn_decl.inputs[argument_index];
match argument_hir_ty.node {
// This indicates a variable with no type annotation, like
@ -696,9 +696,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
highlight.highlighting_region_vid(fr, *counter);
let type_name = infcx.extract_type_name(&return_ty, Some(highlight));
let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir");
let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir");
let (return_span, mir_description) = match tcx.hir().get(mir_node_id) {
let (return_span, mir_description) = match tcx.hir().get_by_hir_id(mir_hir_id) {
hir::Node::Expr(hir::Expr {
node: hir::ExprKind::Closure(_, return_ty, _, span, gen_move),
..
@ -759,9 +759,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
highlight.highlighting_region_vid(fr, *counter);
let type_name = infcx.extract_type_name(&yield_ty, Some(highlight));
let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir");
let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir");
let yield_span = match tcx.hir().get(mir_node_id) {
let yield_span = match tcx.hir().get_by_hir_id(mir_hir_id) {
hir::Node::Expr(hir::Expr {
node: hir::ExprKind::Closure(_, _, _, span, _),
..

View file

@ -73,7 +73,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id);
let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id);
let upvar_span = tcx.hir().span_by_hir_id(upvar_hir_id);
let upvar_span = tcx.hir().span(upvar_hir_id);
debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}",
upvar_name, upvar_span);

View file

@ -471,7 +471,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let tcx = self.infcx.tcx;
let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id);
match tcx.hir().body_owner_kind_by_hir_id(self.mir_hir_id) {
match tcx.hir().body_owner_kind(self.mir_hir_id) {
BodyOwnerKind::Closure |
BodyOwnerKind::Fn => {
let defining_ty = if self.mir_def_id == closure_base_def_id {

View file

@ -55,10 +55,10 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> {
(*body_id, ty.span)
}
Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => {
(*body, tcx.hir().span_by_hir_id(*hir_id))
(*body, tcx.hir().span(*hir_id))
}
_ => span_bug!(tcx.hir().span_by_hir_id(id), "can't build MIR for {:?}", def_id),
_ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id),
};
tcx.infer_ctxt().enter(|infcx| {
@ -101,9 +101,9 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> {
let owner_id = tcx.hir().body_owner(body_id);
let opt_ty_info;
let self_arg;
if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) {
if let Some(ref fn_decl) = tcx.hir().fn_decl_by_hir_id(owner_id) {
let ty_hir_id = fn_decl.inputs[index].hir_id;
let ty_span = tcx.hir().span_by_hir_id(ty_hir_id);
let ty_span = tcx.hir().span(ty_hir_id);
opt_ty_info = Some(ty_span);
self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() {
match fn_decl.implicit_self {
@ -131,7 +131,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> {
ty::Generator(gen_def_id, gen_substs, ..) =>
gen_substs.sig(gen_def_id, tcx),
_ =>
span_bug!(tcx.hir().span_by_hir_id(id),
span_bug!(tcx.hir().span(id),
"generator w/o generator type: {:?}", ty),
};
(Some(gen_sig.yield_ty), gen_sig.return_ty)
@ -535,7 +535,7 @@ where
let tcx = hir.tcx();
let tcx_hir = tcx.hir();
let span = tcx_hir.span_by_hir_id(fn_id);
let span = tcx_hir.span(fn_id);
let hir_tables = hir.tables();
let fn_def_id = tcx_hir.local_def_id_from_hir_id(fn_id);

View file

@ -49,7 +49,7 @@ fn mirror_stmts<'a, 'tcx>(
for (index, stmt) in stmts.iter().enumerate() {
let hir_id = stmt.hir_id;
let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id);
let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id));
let stmt_span = StatementSpan(cx.tcx.hir().span(hir_id));
match stmt.node {
hir::StmtKind::Expr(ref expr) |
hir::StmtKind::Semi(ref expr) => {

View file

@ -908,12 +908,13 @@ fn convert_path_expr<'a, 'tcx>(
}
Res::Def(DefKind::ConstParam, def_id) => {
let node_id = cx.tcx.hir().as_local_node_id(def_id).unwrap();
let item_id = cx.tcx.hir().get_parent_node(node_id);
let item_def_id = cx.tcx.hir().local_def_id(item_id);
let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap();
let item_id = cx.tcx.hir().get_parent_node_by_hir_id(hir_id);
let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(item_id);
let generics = cx.tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&cx.tcx.hir().local_def_id(node_id)];
let name = cx.tcx.hir().name(node_id).as_interned_str();
let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
let index = generics.param_def_id_to_index[&local_def_id];
let name = cx.tcx.hir().name_by_hir_id(hir_id).as_interned_str();
let val = ConstValue::Param(ty::ParamConst::new(index, name));
ExprKind::Literal {
literal: cx.tcx.mk_const(

View file

@ -56,7 +56,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
let tcx = infcx.tcx;
let src_def_id = tcx.hir().local_def_id_from_hir_id(src_id);
let tables = tcx.typeck_tables_of(src_def_id);
let body_owner_kind = tcx.hir().body_owner_kind_by_hir_id(src_id);
let body_owner_kind = tcx.hir().body_owner_kind(src_id);
let constness = match body_owner_kind {
hir::BodyOwnerKind::Const |
@ -65,7 +65,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> {
hir::BodyOwnerKind::Fn => hir::Constness::NotConst,
};
let attrs = tcx.hir().attrs_by_hir_id(src_id);
let attrs = tcx.hir().attrs(src_id);
// Some functions always have overflow checks enabled,
// however, they may not get codegen'd, depending on

View file

@ -161,7 +161,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
}
}
let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id);
let module = self.tcx.hir().get_module_parent(scrut.hir_id);
MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| {
let mut have_errors = false;
@ -193,7 +193,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
// Then, if the match has no arms, check whether the scrutinee
// is uninhabited.
let pat_ty = self.tables.node_type(scrut.hir_id);
let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id);
let module = self.tcx.hir().get_module_parent(scrut.hir_id);
let mut def_span = None;
let mut missing_variants = vec![];
if inlined_arms.is_empty() {
@ -261,7 +261,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
}
fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) {
let module = self.tcx.hir().get_module_parent_by_hir_id(pat.hir_id);
let module = self.tcx.hir().get_module_parent(pat.hir_id);
MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| {
let mut patcx = PatternContext::new(self.tcx,
self.param_env.and(self.identity_substs),

View file

@ -175,8 +175,8 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
// Sometimes the index is beyond the number of upvars (seen
// for a generator).
if let Some((&var_hir_id, _)) = upvars.get_index(field) {
let var_node_id = self.ecx.tcx.hir().hir_to_node_id(var_hir_id);
if let hir::Node::Binding(pat) = self.ecx.tcx.hir().get(var_node_id) {
let node = self.ecx.tcx.hir().get_by_hir_id(var_hir_id);
if let hir::Node::Binding(pat) = node {
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
name = Some(ident.name);
}

View file

@ -130,7 +130,7 @@ fn check_fn_for_unconditional_recursion(
// recurs.
if !reached_exit_without_self_call && !self_call_locations.is_empty() {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let sp = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(hir_id));
let sp = tcx.sess.source_map().def_span(tcx.hir().span(hir_id));
let mut db = tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION,
hir_id,
sp,

View file

@ -455,7 +455,7 @@ fn check_recursion_limit<'tcx>(
let error = format!("reached the recursion limit while instantiating `{}`",
instance);
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &error);
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);
} else {
tcx.sess.fatal(&error);
}

View file

@ -193,7 +193,7 @@ pub trait MonoItemExt<'tcx>: fmt::Debug {
MonoItem::GlobalAsm(hir_id) => {
Some(hir_id)
}
}.map(|hir_id| tcx.hir().span_by_hir_id(hir_id))
}.map(|hir_id| tcx.hir().span(hir_id))
}
}

View file

@ -488,7 +488,7 @@ fn check_unused_unsafe<'a, 'tcx>(
) {
let body_id =
tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| {
tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)
tcx.hir().maybe_body_owned_by(hir_id)
});
let body_id = match body_id {
@ -527,7 +527,7 @@ fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> UnsafetyChec
let param_env = tcx.param_env(def_id);
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind_by_hir_id(id) {
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
hir::BodyOwnerKind::Closure => (false, false),
hir::BodyOwnerKind::Fn => (tcx.is_const_fn(def_id), tcx.is_min_const_fn(def_id)),
hir::BodyOwnerKind::Const |
@ -591,12 +591,12 @@ fn is_enclosed(
}
fn report_unused_unsafe(tcx: TyCtxt<'_>, used_unsafe: &FxHashSet<hir::HirId>, id: hir::HirId) {
let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id));
let span = tcx.sess.source_map().def_span(tcx.hir().span(id));
let msg = "unnecessary `unsafe` block";
let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg);
db.span_label(span, msg);
if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) {
db.span_label(tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)),
db.span_label(tcx.sess.source_map().def_span(tcx.hir().span(id)),
format!("because it's nested under this `unsafe` {}", kind));
}
db.emit();

View file

@ -70,7 +70,7 @@ impl Inliner<'tcx> {
// Only do inlining into fn bodies.
let id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap();
if self.tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure()
if self.tcx.hir().body_owner_kind(id).is_fn_or_closure()
&& self.source.promoted.is_none()
{
for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated() {

View file

@ -208,7 +208,7 @@ fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal<Body<'tcx>>
fn mir_validated(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal<Body<'tcx>> {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(hir_id) {
if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind(hir_id) {
// Ensure that we compute the `mir_const_qualif` for constants at
// this point, before we steal the mir-const result.
let _ = tcx.mir_const_qualif(def_id);

View file

@ -1503,7 +1503,7 @@ impl MirPass for QualifyAndPromoteConstants {
let def_id = src.def_id();
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let mut const_promoted_temps = None;
let mode = match tcx.hir().body_owner_kind_by_hir_id(id) {
let mode = match tcx.hir().body_owner_kind(id) {
hir::BodyOwnerKind::Closure => Mode::NonConstFn,
hir::BodyOwnerKind::Fn => {
if tcx.is_const_fn(def_id) {

View file

@ -165,7 +165,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability {
let item_id = self.tcx.hir().body_owner(body_id);
let item_def_id = self.tcx.hir().local_def_id(item_id);
let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id);
let outer_in_fn = self.in_fn;
let outer_tables = self.tables;

View file

@ -233,7 +233,7 @@ fn def_id_visibility<'tcx>(
Node::Item(item) => &item.vis,
Node::ForeignItem(foreign_item) => &foreign_item.vis,
Node::TraitItem(..) | Node::Variant(..) => {
return def_id_visibility(tcx, tcx.hir().get_parent_did_by_hir_id(hir_id));
return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id));
}
Node::ImplItem(impl_item) => {
match tcx.hir().get_by_hir_id(tcx.hir().get_parent_item(hir_id)) {
@ -255,7 +255,7 @@ fn def_id_visibility<'tcx>(
tcx, parent_did,
);
let adt_def = tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id));
let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id));
let ctor_did = tcx.hir().local_def_id_from_hir_id(
vdata.ctor_hir_id().unwrap());
let variant = adt_def.variant_with_ctor_id(ctor_did);
@ -294,7 +294,7 @@ fn def_id_visibility<'tcx>(
// visibility to within the crate.
if ctor_vis == ty::Visibility::Public {
let adt_def =
tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id));
tcx.adt_def(tcx.hir().get_parent_did(hir_id));
if adt_def.non_enum_variant().is_field_list_non_exhaustive() {
ctor_vis =
ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
@ -311,7 +311,7 @@ fn def_id_visibility<'tcx>(
}
Node::Expr(expr) => {
return (ty::Visibility::Restricted(
tcx.hir().get_module_parent_by_hir_id(expr.hir_id)),
tcx.hir().get_module_parent(expr.hir_id)),
expr.span, "private")
}
node => bug!("unexpected node kind: {:?}", node)
@ -501,11 +501,11 @@ impl EmbargoVisitor<'tcx> {
if let Some(item) = module.res
.and_then(|res| res.mod_def_id())
.and_then(|def_id| self.tcx.hir().as_local_hir_id(def_id))
.map(|module_hir_id| self.tcx.hir().expect_item_by_hir_id(module_hir_id))
.map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id))
{
if let hir::ItemKind::Mod(m) = &item.node {
for item_id in m.item_ids.as_ref() {
let item = self.tcx.hir().expect_item_by_hir_id(item_id.id);
let item = self.tcx.hir().expect_item(item_id.id);
let def_id = self.tcx.hir().local_def_id_from_hir_id(item_id.id);
if !self.tcx.hygienic_eq(segment.ident, item.ident, def_id) { continue; }
if let hir::ItemKind::Use(..) = item.node {
@ -764,7 +764,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
let module = if module_id == hir::CRATE_HIR_ID {
&self.tcx.hir().krate().module
} else if let hir::ItemKind::Mod(ref module) =
self.tcx.hir().expect_item_by_hir_id(module_id).node {
self.tcx.hir().expect_item(module_id).node {
module
} else {
unreachable!()
@ -1690,7 +1690,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> {
tcx: self.tcx,
item_id,
item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id),
span: self.tcx.hir().span_by_hir_id(item_id),
span: self.tcx.hir().span(item_id),
required_visibility,
has_pub_restricted: self.has_pub_restricted,
has_old_errors,

View file

@ -2196,12 +2196,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(def_id) = self.const_param_def_id(expr) {
// Find the name and index of the const parameter by indexing the generics of the
// parent item and construct a `ParamConst`.
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
let item_id = tcx.hir().get_parent_node(node_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id);
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)];
let name = tcx.hir().name(node_id).as_interned_str();
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)];
let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str();
const_.val = ConstValue::Param(ty::ParamConst::new(index, name));
}

View file

@ -354,7 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let def_span = match def {
Res::Err => None,
Res::Local(id) => {
Some(self.tcx.hir().span_by_hir_id(id))
Some(self.tcx.hir().span(id))
},
_ => def
.opt_def_id()

View file

@ -813,7 +813,7 @@ fn compare_synthetic_generics<'tcx>(
{
if impl_synthetic != trait_synthetic {
let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap();
let impl_span = tcx.hir().span_by_hir_id(impl_hir_id);
let impl_span = tcx.hir().span(impl_hir_id);
let trait_span = tcx.def_span(trait_def_id);
let mut err = struct_span_err!(tcx.sess,
impl_span,

View file

@ -213,7 +213,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
// repeated `contains` calls.
if !assumptions_in_impl_context.contains(&predicate) {
let item_span = tcx.hir().span_by_hir_id(self_type_hir_id);
let item_span = tcx.hir().span(self_type_hir_id);
struct_span_err!(
tcx.sess,
drop_impl_span,

View file

@ -180,7 +180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.diverges.set(self.diverges.get() | old_diverges);
self.has_errors.set(self.has_errors.get() | old_has_errors);
debug!("type of {} is...", self.tcx.hir().hir_to_string(expr.hir_id));
debug!("type of {} is...", self.tcx.hir().node_to_string(expr.hir_id));
debug!("... {:?}, expected is {:?}", ty, expected);
ty

View file

@ -264,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// local binding
if let &QPath::Resolved(_, ref path) = &qpath {
if let hir::def::Res::Local(hir_id) = path.res {
let span = tcx.hir().span_by_hir_id(hir_id);
let span = tcx.hir().span(hir_id);
let snippet = tcx.sess.source_map().span_to_snippet(span);
let filename = tcx.sess.source_map().span_to_filename(span);
@ -370,7 +370,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
if let Some((field, field_ty)) = field_receiver {
let scope = self.tcx.hir().get_module_parent_by_hir_id(self.body_id);
let scope = self.tcx.hir().get_module_parent(self.body_id);
let is_accessible = field.vis.is_accessible_from(scope, self.tcx);
if is_accessible {
@ -564,7 +564,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'_>,
mut msg: String,
candidates: Vec<DefId>) {
let module_did = self.tcx.hir().get_module_parent_by_hir_id(self.body_id);
let module_did = self.tcx.hir().get_module_parent(self.body_id);
let module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap();
let krate = self.tcx.hir().krate();
let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
@ -897,7 +897,7 @@ impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
}
// Find a `use` statement.
for item_id in &module.item_ids {
let item = self.tcx.hir().expect_item_by_hir_id(item_id.id);
let item = self.tcx.hir().expect_item(item_id.id);
match item.node {
hir::ItemKind::Use(..) => {
// Don't suggest placing a `use` before the prelude

View file

@ -622,7 +622,7 @@ impl Inherited<'a, 'tcx> {
fn new(infcx: InferCtxt<'a, 'tcx>, def_id: DefId) -> Self {
let tcx = infcx.tcx;
let item_id = tcx.hir().as_local_hir_id(def_id);
let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by_by_hir_id(id));
let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by(id));
let implicit_region_bound = body_id.map(|body_id| {
let body = tcx.hir().body(body_id);
tcx.mk_region(ty::ReScope(region::Scope {
@ -821,7 +821,7 @@ fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::TypeckT
}
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
let span = tcx.hir().span_by_hir_id(id);
let span = tcx.hir().span(id);
// Figure out what primary body this item has.
let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| {
@ -1193,7 +1193,7 @@ fn check_fn<'a, 'tcx>(
}
let inputs = fn_sig.inputs();
let span = fcx.tcx.hir().span_by_hir_id(fn_id);
let span = fcx.tcx.hir().span(fn_id);
if inputs.len() == 1 {
let arg_is_panic_info = match inputs[0].sty {
ty::Ref(region, ty, mutbl) => match ty.sty {
@ -1246,7 +1246,7 @@ fn check_fn<'a, 'tcx>(
}
let inputs = fn_sig.inputs();
let span = fcx.tcx.hir().span_by_hir_id(fn_id);
let span = fcx.tcx.hir().span(fn_id);
if inputs.len() == 1 {
let arg_is_alloc_layout = match inputs[0].sty {
ty::Adt(ref adt, _) => {
@ -1909,11 +1909,11 @@ pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant], i
let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap();
let variant_i = tcx.hir().expect_variant(variant_i_hir_id);
let i_span = match variant_i.node.disr_expr {
Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id),
None => tcx.hir().span_by_hir_id(variant_i_hir_id)
Some(ref expr) => tcx.hir().span(expr.hir_id),
None => tcx.hir().span(variant_i_hir_id)
};
let span = match v.node.disr_expr {
Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id),
Some(ref expr) => tcx.hir().span(expr.hir_id),
None => v.span
};
struct_span_err!(tcx.sess, span, E0081,
@ -2181,7 +2181,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn local_ty(&self, span: Span, nid: hir::HirId) -> LocalTy<'tcx> {
self.locals.borrow().get(&nid).cloned().unwrap_or_else(||
span_bug!(span, "no type for local variable {}",
self.tcx.hir().hir_to_string(nid))
self.tcx.hir().node_to_string(nid))
)
}
@ -2517,9 +2517,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(&t) => t,
None if self.is_tainted_by_errors() => self.tcx.types.err,
None => {
let node_id = self.tcx.hir().hir_to_node_id(id);
bug!("no type for node {}: {} in fcx {}",
node_id, self.tcx.hir().node_to_string(node_id),
id, self.tcx.hir().node_to_string(id),
self.tag());
}
}
@ -4364,7 +4363,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t
for (&used, param) in types_used.iter().zip(types) {
if !used {
let id = tcx.hir().as_local_hir_id(param.def_id).unwrap();
let span = tcx.hir().span_by_hir_id(id);
let span = tcx.hir().span(id);
struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name)
.span_label(span, "unused type parameter")
.emit();

View file

@ -175,7 +175,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.err_count_since_creation() == 0 {
// regionck assumes typeck succeeded
rcx.visit_fn_body(fn_id, body, self.tcx.hir().span_by_hir_id(fn_id));
rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id));
}
rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx));

View file

@ -70,7 +70,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
/// the types first.
pub fn check_item_well_formed<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(hir_id);
let item = tcx.hir().expect_item(hir_id);
debug!("check_item_well_formed(it.hir_id={:?}, it.name={})",
item.hir_id,

View file

@ -34,7 +34,7 @@ use syntax_pos::Span;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body) -> &'tcx ty::TypeckTables<'tcx> {
let item_id = self.tcx.hir().body_owner(body.id());
let item_def_id = self.tcx.hir().local_def_id(item_id);
let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id);
// This attribute causes us to dump some writeback information
// in the form of errors, which is uSymbolfor unit tests.
@ -47,8 +47,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Type only exists for constants and statics, not functions.
match self.tcx.hir().body_owner_kind(item_id) {
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => {
let item_hir_id = self.tcx.hir().node_to_hir_id(item_id);
wbcx.visit_node_id(body.value.span, item_hir_id);
wbcx.visit_node_id(body.value.span, item_id);
}
hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (),
}
@ -399,7 +398,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
if let ty::UserType::TypeOf(_, user_substs) = c_ty.value {
if self.rustc_dump_user_substs {
// This is a unit-testing mechanism.
let span = self.tcx().hir().span_by_hir_id(hir_id);
let span = self.tcx().hir().span(hir_id);
// We need to buffer the errors in order to guarantee a consistent
// order when emitting them.
let err = self.tcx().sess.struct_span_err(
@ -774,13 +773,13 @@ impl Locatable for Span {
impl Locatable for DefIndex {
fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
let hir_id = tcx.hir().def_index_to_hir_id(*self);
tcx.hir().span_by_hir_id(hir_id)
tcx.hir().span(hir_id)
}
}
impl Locatable for hir::HirId {
fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.hir().span_by_hir_id(*self)
tcx.hir().span(*self)
}
}

View file

@ -121,7 +121,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'tcx>) {
for extern_crate in &crates_to_lint {
let id = tcx.hir().as_local_hir_id(extern_crate.def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(id);
let item = tcx.hir().expect_item(id);
// If the crate is fully unused, we suggest removing it altogether.
// We do this in any edition.

View file

@ -88,7 +88,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) {
debug!("visit_implementation_of_copy: self_type={:?} (bound)",
self_type);
let span = tcx.hir().span_by_hir_id(impl_hir_id);
let span = tcx.hir().span(impl_hir_id);
let param_env = tcx.param_env(impl_did);
assert!(!self_type.has_escaping_bound_vars());
@ -98,7 +98,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) {
match param_env.can_type_implement_copy(tcx, self_type) {
Ok(()) => {}
Err(CopyImplementationError::InfrigingFields(fields)) => {
let item = tcx.hir().expect_item_by_hir_id(impl_hir_id);
let item = tcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node {
tr.path.span
} else {
@ -115,7 +115,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) {
err.emit()
}
Err(CopyImplementationError::NotAnAdt) => {
let item = tcx.hir().expect_item_by_hir_id(impl_hir_id);
let item = tcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., ref ty, _) = item.node {
ty.span
} else {
@ -161,7 +161,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did:
let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap();
let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap();
let span = tcx.hir().span_by_hir_id(impl_hir_id);
let span = tcx.hir().span(impl_hir_id);
let source = tcx.type_of(impl_did);
assert!(!source.has_escaping_bound_vars());
@ -343,7 +343,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
source,
target);
let span = gcx.hir().span_by_hir_id(impl_hir_id);
let span = gcx.hir().span(impl_hir_id);
let param_env = gcx.param_env(impl_did);
assert!(!source.has_escaping_bound_vars());
@ -480,11 +480,11 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
being coerced, none found");
return err_info;
} else if diff_fields.len() > 1 {
let item = gcx.hir().expect_item_by_hir_id(impl_hir_id);
let item = gcx.hir().expect_item(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.node {
t.path.span
} else {
gcx.hir().span_by_hir_id(impl_hir_id)
gcx.hir().span(impl_hir_id)
};
let mut err = struct_span_err!(gcx.sess,

View file

@ -26,7 +26,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
// "Trait" impl
if let hir::ItemKind::Impl(.., Some(_), _, _) = item.node {
debug!("coherence2::orphan check: trait impl {}",
self.tcx.hir().hir_to_string(item.hir_id));
self.tcx.hir().node_to_string(item.hir_id));
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
let trait_def_id = trait_ref.def_id;
let cm = self.tcx.sess.source_map();

View file

@ -395,7 +395,7 @@ fn is_param<'tcx>(tcx: TyCtxt<'tcx>, ast_ty: &hir::Ty, param_id: hir::HirId) ->
}
fn convert_item<'tcx>(tcx: TyCtxt<'tcx>, item_id: hir::HirId) {
let it = tcx.hir().expect_item_by_hir_id(item_id);
let it = tcx.hir().expect_item(item_id);
debug!("convert: item {} with id {}", it.ident, it.hir_id);
let def_id = tcx.hir().local_def_id_from_hir_id(item_id);
match it.node {
@ -742,7 +742,7 @@ fn super_predicates_of<'tcx>(
fn trait_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::TraitDef {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item = tcx.hir().expect_item_by_hir_id(hir_id);
let item = tcx.hir().expect_item(hir_id);
let (is_auto, unsafety) = match item.node {
hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety),
@ -1177,7 +1177,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op
ImplItemKind::Const(ref ty, _) => icx.to_ty(ty),
ImplItemKind::Existential(_) => {
if tcx
.impl_trait_ref(tcx.hir().get_parent_did_by_hir_id(hir_id))
.impl_trait_ref(tcx.hir().get_parent_did(hir_id))
.is_none()
{
report_assoc_ty_on_inherent_impl(tcx, item.span);
@ -1187,7 +1187,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op
}
ImplItemKind::Type(ref ty) => {
if tcx
.impl_trait_ref(tcx.hir().get_parent_did_by_hir_id(hir_id))
.impl_trait_ref(tcx.hir().get_parent_did(hir_id))
.is_none()
{
report_assoc_ty_on_inherent_impl(tcx, item.span);
@ -1272,7 +1272,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op
..
}) => match *def {
VariantData::Unit(..) | VariantData::Struct(..) => {
tcx.type_of(tcx.hir().get_parent_did_by_hir_id(hir_id))
tcx.type_of(tcx.hir().get_parent_did(hir_id))
}
VariantData::Tuple(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
@ -1325,7 +1325,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op
..
}) if e.hir_id == hir_id =>
{
tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id))
tcx.adt_def(tcx.hir().get_parent_did(hir_id))
.repr
.discr_type()
.to_ty(tcx)
@ -1709,7 +1709,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> {
node: ForeignItemKind::Fn(ref fn_decl, _, _),
..
}) => {
let abi = tcx.hir().get_foreign_abi_by_hir_id(hir_id);
let abi = tcx.hir().get_foreign_abi(hir_id);
compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi)
}
@ -1717,7 +1717,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> {
node: hir::VariantKind { data, .. },
..
}) if data.ctor_hir_id().is_some() => {
let ty = tcx.type_of(tcx.hir().get_parent_did_by_hir_id(hir_id));
let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id));
let inputs = data.fields()
.iter()
.map(|f| tcx.type_of(tcx.hir().local_def_id_from_hir_id(f.hir_id)));
@ -1762,7 +1762,7 @@ fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<ty::TraitRef
let icx = ItemCtxt::new(tcx, def_id);
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
match tcx.hir().expect_item_by_hir_id(hir_id).node {
match tcx.hir().expect_item(hir_id).node {
hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => {
opt_trait_ref.as_ref().map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id);
@ -1775,7 +1775,7 @@ fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<ty::TraitRef
fn impl_polarity<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> hir::ImplPolarity {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
match tcx.hir().expect_item_by_hir_id(hir_id).node {
match tcx.hir().expect_item(hir_id).node {
hir::ItemKind::Impl(_, polarity, ..) => polarity,
ref item => bug!("impl_polarity: {:?} not an impl", item),
}

View file

@ -46,7 +46,7 @@ fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> &'tcx [ty::Varia
let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id");
let unsupported = || {
// Variance not relevant.
span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item")
span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item")
};
match tcx.hir().get_by_hir_id(id) {
Node::Item(item) => match item.node {

View file

@ -129,7 +129,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
fn visit_item(&mut self, item: &hir::Item) {
debug!("add_inferreds for item {}",
self.tcx.hir().hir_to_string(item.hir_id));
self.tcx.hir().node_to_string(item.hir_id));
match item.node {
hir::ItemKind::Struct(ref struct_def, _) |

View file

@ -305,7 +305,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec<clean::Item>) {
}
let for_ = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item_by_hir_id(hir_id).node {
match tcx.hir().expect_item(hir_id).node {
hir::ItemKind::Impl(.., ref t, _) => {
t.clean(cx)
}
@ -327,7 +327,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec<clean::Item>) {
let predicates = tcx.explicit_predicates_of(did);
let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) {
match tcx.hir().expect_item_by_hir_id(hir_id).node {
match tcx.hir().expect_item(hir_id).node {
hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => {
(
item_ids.iter()

View file

@ -276,7 +276,7 @@ impl Clean<ExternalCrate> for CrateNum {
};
let primitives = if root.is_local() {
cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| {
let item = cx.tcx.hir().expect_item_by_hir_id(id.id);
let item = cx.tcx.hir().expect_item(id.id);
match item.node {
hir::ItemKind::Mod(_) => {
as_primitive(Res::Def(
@ -320,7 +320,7 @@ impl Clean<ExternalCrate> for CrateNum {
};
let keywords = if root.is_local() {
cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| {
let item = cx.tcx.hir().expect_item_by_hir_id(id.id);
let item = cx.tcx.hir().expect_item(id.id);
match item.node {
hir::ItemKind::Mod(_) => {
as_keyword(Res::Def(
@ -2777,7 +2777,7 @@ impl Clean<Type> for hir::Ty {
},
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
TyKind::Def(item_id, _) => {
let item = cx.tcx.hir().expect_item_by_hir_id(item_id.id);
let item = cx.tcx.hir().expect_item(item_id.id);
if let hir::ItemKind::Existential(ref ty) = item.node {
ImplTrait(ty.bounds.clean(cx))
} else {
@ -2799,7 +2799,7 @@ impl Clean<Type> for hir::Ty {
// Substitute private type aliases
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(def_id) {
if !cx.renderinfo.borrow().access_levels.is_exported(def_id) {
alias = Some(&cx.tcx.hir().expect_item_by_hir_id(hir_id).node);
alias = Some(&cx.tcx.hir().expect_item(hir_id).node);
}
}
};
@ -4441,7 +4441,7 @@ pub fn path_to_def_local(tcx: TyCtxt<'_>, path: &[Symbol]) -> Option<DefId> {
let segment = path_it.next()?;
for item_id in mem::replace(&mut items, HirVec::new()).iter() {
let item = tcx.hir().expect_item_by_hir_id(item_id.id);
let item = tcx.hir().expect_item(item_id.id);
if item.ident.name == *segment {
if path_it.peek().is_none() {
return Some(tcx.hir().local_def_id_from_hir_id(item_id.id))

View file

@ -248,7 +248,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let orig_inside_public_path = self.inside_public_path;
self.inside_public_path &= vis.node.is_pub();
for i in &m.item_ids {
let item = self.cx.tcx.hir().expect_item_by_hir_id(i.id);
let item = self.cx.tcx.hir().expect_item(i.id);
self.visit_item(item, None, &mut om);
}
self.inside_public_path = orig_inside_public_path;
@ -275,7 +275,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool {
while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) {
node = id;
if cx.tcx.hir().attrs_by_hir_id(node)
if cx.tcx.hir().attrs(node)
.lists(sym::doc).has_word(sym::hidden) {
return true;
}
@ -295,7 +295,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
return false;
};
let use_attrs = tcx.hir().attrs_by_hir_id(id);
let use_attrs = tcx.hir().attrs(id);
// Don't inline `doc(hidden)` imports so they can be stripped at a later stage.
let is_no_inline = use_attrs.lists(sym::doc).has_word(sym::no_inline) ||
use_attrs.lists(sym::doc).has_word(sym::hidden);
@ -346,7 +346,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => {
let prev = mem::replace(&mut self.inlining, true);
for i in &m.item_ids {
let i = self.cx.tcx.hir().expect_item_by_hir_id(i.id);
let i = self.cx.tcx.hir().expect_item(i.id);
self.visit_item(i, None, om);
}
self.inlining = prev;
@ -361,7 +361,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
Node::ForeignItem(it) if !glob => {
// Generate a fresh `extern {}` block if we want to inline a foreign item.
om.foreigns.push(hir::ForeignMod {
abi: tcx.hir().get_foreign_abi_by_hir_id(it.hir_id),
abi: tcx.hir().get_foreign_abi(it.hir_id),
items: vec![hir::ForeignItem {
ident: renamed.unwrap_or(it.ident),
.. it.clone()

View file

@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
let item = match cx.tcx.hir().get_by_hir_id(id) {
Node::Item(item) => item,
_ => cx.tcx.hir().expect_item_by_hir_id(cx.tcx.hir().get_parent_item(id)),
_ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)),
};
if !attr::contains_name(&item.attrs, Symbol::intern("whitelisted_attr")) {