提交 558a07b8 编写于 作者: L ljedrz

hir: remove NodeId from PatKind

上级 78f91e39
......@@ -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);
}
......
......@@ -3679,11 +3679,10 @@ fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
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 @@ fn pat_ident_binding_mode(
(
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
......
......@@ -1016,7 +1016,7 @@ pub fn name(&self, id: NodeId) -> Name {
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))
}
......
......@@ -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 `..`.
......
......@@ -70,7 +70,7 @@ pub fn each_binding<F>(&self, mut f: F)
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 @@ pub fn contains_bindings_or_wild(&self) -> bool {
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,
}
}
......
......@@ -1765,7 +1765,7 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
// 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")?;
......
......@@ -448,7 +448,7 @@ fn hash_stable<W: StableHasherResult>(&self,
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),
......
......@@ -860,7 +860,7 @@ fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat, match_mode: Mat
// 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);
}
......
......@@ -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, _) => {
......
......@@ -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,
......
......@@ -198,7 +198,7 @@ fn check_pat(&mut self, cx: &LateContext<'_, '_>, pat: &hir::Pat) {
// (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,
......
......@@ -358,7 +358,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem)
}
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);
}
}
......
......@@ -978,7 +978,7 @@ fn encode_fn_arg_names_for_body(&mut self, body_id: hir::BodyId)
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(),
}
}))
......
......@@ -314,7 +314,6 @@ pub(super) fn report_mutability_error(
if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated,
_,
_,
upvar_ident,
_,
) = pat.node
......
......@@ -10,12 +10,13 @@
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 @@ pub fn declare_bindings(
pub fn storage_live_binding(
&mut self,
block: BasicBlock,
var: NodeId,
var: HirId,
span: Span,
for_guard: ForGuard,
) -> Place<'tcx> {
......@@ -545,17 +546,15 @@ pub fn storage_live_binding(
);
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 @@ pub(super) fn visit_bindings(
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 @@ fn declare_binding(
mutability: Mutability,
name: Name,
mode: BindingMode,
var_id: NodeId,
var_id: HirId,
var_ty: Ty<'tcx>,
user_ty: UserTypeProjections<'tcx>,
has_guard: ArmHasGuard,
......
......@@ -13,13 +13,12 @@
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 @@ fn args_and_body(&mut self,
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);
}
_ => (),
......
......@@ -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({:?}, {:?}, {:?}))",
......
......@@ -12,7 +12,6 @@
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,
......
......@@ -315,7 +315,7 @@ fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) {
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(..) => {
......
......@@ -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 @@ fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat) -> Pattern<'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 @@ fn super_fold_with<F: PatternFolder<$lt_tcx>>(&self, _: &mut F) -> Self {
}
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>
......
......@@ -647,7 +647,7 @@ pub fn get_path_def(&self, id: NodeId) -> HirDef {
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),
......
......@@ -227,7 +227,7 @@ pub fn check_pat_walk(
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 {
......
......@@ -1004,7 +1004,7 @@ fn visit_local(&mut self, local: &'gcx hir::Local) {
// 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);
......
......@@ -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),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册