Skip to content

Commit

Permalink
hir: remove NodeId from Pat and FieldPat
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 2, 2019
1 parent 77fa041 commit 50b8bc8
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 102 deletions.
55 changes: 27 additions & 28 deletions src/librustc/hir/lowering.rs
Expand Up @@ -3740,12 +3740,11 @@ impl<'a> LoweringContext<'a> {
let fs = fields
.iter()
.map(|f| {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();

Spanned {
span: f.span,
node: hir::FieldPat {
id: node_id,
hir_id,
ident: f.node.ident,
pat: self.lower_pat(&f.node.pat),
Expand Down Expand Up @@ -3777,9 +3776,8 @@ impl<'a> LoweringContext<'a> {
PatKind::Mac(_) => panic!("Shouldn't exist here"),
};

let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.id);
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(p.id);
P(hir::Pat {
id: node_id,
hir_id,
node,
span: p.span,
Expand Down Expand Up @@ -4353,7 +4351,7 @@ impl<'a> LoweringContext<'a> {
let iter = self.str_to_ident("iter");

let next_ident = self.str_to_ident("__next");
let next_pat = self.pat_ident_binding_mode(
let (next_pat, next_pat_nid) = self.pat_ident_binding_mode(
desugared_span,
next_ident,
hir::BindingAnnotation::Mutable,
Expand All @@ -4362,9 +4360,9 @@ impl<'a> LoweringContext<'a> {
// `::std::option::Option::Some(val) => next = val`
let pat_arm = {
let val_ident = self.str_to_ident("val");
let val_pat = self.pat_ident(pat.span, val_ident);
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.id));
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id));
let (val_pat, val_pat_nid) = self.pat_ident(pat.span, val_ident);
let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat_nid));
let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat_nid));
let assign = P(self.expr(
pat.span,
hir::ExprKind::Assign(next_expr, val_expr),
Expand All @@ -4383,15 +4381,15 @@ impl<'a> LoweringContext<'a> {
};

// `mut iter`
let iter_pat = self.pat_ident_binding_mode(
let (iter_pat, iter_pat_nid) = self.pat_ident_binding_mode(
desugared_span,
iter,
hir::BindingAnnotation::Mutable
);

// `match ::std::iter::Iterator::next(&mut iter) { ... }`
let match_expr = {
let iter = P(self.expr_ident(head_sp, iter, iter_pat.id));
let iter = P(self.expr_ident(head_sp, iter, iter_pat_nid));
let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter);
let next_path = &["iter", "Iterator", "next"];
let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new()));
Expand All @@ -4415,7 +4413,7 @@ impl<'a> LoweringContext<'a> {
span: head_sp,
};

let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id));
let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat_nid));

