Skip to content

Commit

Permalink
hir: remove NodeId from PatKind
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Mar 7, 2019
1 parent 78f91e3 commit 558a07b
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/librustc/hir/intravisit.rs
Expand Up @@ -697,8 +697,8 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
PatKind::Ref(ref subpattern, _) => {
visitor.visit_pat(subpattern)
}
PatKind::Binding(_, canonical_id, _hir_id, ident, ref optional_subpattern) => {
visitor.visit_def_mention(Def::Local(canonical_id));
PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
// visitor.visit_def_mention(Def::Local(hir_id));

This comment has been minimized.

Copy link
@felix91gr

felix91gr Mar 28, 2019

Contributor

This line is commented. Is this intended, or was this a leftover of some cleanup / sweeping changes?

This comment has been minimized.

Copy link
@ljedrz

ljedrz Mar 29, 2019

Author Contributor

It was a work-in-progress change; one of my later commits (probably in the same PR) removed visit_def_mention (and this comment), as I found out it didn't actually do anything.

This comment has been minimized.

Copy link
@felix91gr

felix91gr Apr 5, 2019

Contributor

Ahh, I see. Thank you ^^

visitor.visit_ident(ident);
walk_list!(visitor, visit_pat, optional_subpattern);
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/hir/lowering.rs
Expand Up @@ -3679,11 +3679,10 @@ impl<'a> LoweringContext<'a> {
Some(Def::Local(id)) => id,
_ => p.id,
};
let hir_id = self.lower_node_id(canonical_id).hir_id;

hir::PatKind::Binding(
self.lower_binding_mode(binding_mode),
canonical_id,
hir_id,
self.lower_node_id(canonical_id).hir_id,
ident,
sub.as_ref().map(|x| self.lower_pat(x)),
)
Expand Down Expand Up @@ -4985,7 +4984,7 @@ impl<'a> LoweringContext<'a> {
(
P(hir::Pat {
hir_id,
node: hir::PatKind::Binding(bm, node_id, hir_id, ident.with_span_pos(span), None),
node: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None),
span,
}),
node_id
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Expand Up @@ -1016,7 +1016,7 @@ impl<'hir> Map<'hir> {
Node::Field(f) => f.ident.name,
Node::Lifetime(lt) => lt.name.ident().name,
Node::GenericParam(param) => param.name.ident().name,
Node::Binding(&Pat { node: PatKind::Binding(_, _, _, l, _), .. }) => l.name,
Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name,
Node::StructCtor(_) => self.name(self.get_parent(id)),
_ => bug!("no name for {}", self.node_to_string(id))
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/mod.rs
Expand Up @@ -936,10 +936,10 @@ pub enum PatKind {
Wild,

/// A fresh binding `ref mut binding @ OPT_SUBPATTERN`.
/// The `NodeId` is the canonical ID for the variable being bound,
/// The `HirId` is the canonical ID for the variable being bound,
/// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID),
/// which is the pattern ID of the first `x`.
Binding(BindingAnnotation, NodeId, HirId, Ident, Option<P<Pat>>),
Binding(BindingAnnotation, HirId, Ident, Option<P<Pat>>),

/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/pat_util.rs
Expand Up @@ -70,7 +70,7 @@ impl hir::Pat {
where F: FnMut(hir::BindingAnnotation, HirId, Span, ast::Ident),
{
self.walk(|p| {
if let PatKind::Binding(binding_mode, _, _, ident, _) = p.node {
if let PatKind::Binding(binding_mode, _, ident, _) = p.node {
f(binding_mode, p.hir_id, p.span, ident);
}
true
Expand Down Expand Up @@ -110,8 +110,8 @@ impl hir::Pat {

pub fn simple_ident(&self) -> Option<ast::Ident> {
match self.node {
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, None) |
PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, None) => Some(ident),
PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) |
PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, None) => Some(ident),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/print.rs
Expand Up @@ -1765,7 +1765,7 @@ impl<'a> State<'a> {
// is that it doesn't matter
match pat.node {
PatKind::Wild => self.s.word("_")?,
PatKind::Binding(binding_mode, _, _, ident, ref sub) => {
PatKind::Binding(binding_mode, _, ident, ref sub) => {
match binding_mode {
hir::BindingAnnotation::Ref => {
self.word_nbsp("ref")?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_hir.rs
Expand Up @@ -448,7 +448,7 @@ impl_stable_hash_for!(enum hir::RangeEnd {

impl_stable_hash_for!(enum hir::PatKind {
Wild,
Binding(binding_mode, var, hir_id, name, sub),
Binding(binding_mode, hir_id, name, sub),
Struct(path, field_pats, dotdot),
TupleStruct(path, field_pats, dotdot),
Path(path),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -860,7 +860,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {

// Each match binding is effectively an assignment to the
// binding being produced.
let def = Def::Local(canonical_id);
let def = Def::Local(mc.tcx.hir().hir_to_node_id(canonical_id));
if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) {
delegate.mutate(pat.hir_id, pat.span, binding_cmt, MutateMode::Init);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Expand Up @@ -407,7 +407,7 @@ fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P<hir::Pat>) {
while let Some(pat) = pats.pop_front() {
use crate::hir::PatKind::*;
match pat.node {
Binding(_, _, _, _, ref inner_pat) => {
Binding(_, _, _, ref inner_pat) => {
pats.extend(inner_pat.iter());
}
Struct(_, ref fields, _) => {
Expand Down
Expand Up @@ -98,7 +98,7 @@ pub fn gather_move_from_pat<'a, 'c, 'tcx: 'c>(bccx: &BorrowckCtxt<'a, 'tcx>,
cmt: &'c mc::cmt_<'tcx>) {
let source = get_pattern_source(bccx.tcx,move_pat);
let pat_span_path_opt = match move_pat.node {
PatKind::Binding(_, _, _, ident, _) => {
PatKind::Binding(_, _, ident, _) => {
Some(MovePlace {
span: move_pat.span,
name: ident.name,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Expand Up @@ -198,7 +198,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns {
// (Issue #49588)
continue;
}
if let PatKind::Binding(_, _, _, ident, None) = fieldpat.node.pat.node {
if let PatKind::Binding(_, _, ident, None) = fieldpat.node.pat.node {
if cx.tcx.find_field_index(ident, &variant) ==
Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) {
let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/nonstandard_style.rs
Expand Up @@ -358,7 +358,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}

fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat) {
if let &PatKind::Binding(_, _, _, ident, _) = &p.node {
if let &PatKind::Binding(_, _, ident, _) = &p.node {
self.check_snake_case(cx, "variable", &ident);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/encoder.rs
Expand Up @@ -978,7 +978,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
let body = self.tcx.hir().body(body_id);
self.lazy_seq(body.arguments.iter().map(|arg| {
match arg.pat.node {
PatKind::Binding(_, _, _, ident, _) => ident.name,
PatKind::Binding(_, _, ident, _) => ident.name,
_ => keywords::Invalid.name(),
}
}))
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/borrow_check/mutability_errors.rs
Expand Up @@ -314,7 +314,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated,
_,
_,
upvar_ident,
_,
) = pat.node
Expand Down
19 changes: 9 additions & 10 deletions src/librustc_mir/build/matches/mod.rs
Expand Up @@ -10,12 +10,13 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
use crate::build::{BlockAnd, BlockAndExtension, Builder};
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
use crate::hair::{self, *};
use rustc::hir::HirId;
use rustc::mir::*;
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty};
use rustc::ty::layout::VariantIdx;
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use syntax::ast::{Name, NodeId};
use syntax::ast::Name;
use syntax_pos::Span;

// helper functions, broken out by category:
Expand Down Expand Up @@ -530,7 +531,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
pub fn storage_live_binding(
&mut self,
block: BasicBlock,
var: NodeId,
var: HirId,
span: Span,
for_guard: ForGuard,
) -> Place<'tcx> {
Expand All @@ -545,17 +546,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
);
let place = Place::Base(PlaceBase::Local(local_id));
let var_ty = self.local_decls[local_id].ty;
let hir_id = self.hir.tcx().hir().node_to_hir_id(var);
let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id);
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage);
place
}

pub fn schedule_drop_for_binding(&mut self, var: NodeId, span: Span, for_guard: ForGuard) {
pub fn schedule_drop_for_binding(&mut self, var: HirId, span: Span, for_guard: ForGuard) {
let local_id = self.var_local_id(var, for_guard);
let var_ty = self.local_decls[local_id].ty;
let hir_id = self.hir.tcx().hir().node_to_hir_id(var);
let region_scope = self.hir.region_scope_tree.var_scope(hir_id.local_id);
let region_scope = self.hir.region_scope_tree.var_scope(var.local_id);
self.schedule_drop(
span,
region_scope,
Expand All @@ -576,7 +575,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
Mutability,
Name,
BindingMode,
NodeId,
HirId,
Span,
Ty<'tcx>,
UserTypeProjections<'tcx>,
Expand Down Expand Up @@ -703,7 +702,7 @@ struct Binding<'tcx> {
span: Span,
source: Place<'tcx>,
name: Name,
var_id: NodeId,
var_id: HirId,
var_ty: Ty<'tcx>,
mutability: Mutability,
binding_mode: BindingMode,
Expand Down Expand Up @@ -1694,7 +1693,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
mutability: Mutability,
name: Name,
mode: BindingMode,
var_id: NodeId,
var_id: HirId,
var_ty: Ty<'tcx>,
user_ty: UserTypeProjections<'tcx>,
has_guard: ArmHasGuard,
Expand Down
19 changes: 9 additions & 10 deletions src/librustc_mir/build/mod.rs
Expand Up @@ -13,13 +13,12 @@ use rustc::mir::*;
use rustc::mir::visit::{MutVisitor, TyContext};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::SubstsRef;
use rustc::util::nodemap::NodeMap;
use rustc::util::nodemap::HirIdMap;
use rustc_target::spec::PanicStrategy;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use std::mem;
use std::u32;
use rustc_target::spec::abi::Abi;
use syntax::ast;
use syntax::attr::{self, UnwindAttr};
use syntax::symbol::keywords;
use syntax_pos::Span;
Expand Down Expand Up @@ -376,7 +375,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {

/// Maps `NodeId`s of variable bindings to the `Local`s created for them.
/// (A match binding can have two locals; the 2nd is for the arm's guard.)
var_indices: NodeMap<LocalsForNode>,
var_indices: HirIdMap<LocalsForNode>,
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
upvar_decls: Vec<UpvarDecl>,
Expand All @@ -392,11 +391,11 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
}

impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
fn is_bound_var_in_guard(&self, id: ast::NodeId) -> bool {
fn is_bound_var_in_guard(&self, id: hir::HirId) -> bool {
self.guard_context.iter().any(|frame| frame.locals.iter().any(|local| local.id == id))
}

fn var_local_id(&self, id: ast::NodeId, for_guard: ForGuard) -> Local {
fn var_local_id(&self, id: hir::HirId, for_guard: ForGuard) -> Local {
self.var_indices[&id].local_id(for_guard)
}
}
Expand Down Expand Up @@ -471,11 +470,11 @@ enum LocalsForNode {

#[derive(Debug)]
struct GuardFrameLocal {
id: ast::NodeId,
id: hir::HirId,
}

impl GuardFrameLocal {
fn new(id: ast::NodeId, _binding_mode: BindingMode) -> Self {
fn new(id: hir::HirId, _binding_mode: BindingMode) -> Self {
GuardFrameLocal {
id: id,
}
Expand Down Expand Up @@ -650,7 +649,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
mutability: Mutability::Not,
};
if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) {
if let hir::PatKind::Binding(_, _, _, ident, _) = pat.node {
if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
decl.debug_name = ident.name;
if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
if bm == ty::BindByValue(hir::MutMutable) {
Expand Down Expand Up @@ -855,8 +854,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
let mut name = None;
if let Some(pat) = pattern {
match pat.node {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, _, ident, _)
| hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, _, ident, _) => {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _)
| hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, _) => {
name = Some(ident.name);
}
_ => (),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -992,7 +992,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id);

match def {
Def::Local(id) => ExprKind::VarRef { id },
Def::Local(id) => ExprKind::VarRef { id: cx.tcx.hir().node_to_hir_id(id) },

Def::Upvar(var_id, index, closure_expr_id) => {
debug!("convert_var(upvar({:?}, {:?}, {:?}))",
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/hair/mod.rs
Expand Up @@ -12,7 +12,6 @@ use rustc::ty::subst::SubstsRef;
use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserType};
use rustc::ty::layout::VariantIdx;
use rustc::hir;
use syntax::ast;
use syntax_pos::Span;
use self::cx::Cx;

Expand Down Expand Up @@ -230,7 +229,7 @@ pub enum ExprKind<'tcx> {
index: ExprRef<'tcx>,
},
VarRef {
id: ast::NodeId,
id: hir::HirId,
},
/// first argument, used for self in a closure
SelfRef,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/hair/pattern/check_match.rs
Expand Up @@ -315,7 +315,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {

fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
pat.walk(|p| {
if let PatKind::Binding(_, _, _, ident, None) = p.node {
if let PatKind::Binding(_, _, ident, None) = p.node {
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
if bm != ty::BindByValue(hir::MutImmutable) {
// Nothing to check.
Expand Down Expand Up @@ -590,7 +590,7 @@ fn check_legality_of_move_bindings(

for pat in pats {
pat.walk(|p| {
if let PatKind::Binding(_, _, _, _, ref sub) = p.node {
if let PatKind::Binding(_, _, _, ref sub) = p.node {
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
match bm {
ty::BindByValue(..) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/hair/pattern/mod.rs
Expand Up @@ -126,7 +126,7 @@ pub enum PatternKind<'tcx> {
mutability: Mutability,
name: ast::Name,
mode: BindingMode,
var: ast::NodeId,
var: hir::HirId,
ty: Ty<'tcx>,
subpattern: Option<Pattern<'tcx>>,
},
Expand Down Expand Up @@ -559,7 +559,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
}
}

PatKind::Binding(_, id, _, ident, ref sub) => {
PatKind::Binding(_, id, ident, ref sub) => {
let var_ty = self.tables.node_type(pat.hir_id);
if let ty::Error = var_ty.sty {
// Avoid ICE
Expand Down Expand Up @@ -1090,7 +1090,7 @@ macro_rules! CloneImpls {
}

CloneImpls!{ <'tcx>
Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>,
Span, Field, Mutability, ast::Name, hir::HirId, usize, ty::Const<'tcx>,
Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef,
SubstsRef<'tcx>, &'tcx Kind<'tcx>, UserType<'tcx>,
UserTypeProjection<'tcx>, PatternTypeProjection<'tcx>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Expand Up @@ -647,7 +647,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
Node::Binding(&hir::Pat {
node: hir::PatKind::Binding(_, canonical_id, ..),
..
}) => HirDef::Local(canonical_id),
}) => HirDef::Local(self.tcx.hir().hir_to_node_id(canonical_id)),

Node::Ty(ty) => if let hir::Ty {
node: hir::TyKind::Path(ref qpath),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/_match.rs
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Expand Up @@ -1004,7 +1004,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for GatherLocalsVisitor<'a, 'gcx, 'tcx> {

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

let node_id = self.fcx.tcx.hir().hir_to_node_id(p.hir_id);
Expand Down

0 comments on commit 558a07b

Please sign in to comment.