, Option>),
+ /// records this pattern's `NodeId` in an auxiliary
+ /// set (of "PatIdents that refer to unit patterns or constants").
+ Ident(BindingMode, Spanned, Option>),
+ /// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`.
+ /// The `bool` is `true` in the presence of a `..`.
+ Struct(Path, HirVec>, bool),
+
+ /// A tuple struct/variant pattern `Variant(x, y, z)`.
/// "None" means a `Variant(..)` pattern where we don't bind the fields to names.
- PatEnum(Path, Option>>),
+ TupleStruct(Path, Option>>),
+
+ /// A path pattern.
+ /// Such pattern can be resolved to a unit struct/variant or a constant.
+ Path(Path),
/// An associated const named using the qualified path `::CONST` or
/// `::CONST`. Associated consts from inherent impls can be
/// referred to as simply `T::CONST`, in which case they will end up as
- /// PatEnum, and the resolver will have to sort that out.
- PatQPath(QSelf, Path),
+ /// PatKind::Path, and the resolver will have to sort that out.
+ QPath(QSelf, Path),
- /// Destructuring of a struct, e.g. `Foo {x, y, ..}`
- /// The `bool` is `true` in the presence of a `..`
- PatStruct(Path, HirVec>, bool),
/// A tuple pattern `(a, b)`
- PatTup(HirVec>),
+ Tup(HirVec
>),
/// A `box` pattern
- PatBox(P),
+ Box(P),
/// A reference pattern, e.g. `&mut (a, b)`
- PatRegion(P, Mutability),
+ Ref(P, Mutability),
/// A literal
- PatLit(P),
+ Lit(P),
/// A range pattern, e.g. `1...2`
- PatRange(P, P),
+ Range(P, P),
/// `[a, b, ..i, y, z]` is represented as:
- /// `PatVec(box [a, b], Some(i), box [y, z])`
- PatVec(HirVec>, Option
>, HirVec
>),
+ /// `PatKind::Vec(box [a, b], Some(i), box [y, z])`
+ Vec(HirVec
>, Option
>, HirVec
>),
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
@@ -1015,7 +1020,7 @@ impl Arg {
}),
pat: P(Pat {
id: DUMMY_NODE_ID,
- node: PatIdent(BindByValue(mutability), path, None),
+ node: PatKind::Ident(BindByValue(mutability), path, None),
span: span,
}),
id: DUMMY_NODE_ID,
diff --git a/src/librustc_front/intravisit.rs b/src/librustc_front/intravisit.rs
index 03b021cfa6395..c1bcaab9d6819 100644
--- a/src/librustc_front/intravisit.rs
+++ b/src/librustc_front/intravisit.rs
@@ -468,41 +468,44 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
match pattern.node {
- PatEnum(ref path, ref opt_children) => {
+ PatKind::TupleStruct(ref path, ref opt_children) => {
visitor.visit_path(path, pattern.id);
if let Some(ref children) = *opt_children {
walk_list!(visitor, visit_pat, children);
}
}
- PatQPath(ref qself, ref path) => {
+ PatKind::Path(ref path) => {
+ visitor.visit_path(path, pattern.id);
+ }
+ PatKind::QPath(ref qself, ref path) => {
visitor.visit_ty(&qself.ty);
visitor.visit_path(path, pattern.id)
}
- PatStruct(ref path, ref fields, _) => {
+ PatKind::Struct(ref path, ref fields, _) => {
visitor.visit_path(path, pattern.id);
for field in fields {
visitor.visit_name(field.span, field.node.name);
visitor.visit_pat(&field.node.pat)
}
}
- PatTup(ref tuple_elements) => {
+ PatKind::Tup(ref tuple_elements) => {
walk_list!(visitor, visit_pat, tuple_elements);
}
- PatBox(ref subpattern) |
- PatRegion(ref subpattern, _) => {
+ PatKind::Box(ref subpattern) |
+ PatKind::Ref(ref subpattern, _) => {
visitor.visit_pat(subpattern)
}
- PatIdent(_, ref pth1, ref optional_subpattern) => {
+ PatKind::Ident(_, ref pth1, ref optional_subpattern) => {
visitor.visit_ident(pth1.span, pth1.node);
walk_list!(visitor, visit_pat, optional_subpattern);
}
- PatLit(ref expression) => visitor.visit_expr(expression),
- PatRange(ref lower_bound, ref upper_bound) => {
+ PatKind::Lit(ref expression) => visitor.visit_expr(expression),
+ PatKind::Range(ref lower_bound, ref upper_bound) => {
visitor.visit_expr(lower_bound);
visitor.visit_expr(upper_bound)
}
- PatWild => (),
- PatVec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
+ PatKind::Wild => (),
+ PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
walk_list!(visitor, visit_pat, prepatterns);
walk_list!(visitor, visit_pat, slice_pattern);
walk_list!(visitor, visit_pat, postpatterns);
diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs
index bb113a7ad6a77..0e7d9db37fdb8 100644
--- a/src/librustc_front/lowering.rs
+++ b/src/librustc_front/lowering.rs
@@ -913,27 +913,27 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P {
P(hir::Pat {
id: p.id,
node: match p.node {
- PatKind::Wild => hir::PatWild,
+ PatKind::Wild => hir::PatKind::Wild,
PatKind::Ident(ref binding_mode, pth1, ref sub) => {
- hir::PatIdent(lower_binding_mode(lctx, binding_mode),
+ hir::PatKind::Ident(lower_binding_mode(lctx, binding_mode),
respan(pth1.span, lower_ident(lctx, pth1.node)),
sub.as_ref().map(|x| lower_pat(lctx, x)))
}
- PatKind::Lit(ref e) => hir::PatLit(lower_expr(lctx, e)),
+ PatKind::Lit(ref e) => hir::PatKind::Lit(lower_expr(lctx, e)),
PatKind::TupleStruct(ref pth, ref pats) => {
- hir::PatEnum(lower_path(lctx, pth),
+ hir::PatKind::TupleStruct(lower_path(lctx, pth),
pats.as_ref()
.map(|pats| pats.iter().map(|x| lower_pat(lctx, x)).collect()))
}
PatKind::Path(ref pth) => {
- hir::PatEnum(lower_path(lctx, pth), Some(hir::HirVec::new()))
+ hir::PatKind::Path(lower_path(lctx, pth))
}
PatKind::QPath(ref qself, ref pth) => {
let qself = hir::QSelf {
ty: lower_ty(lctx, &qself.ty),
position: qself.position,
};
- hir::PatQPath(qself, lower_path(lctx, pth))
+ hir::PatKind::QPath(qself, lower_path(lctx, pth))
}
PatKind::Struct(ref pth, ref fields, etc) => {
let pth = lower_path(lctx, pth);
@@ -949,20 +949,20 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P {
}
})
.collect();
- hir::PatStruct(pth, fs, etc)
+ hir::PatKind::Struct(pth, fs, etc)
}
PatKind::Tup(ref elts) => {
- hir::PatTup(elts.iter().map(|x| lower_pat(lctx, x)).collect())
+ hir::PatKind::Tup(elts.iter().map(|x| lower_pat(lctx, x)).collect())
}
- PatKind::Box(ref inner) => hir::PatBox(lower_pat(lctx, inner)),
+ PatKind::Box(ref inner) => hir::PatKind::Box(lower_pat(lctx, inner)),
PatKind::Ref(ref inner, mutbl) => {
- hir::PatRegion(lower_pat(lctx, inner), lower_mutability(lctx, mutbl))
+ hir::PatKind::Ref(lower_pat(lctx, inner), lower_mutability(lctx, mutbl))
}
PatKind::Range(ref e1, ref e2) => {
- hir::PatRange(lower_expr(lctx, e1), lower_expr(lctx, e2))
+ hir::PatKind::Range(lower_expr(lctx, e1), lower_expr(lctx, e2))
}
PatKind::Vec(ref before, ref slice, ref after) => {
- hir::PatVec(before.iter().map(|x| lower_pat(lctx, x)).collect(),
+ hir::PatKind::Vec(before.iter().map(|x| lower_pat(lctx, x)).collect(),
slice.as_ref().map(|x| lower_pat(lctx, x)),
after.iter().map(|x| lower_pat(lctx, x)).collect())
}
@@ -1750,7 +1750,11 @@ fn pat_enum(lctx: &LoweringContext,
path: hir::Path,
subpats: hir::HirVec>)
-> P {
- let pt = hir::PatEnum(path, Some(subpats));
+ let pt = if subpats.is_empty() {
+ hir::PatKind::Path(path)
+ } else {
+ hir::PatKind::TupleStruct(path, Some(subpats))
+ };
pat(lctx, span, pt)
}
@@ -1763,7 +1767,7 @@ fn pat_ident_binding_mode(lctx: &LoweringContext,
ident: hir::Ident,
bm: hir::BindingMode)
-> P {
- let pat_ident = hir::PatIdent(bm,
+ let pat_ident = hir::PatKind::Ident(bm,
Spanned {
span: span,
node: ident,
@@ -1773,10 +1777,10 @@ fn pat_ident_binding_mode(lctx: &LoweringContext,
}
fn pat_wild(lctx: &LoweringContext, span: Span) -> P {
- pat(lctx, span, hir::PatWild)
+ pat(lctx, span, hir::PatKind::Wild)
}
-fn pat(lctx: &LoweringContext, span: Span, pat: hir::Pat_) -> P {
+fn pat(lctx: &LoweringContext, span: Span, pat: hir::PatKind) -> P {
P(hir::Pat {
id: lctx.next_id(),
node: pat,
diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs
index 1425fbe9511a3..d837ab0f8f6cb 100644
--- a/src/librustc_front/print/pprust.rs
+++ b/src/librustc_front/print/pprust.rs
@@ -24,7 +24,7 @@ use syntax::print::pprust::{self as ast_pp, PrintState};
use syntax::ptr::P;
use hir;
-use hir::{Crate, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
+use hir::{Crate, PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use std::io::{self, Write, Read};
@@ -1727,8 +1727,8 @@ impl<'a> State<'a> {
// Pat isn't normalized, but the beauty of it
// is that it doesn't matter
match pat.node {
- hir::PatWild => try!(word(&mut self.s, "_")),
- hir::PatIdent(binding_mode, ref path1, ref sub) => {
+ PatKind::Wild => try!(word(&mut self.s, "_")),
+ PatKind::Ident(binding_mode, ref path1, ref sub) => {
match binding_mode {
hir::BindByRef(mutbl) => {
try!(self.word_nbsp("ref"));
@@ -1748,23 +1748,24 @@ impl<'a> State<'a> {
None => (),
}
}
- hir::PatEnum(ref path, ref args_) => {
+ PatKind::TupleStruct(ref path, ref args_) => {
try!(self.print_path(path, true, 0));
match *args_ {
None => try!(word(&mut self.s, "(..)")),
Some(ref args) => {
- if !args.is_empty() {
- try!(self.popen());
- try!(self.commasep(Inconsistent, &args[..], |s, p| s.print_pat(&p)));
- try!(self.pclose());
- }
+ try!(self.popen());
+ try!(self.commasep(Inconsistent, &args[..], |s, p| s.print_pat(&p)));
+ try!(self.pclose());
}
}
}
- hir::PatQPath(ref qself, ref path) => {
+ PatKind::Path(ref path) => {
+ try!(self.print_path(path, true, 0));
+ }
+ PatKind::QPath(ref qself, ref path) => {
try!(self.print_qpath(path, qself, false));
}
- hir::PatStruct(ref path, ref fields, etc) => {
+ PatKind::Struct(ref path, ref fields, etc) => {
try!(self.print_path(path, true, 0));
try!(self.nbsp());
try!(self.word_space("{"));
@@ -1789,7 +1790,7 @@ impl<'a> State<'a> {
try!(space(&mut self.s));
try!(word(&mut self.s, "}"));
}
- hir::PatTup(ref elts) => {
+ PatKind::Tup(ref elts) => {
try!(self.popen());
try!(self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p)));
if elts.len() == 1 {
@@ -1797,32 +1798,32 @@ impl<'a> State<'a> {
}
try!(self.pclose());
}
- hir::PatBox(ref inner) => {
+ PatKind::Box(ref inner) => {
try!(word(&mut self.s, "box "));
try!(self.print_pat(&inner));
}
- hir::PatRegion(ref inner, mutbl) => {
+ PatKind::Ref(ref inner, mutbl) => {
try!(word(&mut self.s, "&"));
if mutbl == hir::MutMutable {
try!(word(&mut self.s, "mut "));
}
try!(self.print_pat(&inner));
}
- hir::PatLit(ref e) => try!(self.print_expr(&e)),
- hir::PatRange(ref begin, ref end) => {
+ PatKind::Lit(ref e) => try!(self.print_expr(&e)),
+ PatKind::Range(ref begin, ref end) => {
try!(self.print_expr(&begin));
try!(space(&mut self.s));
try!(word(&mut self.s, "..."));
try!(self.print_expr(&end));
}
- hir::PatVec(ref before, ref slice, ref after) => {
+ PatKind::Vec(ref before, ref slice, ref after) => {
try!(word(&mut self.s, "["));
try!(self.commasep(Inconsistent, &before[..], |s, p| s.print_pat(&p)));
if let Some(ref p) = *slice {
if !before.is_empty() {
try!(self.word_space(","));
}
- if p.node != hir::PatWild {
+ if p.node != PatKind::Wild {
try!(self.print_pat(&p));
}
try!(word(&mut self.s, ".."));
@@ -1945,7 +1946,7 @@ impl<'a> State<'a> {
let m = match explicit_self {
&hir::SelfStatic => hir::MutImmutable,
_ => match decl.inputs[0].pat.node {
- hir::PatIdent(hir::BindByValue(m), _, _) => m,
+ PatKind::Ident(hir::BindByValue(m), _, _) => m,
_ => hir::MutImmutable,
},
};
@@ -2210,7 +2211,7 @@ impl<'a> State<'a> {
hir::TyInfer if is_closure => try!(self.print_pat(&input.pat)),
_ => {
match input.pat.node {
- hir::PatIdent(_, ref path1, _) if
+ PatKind::Ident(_, ref path1, _) if
path1.node.name ==
parse::token::special_idents::invalid.name => {
// Do nothing.
diff --git a/src/librustc_front/util.rs b/src/librustc_front/util.rs
index 5d936fae6ec0a..8140ea1f167d8 100644
--- a/src/librustc_front/util.rs
+++ b/src/librustc_front/util.rs
@@ -28,27 +28,28 @@ pub fn walk_pat(pat: &Pat, mut it: F) -> bool
}
match pat.node {
- PatIdent(_, _, Some(ref p)) => walk_pat_(&p, it),
- PatStruct(_, ref fields, _) => {
+ PatKind::Ident(_, _, Some(ref p)) => walk_pat_(&p, it),
+ PatKind::Struct(_, ref fields, _) => {
fields.iter().all(|field| walk_pat_(&field.node.pat, it))
}
- PatEnum(_, Some(ref s)) | PatTup(ref s) => {
+ PatKind::TupleStruct(_, Some(ref s)) | PatKind::Tup(ref s) => {
s.iter().all(|p| walk_pat_(&p, it))
}
- PatBox(ref s) | PatRegion(ref s, _) => {
+ PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
walk_pat_(&s, it)
}
- PatVec(ref before, ref slice, ref after) => {
+ PatKind::Vec(ref before, ref slice, ref after) => {
before.iter().all(|p| walk_pat_(&p, it)) &&
slice.iter().all(|p| walk_pat_(&p, it)) &&
after.iter().all(|p| walk_pat_(&p, it))
}
- PatWild |
- PatLit(_) |
- PatRange(_, _) |
- PatIdent(_, _, _) |
- PatEnum(_, _) |
- PatQPath(_, _) => {
+ PatKind::Wild |
+ PatKind::Lit(_) |
+ PatKind::Range(_, _) |
+ PatKind::Ident(_, _, _) |
+ PatKind::TupleStruct(..) |
+ PatKind::Path(..) |
+ PatKind::QPath(_, _) => {
true
}
}
diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs
index 367475a14a2e6..16ef6e001ddbd 100644
--- a/src/librustc_lint/bad_style.rs
+++ b/src/librustc_lint/bad_style.rs
@@ -17,7 +17,7 @@ use syntax::ast;
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::Span;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit::FnKind;
#[derive(PartialEq)]
@@ -272,7 +272,7 @@ impl LateLintPass for NonSnakeCase {
}
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
- if let &hir::PatIdent(_, ref path1, _) = &p.node {
+ if let &PatKind::Ident(_, ref path1, _) = &p.node {
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
if let Some(Def::Local(..)) = def {
self.check_snake_case(cx, "variable", &path1.node.name.as_str(), Some(p.span));
@@ -362,7 +362,7 @@ impl LateLintPass for NonUpperCaseGlobals {
fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
// Lint for constants that look like binding identifiers (#7526)
match (&p.node, cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def())) {
- (&hir::PatIdent(_, ref path1, _), Some(Def::Const(..))) => {
+ (&PatKind::Ident(_, ref path1, _), Some(Def::Const(..))) => {
NonUpperCaseGlobals::check_upper_case(cx, "constant in pattern",
path1.node.name, p.span);
}
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index ed16a11f5501a..2780baa6de3fd 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -46,7 +46,7 @@ use syntax::{ast};
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{self, Span};
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit::FnKind;
use bad_style::{MethodLateContext, method_context};
@@ -157,7 +157,7 @@ impl LintPass for NonShorthandFieldPatterns {
impl LateLintPass for NonShorthandFieldPatterns {
fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) {
let def_map = cx.tcx.def_map.borrow();
- if let hir::PatStruct(_, ref v, _) = pat.node {
+ if let PatKind::Struct(_, ref v, _) = pat.node {
let field_pats = v.iter().filter(|fieldpat| {
if fieldpat.node.is_shorthand {
return false;
@@ -170,7 +170,7 @@ impl LateLintPass for NonShorthandFieldPatterns {
}
});
for fieldpat in field_pats {
- if let hir::PatIdent(_, ident, None) = fieldpat.node.pat.node {
+ if let PatKind::Ident(_, ident, None) = fieldpat.node.pat.node {
if ident.node.unhygienic_name == fieldpat.node.name {
cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span,
&format!("the `{}:` in this pattern is redundant and can \
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index 207a680a13d80..d707c61cbb440 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -50,7 +50,7 @@ use syntax::parse::token::special_idents;
use syntax;
use rbml::writer::Encoder;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit::Visitor;
use rustc_front::intravisit;
@@ -783,7 +783,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
rbml_w.start_tag(tag_method_argument_names);
for arg in &decl.inputs {
let tag = tag_method_argument_name;
- if let hir::PatIdent(_, ref path1, _) = arg.pat.node {
+ if let PatKind::Ident(_, ref path1, _) = arg.pat.node {
let name = path1.node.name.as_str();
rbml_w.wr_tagged_bytes(tag, name.as_bytes());
} else {
diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs
index 5985a88382e2f..c5b34d9246694 100644
--- a/src/librustc_mir/hair/cx/pattern.rs
+++ b/src/librustc_mir/hair/cx/pattern.rs
@@ -16,7 +16,7 @@ use rustc::middle::def::Def;
use rustc::middle::pat_util::{pat_is_resolved_const, pat_is_binding};
use rustc::middle::ty::{self, Ty};
use rustc::mir::repr::*;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use syntax::ast;
use syntax::codemap::Span;
use syntax::ptr::P;
@@ -64,14 +64,14 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
fn to_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
let kind = match pat.node {
- hir::PatWild => PatternKind::Wild,
+ PatKind::Wild => PatternKind::Wild,
- hir::PatLit(ref value) => {
+ PatKind::Lit(ref value) => {
let value = const_eval::eval_const_expr(self.cx.tcx, value);
PatternKind::Constant { value: value }
}
- hir::PatRange(ref lo, ref hi) => {
+ PatKind::Range(ref lo, ref hi) => {
let lo = const_eval::eval_const_expr(self.cx.tcx, lo);
let lo = Literal::Value { value: lo };
let hi = const_eval::eval_const_expr(self.cx.tcx, hi);
@@ -79,7 +79,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
PatternKind::Range { lo: lo, hi: hi }
},
- hir::PatEnum(..) | hir::PatIdent(..) | hir::PatQPath(..)
+ PatKind::Path(..) | PatKind::Ident(..) | PatKind::QPath(..)
if pat_is_resolved_const(&self.cx.tcx.def_map.borrow(), pat) =>
{
let def = self.cx.tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
@@ -105,12 +105,12 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
}
}
- hir::PatRegion(ref subpattern, _) |
- hir::PatBox(ref subpattern) => {
+ PatKind::Ref(ref subpattern, _) |
+ PatKind::Box(ref subpattern) => {
PatternKind::Deref { subpattern: self.to_pattern(subpattern) }
}
- hir::PatVec(ref prefix, ref slice, ref suffix) => {
+ PatKind::Vec(ref prefix, ref slice, ref suffix) => {
let ty = self.cx.tcx.node_id_to_type(pat.id);
match ty.sty {
ty::TyRef(_, mt) =>
@@ -134,7 +134,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
}
}
- hir::PatTup(ref subpatterns) => {
+ PatKind::Tup(ref subpatterns) => {
let subpatterns =
subpatterns.iter()
.enumerate()
@@ -147,7 +147,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
PatternKind::Leaf { subpatterns: subpatterns }
}
- hir::PatIdent(bm, ref ident, ref sub)
+ PatKind::Ident(bm, ref ident, ref sub)
if pat_is_binding(&self.cx.tcx.def_map.borrow(), pat) =>
{
let id = match self.binding_map {
@@ -179,11 +179,11 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
}
}
- hir::PatIdent(..) => {
+ PatKind::Ident(..) | PatKind::Path(..) => {
self.variant_or_leaf(pat, vec![])
}
- hir::PatEnum(_, ref opt_subpatterns) => {
+ PatKind::TupleStruct(_, ref opt_subpatterns) => {
let subpatterns =
opt_subpatterns.iter()
.flat_map(|v| v.iter())
@@ -196,7 +196,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
self.variant_or_leaf(pat, subpatterns)
}
- hir::PatStruct(_, ref fields, _) => {
+ PatKind::Struct(_, ref fields, _) => {
let pat_ty = self.cx.tcx.node_id_to_type(pat.id);
let adt_def = match pat_ty.sty {
ty::TyStruct(adt_def, _) | ty::TyEnum(adt_def, _) => adt_def,
@@ -229,7 +229,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
self.variant_or_leaf(pat, subpatterns)
}
- hir::PatQPath(..) => {
+ PatKind::QPath(..) => {
self.cx.tcx.sess.span_bug(pat.span, "unexpanded macro or bad constant etc");
}
};
diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs
index c3699735ae867..ee6003f713e7b 100644
--- a/src/librustc_passes/consts.rs
+++ b/src/librustc_passes/consts.rs
@@ -41,7 +41,7 @@ use rustc::util::nodemap::NodeMap;
use rustc::middle::const_qualif::ConstQualif;
use rustc::lint::builtin::CONST_ERR;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use syntax::ast;
use syntax::codemap::Span;
use syntax::feature_gate::UnstableFeatures;
@@ -322,10 +322,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
fn visit_pat(&mut self, p: &hir::Pat) {
match p.node {
- hir::PatLit(ref lit) => {
+ PatKind::Lit(ref lit) => {
self.global_expr(Mode::Const, &lit);
}
- hir::PatRange(ref start, ref end) => {
+ PatKind::Range(ref start, ref end) => {
self.global_expr(Mode::Const, &start);
self.global_expr(Mode::Const, &end);
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 85c2fe0c0a568..1424616e792f6 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -33,7 +33,7 @@ use self::FieldName::*;
use std::cmp;
use std::mem::replace;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit::{self, Visitor};
use rustc::dep_graph::DepNode;
@@ -920,7 +920,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
if self.in_foreign { return }
match pattern.node {
- hir::PatStruct(_, ref fields, _) => {
+ PatKind::Struct(_, ref fields, _) => {
let adt = self.tcx.pat_ty(pattern).ty_adt_def().unwrap();
let def = self.tcx.def_map.borrow().get(&pattern.id).unwrap().full_def();
let variant = adt.variant_of_def(def);
@@ -932,11 +932,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
// Patterns which bind no fields are allowable (the path is check
// elsewhere).
- hir::PatEnum(_, Some(ref fields)) => {
+ PatKind::TupleStruct(_, Some(ref fields)) => {
match self.tcx.pat_ty(pattern).sty {
ty::TyStruct(def, _) => {
for (i, field) in fields.iter().enumerate() {
- if let hir::PatWild = field.node {
+ if let PatKind::Wild = field.node {
continue
}
self.check_field(field.span,
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index f0e4d7578e373..22b28865effd8 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -80,8 +80,7 @@ use rustc_front::hir::{ImplItem, Item, ItemConst, ItemEnum, ItemExternCrate};
use rustc_front::hir::{ItemFn, ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaultImpl};
use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse};
use rustc_front::hir::Local;
-use rustc_front::hir::{Pat, PatEnum, PatIdent, PatLit, PatQPath};
-use rustc_front::hir::{PatRange, PatStruct, Path, PrimTy};
+use rustc_front::hir::{Pat, PatKind, Path, PrimTy};
use rustc_front::hir::{TraitRef, Ty, TyBool, TyChar, TyFloat, TyInt};
use rustc_front::hir::{TyRptr, TyStr, TyUint, TyPath, TyPtr};
use rustc_front::util::walk_pat;
@@ -2362,8 +2361,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let pat_id = pattern.id;
walk_pat(pattern, |pattern| {
match pattern.node {
- PatIdent(binding_mode, ref path1, ref at_rhs) => {
- // The meaning of PatIdent with no type parameters
+ PatKind::Ident(binding_mode, ref path1, ref at_rhs) => {
+ // The meaning of PatKind::Ident with no type parameters
// depends on whether an enum variant or unit-like struct
// with that name is in scope. The probing lookup has to
// be careful not to emit spurious errors. Only matching
@@ -2474,7 +2473,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}
- PatEnum(ref path, _) => {
+ PatKind::TupleStruct(ref path, _) | PatKind::Path(ref path) => {
// This must be an enum variant, struct or const.
let resolution = match self.resolve_possibly_assoc_item(pat_id,
None,
@@ -2482,16 +2481,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ValueNS,
false) {
// The below shouldn't happen because all
- // qualified paths should be in PatQPath.
+ // qualified paths should be in PatKind::QPath.
TypecheckRequired =>
self.session.span_bug(path.span,
- "resolve_possibly_assoc_item claimed
- \
- that a path in PatEnum requires typecheck
- \
- to resolve, but qualified paths should be
- \
- PatQPath"),
+ "resolve_possibly_assoc_item claimed that a path \
+ in PatKind::Path or PatKind::TupleStruct \
+ requires typecheck to resolve, but qualified \
+ paths should be PatKind::QPath"),
ResolveAttempt(resolution) => resolution,
};
if let Some(path_res) = resolution {
@@ -2550,7 +2546,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
intravisit::walk_path(self, path);
}
- PatQPath(ref qself, ref path) => {
+ PatKind::QPath(ref qself, ref path) => {
// Associated constants only.
let resolution = match self.resolve_possibly_assoc_item(pat_id,
Some(qself),
@@ -2605,7 +2601,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
intravisit::walk_pat(self, pattern);
}
- PatStruct(ref path, _, _) => {
+ PatKind::Struct(ref path, _, _) => {
match self.resolve_path(pat_id, path, 0, TypeNS, false) {
Some(definition) => {
self.record_def(pattern.id, definition);
@@ -2624,7 +2620,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
intravisit::walk_path(self, path);
}
- PatLit(_) | PatRange(..) => {
+ PatKind::Lit(_) | PatKind::Range(..) => {
intravisit::walk_pat(self, pattern);
}
diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs
index 70f8e268f1745..c5efc9b7e2286 100644
--- a/src/librustc_trans/trans/_match.rs
+++ b/src/librustc_trans/trans/_match.rs
@@ -227,7 +227,7 @@ use std::cell::RefCell;
use std::cmp::Ordering;
use std::fmt;
use std::rc::Rc;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use syntax::ast::{self, DUMMY_NODE_ID, NodeId};
use syntax::codemap::Span;
use rustc_front::fold::Folder;
@@ -424,7 +424,7 @@ impl<'a, 'p, 'blk, 'tcx> fmt::Debug for Match<'a, 'p, 'blk, 'tcx> {
fn has_nested_bindings(m: &[Match], col: usize) -> bool {
for br in m {
match br.pats[col].node {
- hir::PatIdent(_, _, Some(_)) => return true,
+ PatKind::Ident(_, _, Some(_)) => return true,
_ => ()
}
}
@@ -477,7 +477,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let mut pat = br.pats[col];
loop {
pat = match pat.node {
- hir::PatIdent(_, ref path, Some(ref inner)) => {
+ PatKind::Ident(_, ref path, Some(ref inner)) => {
bound_ptrs.push((path.node.name, val.val));
&inner
},
@@ -517,13 +517,13 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
let this = br.pats[col];
let mut bound_ptrs = br.bound_ptrs.clone();
match this.node {
- hir::PatIdent(_, ref path, None) => {
+ PatKind::Ident(_, ref path, None) => {
if pat_is_binding(&dm.borrow(), &this) {
bound_ptrs.push((path.node.name, val.val));
}
}
- hir::PatVec(ref before, Some(ref slice), ref after) => {
- if let hir::PatIdent(_, ref path, None) = slice.node {
+ PatKind::Vec(ref before, Some(ref slice), ref after) => {
+ if let PatKind::Ident(_, ref path, None) = slice.node {
let subslice_val = bind_subslice_pat(
bcx, this.id, val,
before.len(), after.len());
@@ -662,10 +662,11 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
};
let opt = match cur.node {
- hir::PatLit(ref l) => {
+ PatKind::Lit(ref l) => {
ConstantValue(ConstantExpr(&l), debug_loc)
}
- hir::PatIdent(..) | hir::PatEnum(..) | hir::PatStruct(..) => {
+ PatKind::Ident(..) | PatKind::Path(..) |
+ PatKind::TupleStruct(..) | PatKind::Struct(..) => {
// This is either an enum variant or a variable binding.
let opt_def = tcx.def_map.borrow().get(&cur.id).map(|d| d.full_def());
match opt_def {
@@ -679,13 +680,13 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
_ => continue
}
}
- hir::PatRange(ref l1, ref l2) => {
+ PatKind::Range(ref l1, ref l2) => {
ConstantRange(ConstantExpr(&l1), ConstantExpr(&l2), debug_loc)
}
- hir::PatVec(ref before, None, ref after) => {
+ PatKind::Vec(ref before, None, ref after) => {
SliceLengthEqual(before.len() + after.len(), debug_loc)
}
- hir::PatVec(ref before, Some(_), ref after) => {
+ PatKind::Vec(ref before, Some(_), ref after) => {
SliceLengthGreaterOrEqual(before.len(), after.len(), debug_loc)
}
_ => continue
@@ -786,28 +787,23 @@ macro_rules! any_pat {
}
fn any_uniq_pat(m: &[Match], col: usize) -> bool {
- any_pat!(m, col, hir::PatBox(_))
+ any_pat!(m, col, PatKind::Box(_))
}
fn any_region_pat(m: &[Match], col: usize) -> bool {
- any_pat!(m, col, hir::PatRegion(..))
+ any_pat!(m, col, PatKind::Ref(..))
}
fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: usize) -> bool {
m.iter().any(|br| {
let pat = br.pats[col];
match pat.node {
- hir::PatTup(_) => true,
- hir::PatStruct(..) => {
- match tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Variant(..)) => false,
- _ => true,
- }
- }
- hir::PatEnum(..) | hir::PatIdent(_, _, None) => {
- match tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Struct(..)) => true,
- _ => false
+ PatKind::Tup(_) => true,
+ PatKind::Struct(..) | PatKind::TupleStruct(..) |
+ PatKind::Path(..) | PatKind::Ident(_, _, None) => {
+ match tcx.def_map.borrow().get(&pat.id).unwrap().full_def() {
+ Def::Struct(..) | Def::TyAlias(..) => true,
+ _ => false,
}
}
_ => false
@@ -849,7 +845,7 @@ impl FailureHandler {
fn pick_column_to_specialize(def_map: &RefCell, m: &[Match]) -> Option {
fn pat_score(def_map: &RefCell, pat: &hir::Pat) -> usize {
match pat.node {
- hir::PatIdent(_, _, Some(ref inner)) => pat_score(def_map, &inner),
+ PatKind::Ident(_, _, Some(ref inner)) => pat_score(def_map, &inner),
_ if pat_is_refutable(&def_map.borrow(), pat) => 1,
_ => 0
}
@@ -871,7 +867,7 @@ fn pick_column_to_specialize(def_map: &RefCell, m: &[Match]) -> Option bool {
m.iter().any(|row| match row.pats[col].node {
- hir::PatWild => false,
+ PatKind::Wild => false,
_ => true
})
};
@@ -1639,7 +1635,7 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>,
// to the default arm.
let has_default = arms.last().map_or(false, |arm| {
arm.pats.len() == 1
- && arm.pats.last().unwrap().node == hir::PatWild
+ && arm.pats.last().unwrap().node == PatKind::Wild
});
compile_submatch(bcx, &matches[..], &[discr_datum.match_input()], &chk, has_default);
@@ -1812,7 +1808,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let tcx = bcx.tcx();
let ccx = bcx.ccx();
match pat.node {
- hir::PatIdent(pat_binding_mode, ref path1, ref inner) => {
+ PatKind::Ident(pat_binding_mode, ref path1, ref inner) => {
if pat_is_binding(&tcx.def_map.borrow(), &pat) {
// Allocate the stack slot where the value of this
// binding will live and place it into the appropriate
@@ -1849,7 +1845,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
bcx = bind_irrefutable_pat(bcx, &inner_pat, val, cleanup_scope);
}
}
- hir::PatEnum(_, ref sub_pats) => {
+ PatKind::TupleStruct(_, ref sub_pats) => {
let opt_def = bcx.tcx().def_map.borrow().get(&pat.id).map(|d| d.full_def());
match opt_def {
Some(Def::Variant(enum_id, var_id)) => {
@@ -1895,7 +1891,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
}
}
- hir::PatStruct(_, ref fields, _) => {
+ PatKind::Struct(_, ref fields, _) => {
let tcx = bcx.tcx();
let pat_ty = node_id_type(bcx, pat.id);
let pat_repr = adt::represent_type(bcx.ccx(), pat_ty);
@@ -1935,7 +1931,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
cleanup_scope);
}
}
- hir::PatTup(ref elems) => {
+ PatKind::Tup(ref elems) => {
let repr = adt::represent_node(bcx, pat.id);
let val = adt::MaybeSizedValue::sized(val.val);
for (i, elem) in elems.iter().enumerate() {
@@ -1947,13 +1943,13 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
cleanup_scope);
}
}
- hir::PatBox(ref inner) => {
+ PatKind::Box(ref inner) => {
let pat_ty = node_id_type(bcx, inner.id);
// Pass along DSTs as fat pointers.
let val = if type_is_fat_ptr(tcx, pat_ty) {
// We need to check for this, as the pattern could be binding
// a fat pointer by-value.
- if let hir::PatIdent(hir::BindByRef(_),_,_) = inner.node {
+ if let PatKind::Ident(hir::BindByRef(_),_,_) = inner.node {
val.val
} else {
Load(bcx, val.val)
@@ -1966,13 +1962,13 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
bcx = bind_irrefutable_pat(
bcx, &inner, MatchInput::from_val(val), cleanup_scope);
}
- hir::PatRegion(ref inner, _) => {
+ PatKind::Ref(ref inner, _) => {
let pat_ty = node_id_type(bcx, inner.id);
// Pass along DSTs as fat pointers.
let val = if type_is_fat_ptr(tcx, pat_ty) {
// We need to check for this, as the pattern could be binding
// a fat pointer by-value.
- if let hir::PatIdent(hir::BindByRef(_),_,_) = inner.node {
+ if let PatKind::Ident(hir::BindByRef(_),_,_) = inner.node {
val.val
} else {
Load(bcx, val.val)
@@ -1988,7 +1984,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
MatchInput::from_val(val),
cleanup_scope);
}
- hir::PatVec(ref before, ref slice, ref after) => {
+ PatKind::Vec(ref before, ref slice, ref after) => {
let pat_ty = node_id_type(bcx, pat.id);
let mut extracted = extract_vec_elems(bcx, pat_ty, before.len(), after.len(), val);
match slice {
@@ -2013,8 +2009,8 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
cleanup_scope)
});
}
- hir::PatQPath(..) | hir::PatWild | hir::PatLit(_) |
- hir::PatRange(_, _) => ()
+ PatKind::Path(..) | PatKind::QPath(..) | PatKind::Wild | PatKind::Lit(_) |
+ PatKind::Range(_, _) => ()
}
return bcx;
}
diff --git a/src/librustc_trans/trans/debuginfo/create_scope_map.rs b/src/librustc_trans/trans/debuginfo/create_scope_map.rs
index bbbc9c4eda468..73fdbd54b29d0 100644
--- a/src/librustc_trans/trans/debuginfo/create_scope_map.rs
+++ b/src/librustc_trans/trans/debuginfo/create_scope_map.rs
@@ -22,7 +22,7 @@ use syntax::codemap::{Span, Pos};
use syntax::{ast, codemap};
use rustc_front;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
// This procedure builds the *scope map* for a given function, which maps any
// given ast::NodeId in the function's AST to the correct DIScope metadata instance.
@@ -163,7 +163,7 @@ fn walk_pattern(cx: &CrateContext,
// ast_util::walk_pat() here because we have to visit *all* nodes in
// order to put them into the scope map. The above functions don't do that.
match pat.node {
- hir::PatIdent(_, ref path1, ref sub_pat_opt) => {
+ PatKind::Ident(_, ref path1, ref sub_pat_opt) => {
// Check if this is a binding. If so we need to put it on the
// scope stack and maybe introduce an artificial scope
@@ -235,11 +235,11 @@ fn walk_pattern(cx: &CrateContext,
}
}
- hir::PatWild => {
+ PatKind::Wild => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
}
- hir::PatEnum(_, ref sub_pats_opt) => {
+ PatKind::TupleStruct(_, ref sub_pats_opt) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
if let Some(ref sub_pats) = *sub_pats_opt {
@@ -249,11 +249,11 @@ fn walk_pattern(cx: &CrateContext,
}
}
- hir::PatQPath(..) => {
+ PatKind::Path(..) | PatKind::QPath(..) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
}
- hir::PatStruct(_, ref field_pats, _) => {
+ PatKind::Struct(_, ref field_pats, _) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
for &codemap::Spanned {
@@ -264,7 +264,7 @@ fn walk_pattern(cx: &CrateContext,
}
}
- hir::PatTup(ref sub_pats) => {
+ PatKind::Tup(ref sub_pats) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
for sub_pat in sub_pats {
@@ -272,23 +272,23 @@ fn walk_pattern(cx: &CrateContext,
}
}
- hir::PatBox(ref sub_pat) | hir::PatRegion(ref sub_pat, _) => {
+ PatKind::Box(ref sub_pat) | PatKind::Ref(ref sub_pat, _) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
walk_pattern(cx, &sub_pat, scope_stack, scope_map);
}
- hir::PatLit(ref exp) => {
+ PatKind::Lit(ref exp) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
walk_expr(cx, &exp, scope_stack, scope_map);
}
- hir::PatRange(ref exp1, ref exp2) => {
+ PatKind::Range(ref exp1, ref exp2) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
walk_expr(cx, &exp1, scope_stack, scope_map);
walk_expr(cx, &exp2, scope_stack, scope_map);
}
- hir::PatVec(ref front_sub_pats, ref middle_sub_pats, ref back_sub_pats) => {
+ PatKind::Vec(ref front_sub_pats, ref middle_sub_pats, ref back_sub_pats) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
for sub_pat in front_sub_pats {
diff --git a/src/librustc_trans/trans/debuginfo/metadata.rs b/src/librustc_trans/trans/debuginfo/metadata.rs
index 843aebc443722..330d4077c4101 100644
--- a/src/librustc_trans/trans/debuginfo/metadata.rs
+++ b/src/librustc_trans/trans/debuginfo/metadata.rs
@@ -28,7 +28,7 @@ use middle::infer;
use middle::pat_util;
use middle::subst;
use rustc::front::map as hir_map;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use trans::{type_of, adt, machine, monomorphize};
use trans::common::{self, CrateContext, FunctionContext, Block};
use trans::_match::{BindingInfo, TransBindingMode};
@@ -1971,7 +1971,7 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
}
Some(hir_map::NodeLocal(pat)) => {
match pat.node {
- hir::PatIdent(_, ref path1, _) => {
+ PatKind::Ident(_, ref path1, _) => {
path1.node.name
}
_ => {
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index 6ca48f2d8d484..bd2c7b3915363 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -30,7 +30,7 @@ use syntax::ast;
use syntax::codemap::{Span, Spanned};
use syntax::ptr::P;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::print::pprust;
use rustc_front::util as hir_util;
@@ -46,10 +46,10 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
expected);
match pat.node {
- hir::PatWild => {
+ PatKind::Wild => {
fcx.write_ty(pat.id, expected);
}
- hir::PatLit(ref lt) => {
+ PatKind::Lit(ref lt) => {
check_expr(fcx, <);
let expr_ty = fcx.expr_ty(<);
@@ -84,7 +84,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// that's equivalent to there existing a LUB.
demand::suptype(fcx, pat.span, expected, pat_ty);
}
- hir::PatRange(ref begin, ref end) => {
+ PatKind::Range(ref begin, ref end) => {
check_expr(fcx, begin);
check_expr(fcx, end);
@@ -135,14 +135,8 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// subtyping doesn't matter here, as the value is some kind of scalar
demand::eqtype(fcx, pat.span, expected, lhs_ty);
}
- hir::PatEnum(..) | hir::PatIdent(..)
+ PatKind::Path(..) | PatKind::Ident(..)
if pat_is_resolved_const(&tcx.def_map.borrow(), pat) => {
- if let hir::PatEnum(ref path, ref subpats) = pat.node {
- if !(subpats.is_some() && subpats.as_ref().unwrap().is_empty()) {
- bad_struct_kind_err(tcx.sess, pat, path, false);
- return;
- }
- }
if let Some(pat_def) = tcx.def_map.borrow().get(&pat.id) {
let const_did = pat_def.def_id();
let const_scheme = tcx.lookup_item_type(const_did);
@@ -154,7 +148,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// FIXME(#20489) -- we should limit the types here to scalars or something!
- // As with PatLit, what we really want here is that there
+ // As with PatKind::Lit, what we really want here is that there
// exist a LUB, but for the cases that can occur, subtype
// is good enough.
demand::suptype(fcx, pat.span, expected, const_ty);
@@ -162,7 +156,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
fcx.write_error(pat.id);
}
}
- hir::PatIdent(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map.borrow(), pat) => {
+ PatKind::Ident(bm, ref path, ref sub) if pat_is_binding(&tcx.def_map.borrow(), pat) => {
let typ = fcx.local_ty(pat.span, pat.id);
match bm {
hir::BindByRef(mutbl) => {
@@ -202,16 +196,17 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
}
}
}
- hir::PatIdent(_, ref path, _) => {
+ PatKind::Ident(_, ref path, _) => {
let path = hir_util::ident_to_path(path.span, path.node);
check_pat_enum(pcx, pat, &path, Some(&[]), expected, false);
}
- hir::PatEnum(ref path, ref subpats) => {
- let subpats = subpats.as_ref().map(|v| &v[..]);
- let is_tuple_struct_pat = !(subpats.is_some() && subpats.unwrap().is_empty());
- check_pat_enum(pcx, pat, path, subpats, expected, is_tuple_struct_pat);
+ PatKind::TupleStruct(ref path, ref subpats) => {
+ check_pat_enum(pcx, pat, path, subpats.as_ref().map(|v| &v[..]), expected, true);
+ }
+ PatKind::Path(ref path) => {
+ check_pat_enum(pcx, pat, path, None, expected, false);
}
- hir::PatQPath(ref qself, ref path) => {
+ PatKind::QPath(ref qself, ref path) => {
let self_ty = fcx.to_ty(&qself.ty);
let path_res = if let Some(&d) = tcx.def_map.borrow().get(&pat.id) {
if d.base_def == Def::Err {
@@ -248,10 +243,10 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
}
}
}
- hir::PatStruct(ref path, ref fields, etc) => {
+ PatKind::Struct(ref path, ref fields, etc) => {
check_pat_struct(pcx, pat, path, fields, etc, expected);
}
- hir::PatTup(ref elements) => {
+ PatKind::Tup(ref elements) => {
let element_tys: Vec<_> =
(0..elements.len()).map(|_| fcx.infcx().next_ty_var())
.collect();
@@ -262,7 +257,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
check_pat(pcx, &element_pat, element_ty);
}
}
- hir::PatBox(ref inner) => {
+ PatKind::Box(ref inner) => {
let inner_ty = fcx.infcx().next_ty_var();
let uniq_ty = tcx.mk_box(inner_ty);
@@ -278,7 +273,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
check_pat(pcx, &inner, tcx.types.err);
}
}
- hir::PatRegion(ref inner, mutbl) => {
+ PatKind::Ref(ref inner, mutbl) => {
let expected = fcx.infcx().shallow_resolve(expected);
if check_dereferencable(pcx, pat.span, expected, &inner) {
// `demand::subtype` would be good enough, but using
@@ -310,7 +305,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
check_pat(pcx, &inner, tcx.types.err);
}
}
- hir::PatVec(ref before, ref slice, ref after) => {
+ PatKind::Vec(ref before, ref slice, ref after) => {
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
let inner_ty = fcx.infcx().next_ty_var();
let pat_ty = match expected_ty.sty {
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 6a7bc9b61116d..208c166dedf19 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -127,7 +127,7 @@ use syntax::util::lev_distance::find_best_match_for_name;
use rustc_front::intravisit::{self, Visitor};
use rustc_front::hir;
-use rustc_front::hir::Visibility;
+use rustc_front::hir::{Visibility, PatKind};
use rustc_front::print::pprust;
use rustc_back::slice;
@@ -506,7 +506,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
// Add pattern bindings.
fn visit_pat(&mut self, p: &'tcx hir::Pat) {
- if let hir::PatIdent(_, ref path1, _) = p.node {
+ if let PatKind::Ident(_, ref path1, _) = p.node {
if pat_util::pat_is_binding(&self.fcx.ccx.tcx.def_map.borrow(), p) {
let var_ty = self.assign(p.span, p.id, None);
diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs
index 2335b76626b17..e399818779ecf 100644
--- a/src/librustc_typeck/check/regionck.rs
+++ b/src/librustc_typeck/check/regionck.rs
@@ -101,7 +101,7 @@ use std::mem;
use syntax::ast;
use syntax::codemap::Span;
use rustc_front::intravisit::{self, Visitor};
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::util as hir_util;
use self::SubjectNode::Subject;
@@ -1190,14 +1190,14 @@ fn link_pattern<'t, 'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
let _ = mc.cat_pattern(discr_cmt, root_pat, |mc, sub_cmt, sub_pat| {
match sub_pat.node {
// `ref x` pattern
- hir::PatIdent(hir::BindByRef(mutbl), _, _) => {
+ PatKind::Ident(hir::BindByRef(mutbl), _, _) => {
link_region_from_node_type(
rcx, sub_pat.span, sub_pat.id,
mutbl, sub_cmt);
}
// `[_, ..slice, _]` pattern
- hir::PatVec(_, Some(ref slice_pat), _) => {
+ PatKind::Vec(_, Some(ref slice_pat), _) => {
match mc.cat_slice_pattern(sub_cmt, &slice_pat) {
Ok((slice_cmt, slice_mutbl, slice_r)) => {
link_region(rcx, sub_pat.span, &slice_r,
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index cae2d9d890d79..026881927cb21 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -90,7 +90,7 @@ use syntax::attr;
use syntax::codemap::Span;
use syntax::parse::token::special_idents;
use syntax::ptr::P;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit;
use rustc_front::print::pprust;
@@ -2121,8 +2121,8 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
{
for i in &decl.inputs {
match i.pat.node {
- hir::PatIdent(_, _, _) => (),
- hir::PatWild => (),
+ PatKind::Ident(_, _, _) => (),
+ PatKind::Wild => (),
_ => {
span_err!(ccx.tcx.sess, i.pat.span, E0130,
"patterns aren't allowed in foreign function declarations");
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index d6e4b7e4a51d6..7072f1b498bb9 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2552,12 +2552,12 @@ fn name_from_pat(p: &hir::Pat) -> String {
debug!("Trying to get a name from pattern: {:?}", p);
match p.node {
- PatWild => "_".to_string(),
- PatIdent(_, ref p, _) => p.node.to_string(),
- PatEnum(ref p, _) => path_to_string(p),
- PatQPath(..) => panic!("tried to get argument name from PatQPath, \
+ PatKind::Wild => "_".to_string(),
+ PatKind::Ident(_, ref p, _) => p.node.to_string(),
+ PatKind::TupleStruct(ref p, _) | PatKind::Path(ref p) => path_to_string(p),
+ PatKind::QPath(..) => panic!("tried to get argument name from PatKind::QPath, \
which is not allowed in function arguments"),
- PatStruct(ref name, ref fields, etc) => {
+ PatKind::Struct(ref name, ref fields, etc) => {
format!("{} {{ {}{} }}", path_to_string(name),
fields.iter().map(|&Spanned { node: ref fp, .. }|
format!("{}: {}", fp.name, name_from_pat(&*fp.pat)))
@@ -2565,18 +2565,18 @@ fn name_from_pat(p: &hir::Pat) -> String {
if etc { ", ..." } else { "" }
)
},
- PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
+ PatKind::Tup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
.collect::>().join(", ")),
- PatBox(ref p) => name_from_pat(&**p),
- PatRegion(ref p, _) => name_from_pat(&**p),
- PatLit(..) => {
- warn!("tried to get argument name from PatLit, \
+ PatKind::Box(ref p) => name_from_pat(&**p),
+ PatKind::Ref(ref p, _) => name_from_pat(&**p),
+ PatKind::Lit(..) => {
+ warn!("tried to get argument name from PatKind::Lit, \
which is silly in function arguments");
"()".to_string()
},
- PatRange(..) => panic!("tried to get argument name from PatRange, \
+ PatKind::Range(..) => panic!("tried to get argument name from PatKind::Range, \
which is not allowed in function arguments"),
- PatVec(ref begin, ref mid, ref end) => {
+ PatKind::Vec(ref begin, ref mid, ref end) => {
let begin = begin.iter().map(|p| name_from_pat(&**p));
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();
let end = end.iter().map(|p| name_from_pat(&**p));
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index cb79c609c1bfc..23bb6fd141a4e 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -580,7 +580,7 @@ pub enum PatKind {
/// An associated const named using the qualified path `::CONST` or
/// `::CONST`. Associated consts from inherent impls can be
/// referred to as simply `T::CONST`, in which case they will end up as
- /// PatKind::Enum, and the resolver will have to sort that out.
+ /// PatKind::Path, and the resolver will have to sort that out.
QPath(QSelf, Path),
/// A tuple pattern `(a, b)`