// `let mut __next`
let next_let = self.stmt_let_pat(
Expand Down Expand Up @@ -4542,11 +4540,11 @@ impl<'a> LoweringContext<'a> {
// `Ok(val) => #[allow(unreachable_code)] val,`
let ok_arm = {
let val_ident = self.str_to_ident("val");
let val_pat = self.pat_ident(e.span, val_ident);
let (val_pat, val_pat_nid) = self.pat_ident(e.span, val_ident);
let val_expr = P(self.expr_ident_with_attrs(
e.span,
val_ident,
val_pat.id,
val_pat_nid,
ThinVec::from(attrs.clone()),
));
let ok_pat = self.pat_ok(e.span, val_pat);
Expand All @@ -4558,12 +4556,12 @@ impl<'a> LoweringContext<'a> {
// return Try::from_error(From::from(err)),`
let err_arm = {
let err_ident = self.str_to_ident("err");
let err_local = self.pat_ident(e.span, err_ident);
let (err_local, err_local_nid) = self.pat_ident(e.span, err_ident);
let from_expr = {
let path = &["convert", "From", "from"];
let from = P(self.expr_std_path(
e.span, path, None, ThinVec::new()));
let err_expr = self.expr_ident(e.span, err_ident, err_local.id);
let err_expr = self.expr_ident(e.span, err_ident, err_local_nid);

self.expr_call(e.span, from, hir_vec![err_expr])
};
Expand Down Expand Up @@ -4911,15 +4909,15 @@ impl<'a> LoweringContext<'a> {
ident: Ident,
ex: P<hir::Expr>,
) -> (hir::Stmt, NodeId) {
let pat = if mutbl {
let (pat, pat_nid) = if mutbl {
self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable)
} else {
self.pat_ident(sp, ident)
};
let pat_id = pat.id;

(
self.stmt_let_pat(sp, Some(ex), pat, hir::LocalSource::Normal),
pat_id,
pat_nid,
)
}

Expand Down Expand Up @@ -4977,7 +4975,7 @@ impl<'a> LoweringContext<'a> {
self.pat(span, pt)
}

fn pat_ident(&mut self, span: Span, ident: Ident) -> P<hir::Pat> {
fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat>, NodeId) {
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
}

Expand All @@ -4986,25 +4984,26 @@ impl<'a> LoweringContext<'a> {
span: Span,
ident: Ident,
bm: hir::BindingAnnotation,
) -> P<hir::Pat> {
) -> (P<hir::Pat>, NodeId) {
let LoweredNodeId { node_id, hir_id } = self.next_id();

P(hir::Pat {
id: node_id,
hir_id,
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
span,
})
(
P(hir::Pat {
hir_id,
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
span,
}),
node_id
)
}

fn pat_wild(&mut self, span: Span) -> P<hir::Pat> {
self.pat(span, hir::PatKind::Wild)
}

fn pat(&mut self, span: Span, pat: hir::PatKind) -> P<hir::Pat> {
let LoweredNodeId { node_id, hir_id } = self.next_id();
let LoweredNodeId { node_id: _, hir_id } = self.next_id();
P(hir::Pat {
id: node_id,
hir_id,
node: pat,
span,
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/hir/mod.rs
Expand Up @@ -834,15 +834,14 @@ pub struct Block {

#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct Pat {
pub id: NodeId,
pub hir_id: HirId,
pub node: PatKind,
pub span: Span,
}

impl fmt::Debug for Pat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "pat({}: {})", self.id,
write!(f, "pat({}: {})", self.hir_id,
print::to_string(print::NO_ANN, |s| s.print_pat(self)))
}
}
Expand Down Expand Up @@ -897,7 +896,6 @@ impl Pat {
/// except `is_shorthand` is true.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct FieldPat {
pub id: NodeId,
pub hir_id: HirId,
/// The identifier for the field.
pub ident: Ident,
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/ich/impls_hir.rs
Expand Up @@ -421,7 +421,6 @@ impl_stable_hash_for!(struct hir::Block {
});

impl_stable_hash_for!(struct hir::Pat {
id -> _,
hir_id -> _,
node,
span,
Expand All @@ -430,7 +429,6 @@ impl_stable_hash_for!(struct hir::Pat {
impl_stable_hash_for_spanned!(hir::FieldPat);

impl_stable_hash_for!(struct hir::FieldPat {
id -> _,
hir_id -> _,
ident -> (ident.name),
pat,
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -19,7 +19,6 @@ use crate::ty::{self, TyCtxt, adjustment};
use crate::hir::{self, PatKind};
use rustc_data_structures::sync::Lrc;
use std::rc::Rc;
use syntax::ast;
use syntax::ptr::P;
use syntax_pos::Span;
use crate::util::nodemap::ItemLocalSet;
Expand Down Expand Up @@ -74,7 +73,7 @@ pub trait Delegate<'tcx> {

// The local variable `id` is declared but not initialized.
fn decl_without_init(&mut self,
id: ast::NodeId,
id: hir::HirId,
span: Span);

// The path at `cmt` is being assigned to.
Expand Down Expand Up @@ -609,8 +608,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
match local.init {
None => {
local.pat.each_binding(|_, hir_id, span, _| {
let node_id = self.mc.tcx.hir().hir_to_node_id(hir_id);
self.delegate.decl_without_init(node_id, span);
self.delegate.decl_without_init(hir_id, span);
})
}

Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/mem_categorization.rs
Expand Up @@ -88,7 +88,7 @@ pub enum Categorization<'tcx> {
ThreadLocal(ty::Region<'tcx>), // value that cannot move, but still restricted in scope
StaticItem,
Upvar(Upvar), // upvar referenced by closure env
Local(ast::NodeId), // local variable
Local(hir::HirId), // local variable
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
Interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc
Downcast(cmt<'tcx>, DefId), // selects a particular enum variant (*1)
Expand Down Expand Up @@ -198,9 +198,9 @@ pub struct cmt_<'tcx> {
pub type cmt<'tcx> = Rc<cmt_<'tcx>>;

pub enum ImmutabilityBlame<'tcx> {
ImmLocal(ast::NodeId),
ImmLocal(hir::HirId),
ClosureEnv(LocalDefId),
LocalDeref(ast::NodeId),
LocalDeref(hir::HirId),
AdtFieldDeref(&'tcx ty::AdtDef, &'tcx ty::FieldDef)
}

Expand Down Expand Up @@ -230,8 +230,8 @@ impl<'tcx> cmt_<'tcx> {
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) => {
// try to figure out where the immutable reference came from
match base_cmt.cat {
Categorization::Local(node_id) =>
Some(ImmutabilityBlame::LocalDeref(node_id)),
Categorization::Local(hir_id) =>
Some(ImmutabilityBlame::LocalDeref(hir_id)),
Categorization::Interior(ref base_cmt, InteriorField(field_index)) => {
base_cmt.resolve_field(field_index.0).map(|(adt_def, field_def)| {
ImmutabilityBlame::AdtFieldDeref(adt_def, field_def)
Expand All @@ -247,8 +247,8 @@ impl<'tcx> cmt_<'tcx> {
_ => None
}
}
Categorization::Local(node_id) => {
Some(ImmutabilityBlame::ImmLocal(node_id))
Categorization::Local(hir_id) => {
Some(ImmutabilityBlame::ImmLocal(hir_id))
}
Categorization::Rvalue(..) |
Categorization::Upvar(..) |
Expand Down Expand Up @@ -741,7 +741,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
Ok(cmt_ {
hir_id,
span,
cat: Categorization::Local(vid),
cat: Categorization::Local(self.tcx.hir().node_to_hir_id(vid)),
mutbl: MutabilityCategory::from_local(self.tcx, self.tables, vid),
ty: expr_ty,
note: NoteNone
Expand Down Expand Up @@ -1495,7 +1495,7 @@ impl<'tcx> cmt_<'tcx> {
"non-place".into()
}
Categorization::Local(vid) => {
if tcx.hir().is_argument(vid) {
if tcx.hir().is_argument(tcx.hir().hir_to_node_id(vid)) {
"argument"
} else {
"local variable"
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -2397,7 +2397,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {

let help_name = if let Some(body) = parent {
let arg = &self.tcx.hir().body(body).arguments[index];
format!("`{}`", self.tcx.hir().node_to_pretty_string(arg.pat.id))
format!("`{}`", self.tcx.hir().hir_to_pretty_string(arg.pat.hir_id))
} else {
format!("argument {}", index + 1)
};
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_borrowck/borrowck/check_loans.rs
Expand Up @@ -17,7 +17,6 @@ use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use rustc::middle::region;
use rustc::ty::{self, TyCtxt, RegionKind};
use syntax::ast;
use syntax_pos::Span;
use rustc::hir;
use rustc::hir::Node;
Expand Down Expand Up @@ -177,7 +176,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
self.check_assignment(assignment_id.local_id, assignment_span, assignee_cmt);
}

fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { }
fn decl_without_init(&mut self, _id: hir::HirId, _span: Span) { }
}

pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
Expand Down Expand Up @@ -887,11 +886,10 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
// Check for reassignments to (immutable) local variables. This
// needs to be done here instead of in check_loans because we
// depend on move data.
if let Categorization::Local(local_id) = assignee_cmt.cat {
if let Categorization::Local(hir_id) = assignee_cmt.cat {
let lp = opt_loan_path(assignee_cmt).unwrap();
self.move_data.each_assignment_of(assignment_id, &lp, |assign| {
if assignee_cmt.mutbl.is_mutable() {
let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id);
self.bccx.used_mut_nodes.borrow_mut().insert(hir_id);
} else {
self.bccx.report_reassigned_immutable_variable(
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs
Expand Up @@ -11,7 +11,6 @@ use rustc::middle::mem_categorization::InteriorOffsetKind as Kind;
use rustc::ty::{self, Ty};

use std::rc::Rc;
use syntax::ast;
use syntax_pos::Span;
use rustc::hir::*;
use rustc::hir::Node;
Expand Down Expand Up @@ -48,9 +47,9 @@ pub enum PatternSource<'tcx> {
/// with a reference to the let
fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> PatternSource<'tcx> {

let parent = tcx.hir().get_parent_node(pat.id);
let parent = tcx.hir().get_parent_node_by_hir_id(pat.hir_id);

match tcx.hir().get(parent) {
match tcx.hir().get_by_hir_id(parent) {
Node::Expr(ref e) => {
// the enclosing expression must be a `match` or something else
assert!(match e.node {
Expand All @@ -67,11 +66,10 @@ fn get_pattern_source<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, pat: &Pat) -> Patte

pub fn gather_decl<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
move_data: &MoveData<'tcx>,
var_id: ast::NodeId,
var_id: hir::HirId,
var_ty: Ty<'tcx>) {
let loan_path = Rc::new(LoanPath::new(LpVar(var_id), var_ty));
let hir_id = bccx.tcx.hir().node_to_hir_id(var_id);
move_data.add_move(bccx.tcx, loan_path, hir_id.local_id, Declared);
move_data.add_move(bccx.tcx, loan_path, var_id.local_id, Declared);
}

pub fn gather_move_from_expr<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_borrowck/borrowck/gather_loans/lifetime.rs
Expand Up @@ -104,8 +104,7 @@ impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> {
Categorization::Upvar(..) => {
self.bccx.tcx.mk_region(ty::ReScope(self.item_scope))
}
Categorization::Local(local_id) => {
let hir_id = self.bccx.tcx.hir().node_to_hir_id(local_id);
Categorization::Local(hir_id) => {
self.bccx.tcx.mk_region(ty::ReScope(
self.bccx.region_scope_tree.var_scope(hir_id.local_id)))
}
Expand Down

0 comments on commit 50b8bc8

Please sign in to comment.