hir: remove NodeId from PatKind

This commit is contained in:
ljedrz 2019-03-07 12:18:59 +01:00
parent 78f91e3976
commit 558a07b896
24 changed files with 48 additions and 53 deletions

View File

@ -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));
visitor.visit_ident(ident);
walk_list!(visitor, visit_pat, optional_subpattern);
}

View File

@ -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)),
)
@ -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

View File

@ -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))
}

View File

@ -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 `..`.

View File

@ -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
@ -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,
}
}

View File

@ -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")?;

View File

@ -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),

View File

@ -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);
}

View File

@ -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, _) => {

View File

@ -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,

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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(),
}
}))

View File

@ -314,7 +314,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated,
_,
_,
upvar_ident,
_,
) = pat.node

View File

@ -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:
@ -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> {
@ -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,
@ -576,7 +575,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
Mutability,
Name,
BindingMode,
NodeId,
HirId,
Span,
Ty<'tcx>,
UserTypeProjections<'tcx>,
@ -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,
@ -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,

View File

@ -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;
@ -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>,
@ -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)
}
}
@ -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,
}
@ -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) {
@ -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);
}
_ => (),

View File

@ -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({:?}, {:?}, {:?}))",

View File

@ -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;
@ -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,

View File

@ -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.
@ -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(..) => {

View File

@ -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>>,
},
@ -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
@ -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>

View File

@ -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),

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 {

View File

@ -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);

View File

@ -3869,7 +3869,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
match p.node {
PatKind::Wild => "_".to_string(),
PatKind::Binding(_, _, _, ident, _) => ident.to_string(),
PatKind::Binding(_, _, ident, _) => ident.to_string(),
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
PatKind::Struct(ref name, ref fields, etc) => {
format!("{} {{ {}{} }}", qpath_to_string(name),