hir: remove NodeId from Local

This commit is contained in:
ljedrz 2019-02-26 10:04:27 +01:00
parent 341b023986
commit 70d3b290e2
7 changed files with 20 additions and 23 deletions

View file

@ -2008,7 +2008,7 @@ impl<'a> LoweringContext<'a> {
}
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) {
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id);
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty {
@ -2018,7 +2018,6 @@ impl<'a> LoweringContext<'a> {
}
let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0);
(hir::Local {
id: node_id,
hir_id,
ty: l.ty
.as_ref()
@ -4905,13 +4904,12 @@ impl<'a> LoweringContext<'a> {
pat: P<hir::Pat>,
source: hir::LocalSource,
) -> hir::Stmt {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
let local = hir::Local {
pat,
ty: None,
init: ex,
id: node_id,
hir_id,
span: sp,
attrs: ThinVec::new(),

View file

@ -387,7 +387,7 @@ impl<'hir> Map<'hir> {
Node::Block(_) |
Node::Crate => None,
Node::Local(local) => {
Some(Def::Local(local.id))
Some(Def::Local(self.hir_to_node_id(local.hir_id)))
}
Node::MacroDef(macro_def) => {
Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id),

View file

@ -1207,7 +1207,6 @@ pub struct Local {
pub ty: Option<P<Ty>>,
/// Initializer expression to set the value, if any.
pub init: Option<P<Expr>>,
pub id: NodeId,
pub hir_id: HirId,
pub span: Span,
pub attrs: ThinVec<Attribute>,

View file

@ -505,7 +505,6 @@ impl_stable_hash_for!(struct hir::Local {
pat,
ty,
init,
id,
hir_id,
span,
attrs,

View file

@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.demand_eqtype_pat(pat.span, expected, rhs_ty, match_discrim_span);
common_type
}
PatKind::Binding(ba, var_id, _, _, ref sub) => {
PatKind::Binding(ba, _, var_id, _, ref sub) => {
let bm = if ba == hir::BindingAnnotation::Unannotated {
def_bm
} else {
@ -239,7 +239,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.pat_binding_modes_mut()
.insert(pat.hir_id, bm);
debug!("check_pat_walk: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
let local_ty = self.local_ty(pat.span, pat.id).decl_ty;
let local_ty = self.local_ty(pat.span, pat.hir_id).decl_ty;
match bm {
ty::BindByReference(mutbl) => {
// if the binding is like
@ -265,7 +265,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// if there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be
if var_id != pat.id {
if var_id != pat.hir_id {
let vt = self.local_ty(pat.span, var_id).decl_ty;
self.demand_eqtype_pat(pat.span, vt, local_ty, match_discrim_span);
}

View file

@ -137,7 +137,7 @@ use crate::TypeAndSubsts;
use crate::lint;
use crate::util::captures::Captures;
use crate::util::common::{ErrorReported, indenter};
use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap, NodeMap};
use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap};
pub use self::Expectation::*;
use self::autoderef::Autoderef;
@ -194,7 +194,7 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
tables: MaybeInProgressTables<'a, 'tcx>,
locals: RefCell<NodeMap<LocalTy<'tcx>>>,
locals: RefCell<HirIdMap<LocalTy<'tcx>>>,
fulfillment_cx: RefCell<Box<dyn TraitEngine<'tcx>>>,
@ -943,7 +943,7 @@ struct GatherLocalsVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
}
impl<'a, 'gcx, 'tcx> GatherLocalsVisitor<'a, 'gcx, 'tcx> {
fn assign(&mut self, span: Span, nid: ast::NodeId, ty_opt: Option<LocalTy<'tcx>>) -> Ty<'tcx> {
fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option<LocalTy<'tcx>>) -> Ty<'tcx> {
match ty_opt {
None => {
// infer the variable's type
@ -994,19 +994,19 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {
},
None => None,
};
self.assign(local.span, local.id, local_ty);
self.assign(local.span, local.hir_id, local_ty);
debug!("Local variable {:?} is assigned type {}",
local.pat,
self.fcx.ty_to_string(
self.fcx.locals.borrow().get(&local.id).unwrap().clone().decl_ty));
self.fcx.locals.borrow().get(&local.hir_id).unwrap().clone().decl_ty));
intravisit::walk_local(self, local);
}
// Add pattern bindings.
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
if let PatKind::Binding(_, _, _, ident, _) = p.node {
let var_ty = self.assign(p.span, p.id, None);
let var_ty = self.assign(p.span, p.hir_id, None);
if !self.fcx.tcx.features().unsized_locals {
self.fcx.require_type_is_sized(var_ty, p.span,
@ -1016,7 +1016,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {
debug!("Pattern binding {} is assigned to {} with type {:?}",
ident,
self.fcx.ty_to_string(
self.fcx.locals.borrow().get(&p.id).unwrap().clone().decl_ty),
self.fcx.locals.borrow().get(&p.hir_id).unwrap().clone().decl_ty),
var_ty);
}
intravisit::walk_pat(self, p);
@ -2124,10 +2124,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
format!("{:?}", self_ptr)
}
pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> LocalTy<'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().node_to_string(nid))
self.tcx.hir().hir_to_string(nid))
)
}
@ -4805,7 +4805,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// See #44848.
let ref_bindings = local.pat.contains_explicit_ref_binding();
let local_ty = self.local_ty(init.span, local.id).revealed_ty;
let local_ty = self.local_ty(init.span, local.hir_id).revealed_ty;
if let Some(m) = ref_bindings {
// Somewhat subtle: if we have a `ref` binding in the pattern,
// we want to avoid introducing coercions for the RHS. This is
@ -4824,7 +4824,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
pub fn check_decl_local(&self, local: &'gcx hir::Local) {
let t = self.local_ty(local.span, local.id).decl_ty;
let t = self.local_ty(local.span, local.hir_id).decl_ty;
self.write_ty(local.hir_id, t);
if let Some(ref init) = local.init {
@ -5378,7 +5378,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
match def {
Def::Local(nid) | Def::Upvar(nid, ..) => {
let ty = self.local_ty(span, nid).decl_ty;
let hid = self.tcx.hir().node_to_hir_id(nid);
let ty = self.local_ty(span, hid).decl_ty;
let ty = self.normalize_associated_types_in(span, &ty);
self.write_ty(hir_id, ty);
return (ty, def);

View file

@ -287,7 +287,7 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
fn visit_local(&mut self, l: &'gcx hir::Local) {
intravisit::walk_local(self, l);
let var_ty = self.fcx.local_ty(l.span, l.id).decl_ty;
let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty;
let var_ty = self.resolve(&var_ty, &l.span);
self.write_ty_to_tables(l.hir_id, var_ty);
}