Skip to content

Commit 70d3b29

Browse files
committed
hir: remove NodeId from Local
1 parent 341b023 commit 70d3b29

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ impl<'a> LoweringContext<'a> {
20082008
}
20092009

20102010
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) {
2011-
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
2011+
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(l.id);
20122012
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
20132013
if self.sess.features_untracked().impl_trait_in_bindings {
20142014
if let Some(ref ty) = l.ty {
@@ -2018,7 +2018,6 @@ impl<'a> LoweringContext<'a> {
20182018
}
20192019
let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0);
20202020
(hir::Local {
2021-
id: node_id,
20222021
hir_id,
20232022
ty: l.ty
20242023
.as_ref()
@@ -4905,13 +4904,12 @@ impl<'a> LoweringContext<'a> {
49054904
pat: P<hir::Pat>,
49064905
source: hir::LocalSource,
49074906
) -> hir::Stmt {
4908-
let LoweredNodeId { node_id, hir_id } = self.next_id();
4907+
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
49094908

49104909
let local = hir::Local {
49114910
pat,
49124911
ty: None,
49134912
init: ex,
4914-
id: node_id,
49154913
hir_id,
49164914
span: sp,
49174915
attrs: ThinVec::new(),

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'hir> Map<'hir> {
387387
Node::Block(_) |
388388
Node::Crate => None,
389389
Node::Local(local) => {
390-
Some(Def::Local(local.id))
390+
Some(Def::Local(self.hir_to_node_id(local.hir_id)))
391391
}
392392
Node::MacroDef(macro_def) => {
393393
Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id),

src/librustc/hir/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,6 @@ pub struct Local {
12071207
pub ty: Option<P<Ty>>,
12081208
/// Initializer expression to set the value, if any.
12091209
pub init: Option<P<Expr>>,
1210-
pub id: NodeId,
12111210
pub hir_id: HirId,
12121211
pub span: Span,
12131212
pub attrs: ThinVec<Attribute>,

src/librustc/ich/impls_hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ impl_stable_hash_for!(struct hir::Local {
505505
pat,
506506
ty,
507507
init,
508-
id,
509508
hir_id,
510509
span,
511510
attrs,

src/librustc_typeck/check/_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
227227
self.demand_eqtype_pat(pat.span, expected, rhs_ty, match_discrim_span);
228228
common_type
229229
}
230-
PatKind::Binding(ba, var_id, _, _, ref sub) => {
230+
PatKind::Binding(ba, _, var_id, _, ref sub) => {
231231
let bm = if ba == hir::BindingAnnotation::Unannotated {
232232
def_bm
233233
} else {
@@ -239,7 +239,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
239239
.pat_binding_modes_mut()
240240
.insert(pat.hir_id, bm);
241241
debug!("check_pat_walk: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
242-
let local_ty = self.local_ty(pat.span, pat.id).decl_ty;
242+
let local_ty = self.local_ty(pat.span, pat.hir_id).decl_ty;
243243
match bm {
244244
ty::BindByReference(mutbl) => {
245245
// if the binding is like
@@ -265,7 +265,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
265265

266266
// if there are multiple arms, make sure they all agree on
267267
// what the type of the binding `x` ought to be
268-
if var_id != pat.id {
268+
if var_id != pat.hir_id {
269269
let vt = self.local_ty(pat.span, var_id).decl_ty;
270270
self.demand_eqtype_pat(pat.span, vt, local_ty, match_discrim_span);
271271
}

src/librustc_typeck/check/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ use crate::TypeAndSubsts;
137137
use crate::lint;
138138
use crate::util::captures::Captures;
139139
use crate::util::common::{ErrorReported, indenter};
140-
use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap, NodeMap};
140+
use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap};
141141

142142
pub use self::Expectation::*;
143143
use self::autoderef::Autoderef;
@@ -194,7 +194,7 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
194194

195195
tables: MaybeInProgressTables<'a, 'tcx>,
196196

197-
locals: RefCell<NodeMap<LocalTy<'tcx>>>,
197+
locals: RefCell<HirIdMap<LocalTy<'tcx>>>,
198198

199199
fulfillment_cx: RefCell<Box<dyn TraitEngine<'tcx>>>,
200200

@@ -943,7 +943,7 @@ struct GatherLocalsVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
943943
}
944944

945945
impl<'a, 'gcx, 'tcx> GatherLocalsVisitor<'a, 'gcx, 'tcx> {
946-
fn assign(&mut self, span: Span, nid: ast::NodeId, ty_opt: Option<LocalTy<'tcx>>) -> Ty<'tcx> {
946+
fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option<LocalTy<'tcx>>) -> Ty<'tcx> {
947947
match ty_opt {
948948
None => {
949949
// infer the variable's type
@@ -994,19 +994,19 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {
994994
},
995995
None => None,
996996
};
997-
self.assign(local.span, local.id, local_ty);
997+
self.assign(local.span, local.hir_id, local_ty);
998998

999999
debug!("Local variable {:?} is assigned type {}",
10001000
local.pat,
10011001
self.fcx.ty_to_string(
1002-
self.fcx.locals.borrow().get(&local.id).unwrap().clone().decl_ty));
1002+
self.fcx.locals.borrow().get(&local.hir_id).unwrap().clone().decl_ty));
10031003
intravisit::walk_local(self, local);
10041004
}
10051005

10061006
// Add pattern bindings.
10071007
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
10081008
if let PatKind::Binding(_, _, _, ident, _) = p.node {
1009-
let var_ty = self.assign(p.span, p.id, None);
1009+
let var_ty = self.assign(p.span, p.hir_id, None);
10101010

10111011
if !self.fcx.tcx.features().unsized_locals {
10121012
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> {
10161016
debug!("Pattern binding {} is assigned to {} with type {:?}",
10171017
ident,
10181018
self.fcx.ty_to_string(
1019-
self.fcx.locals.borrow().get(&p.id).unwrap().clone().decl_ty),
1019+
self.fcx.locals.borrow().get(&p.hir_id).unwrap().clone().decl_ty),
10201020
var_ty);
10211021
}
10221022
intravisit::walk_pat(self, p);
@@ -2124,10 +2124,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
21242124
format!("{:?}", self_ptr)
21252125
}
21262126

2127-
pub fn local_ty(&self, span: Span, nid: ast::NodeId) -> LocalTy<'tcx> {
2127+
pub fn local_ty(&self, span: Span, nid: hir::HirId) -> LocalTy<'tcx> {
21282128
self.locals.borrow().get(&nid).cloned().unwrap_or_else(||
21292129
span_bug!(span, "no type for local variable {}",
2130-
self.tcx.hir().node_to_string(nid))
2130+
self.tcx.hir().hir_to_string(nid))
21312131
)
21322132
}
21332133

@@ -4805,7 +4805,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48054805
// See #44848.
48064806
let ref_bindings = local.pat.contains_explicit_ref_binding();
48074807

4808-
let local_ty = self.local_ty(init.span, local.id).revealed_ty;
4808+
let local_ty = self.local_ty(init.span, local.hir_id).revealed_ty;
48094809
if let Some(m) = ref_bindings {
48104810
// Somewhat subtle: if we have a `ref` binding in the pattern,
48114811
// we want to avoid introducing coercions for the RHS. This is
@@ -4824,7 +4824,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48244824
}
48254825

48264826
pub fn check_decl_local(&self, local: &'gcx hir::Local) {
4827-
let t = self.local_ty(local.span, local.id).decl_ty;
4827+
let t = self.local_ty(local.span, local.hir_id).decl_ty;
48284828
self.write_ty(local.hir_id, t);
48294829

48304830
if let Some(ref init) = local.init {
@@ -5378,7 +5378,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53785378

53795379
match def {
53805380
Def::Local(nid) | Def::Upvar(nid, ..) => {
5381-
let ty = self.local_ty(span, nid).decl_ty;
5381+
let hid = self.tcx.hir().node_to_hir_id(nid);
5382+
let ty = self.local_ty(span, hid).decl_ty;
53825383
let ty = self.normalize_associated_types_in(span, &ty);
53835384
self.write_ty(hir_id, ty);
53845385
return (ty, def);

src/librustc_typeck/check/writeback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
287287

288288
fn visit_local(&mut self, l: &'gcx hir::Local) {
289289
intravisit::walk_local(self, l);
290-
let var_ty = self.fcx.local_ty(l.span, l.id).decl_ty;
290+
let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty;
291291
let var_ty = self.resolve(&var_ty, &l.span);
292292
self.write_ty_to_tables(l.hir_id, var_ty);
293293
}

0 commit comments

Comments
 (0)