, 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.
- Enum(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
- /// 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),
- /// Destructuring of a struct, e.g. `Foo {x, y, ..}`
- /// The `bool` is `true` in the presence of a `..`
- Struct(Path, HirVec>, bool),
/// A tuple pattern `(a, b)`
Tup(HirVec>),
/// A `box` pattern
diff --git a/src/librustc_front/intravisit.rs b/src/librustc_front/intravisit.rs
index f235a7b82344..c1bcaab9d681 100644
--- a/src/librustc_front/intravisit.rs
+++ b/src/librustc_front/intravisit.rs
@@ -468,12 +468,15 @@ 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 {
- PatKind::Enum(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);
}
}
+ 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)
diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs
index 5935594b67ff..0e7d9db37fdb 100644
--- a/src/librustc_front/lowering.rs
+++ b/src/librustc_front/lowering.rs
@@ -921,12 +921,12 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P {
}
PatKind::Lit(ref e) => hir::PatKind::Lit(lower_expr(lctx, e)),
PatKind::TupleStruct(ref pth, ref pats) => {
- hir::PatKind::Enum(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::PatKind::Enum(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 {
@@ -1750,7 +1750,11 @@ fn pat_enum(lctx: &LoweringContext,
path: hir::Path,
subpats: hir::HirVec>)
-> P {
- let pt = hir::PatKind::Enum(path, Some(subpats));
+ let pt = if subpats.is_empty() {
+ hir::PatKind::Path(path)
+ } else {
+ hir::PatKind::TupleStruct(path, Some(subpats))
+ };
pat(lctx, span, pt)
}
diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs
index dc4bd8ba474b..d837ab0f8f6c 100644
--- a/src/librustc_front/print/pprust.rs
+++ b/src/librustc_front/print/pprust.rs
@@ -1748,19 +1748,20 @@ impl<'a> State<'a> {
None => (),
}
}
- PatKind::Enum(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());
}
}
}
+ PatKind::Path(ref path) => {
+ try!(self.print_path(path, true, 0));
+ }
PatKind::QPath(ref qself, ref path) => {
try!(self.print_qpath(path, qself, false));
}
diff --git a/src/librustc_front/util.rs b/src/librustc_front/util.rs
index 12654b2b3d74..8140ea1f167d 100644
--- a/src/librustc_front/util.rs
+++ b/src/librustc_front/util.rs
@@ -32,7 +32,7 @@ pub fn walk_pat(pat: &Pat, mut it: F) -> bool
PatKind::Struct(_, ref fields, _) => {
fields.iter().all(|field| walk_pat_(&field.node.pat, it))
}
- PatKind::Enum(_, Some(ref s)) | PatKind::Tup(ref s) => {
+ PatKind::TupleStruct(_, Some(ref s)) | PatKind::Tup(ref s) => {
s.iter().all(|p| walk_pat_(&p, it))
}
PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
@@ -47,7 +47,8 @@ pub fn walk_pat(pat: &Pat, mut it: F) -> bool
PatKind::Lit(_) |
PatKind::Range(_, _) |
PatKind::Ident(_, _, _) |
- PatKind::Enum(_, _) |
+ PatKind::TupleStruct(..) |
+ PatKind::Path(..) |
PatKind::QPath(_, _) => {
true
}
diff --git a/src/librustc_mir/hair/cx/pattern.rs b/src/librustc_mir/hair/cx/pattern.rs
index fc1af0e7af16..c5b34d924669 100644
--- a/src/librustc_mir/hair/cx/pattern.rs
+++ b/src/librustc_mir/hair/cx/pattern.rs
@@ -79,7 +79,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
PatternKind::Range { lo: lo, hi: hi }
},
- PatKind::Enum(..) | PatKind::Ident(..) | PatKind::QPath(..)
+ 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();
@@ -179,11 +179,11 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
}
}
- PatKind::Ident(..) => {
+ PatKind::Ident(..) | PatKind::Path(..) => {
self.variant_or_leaf(pat, vec![])
}
- PatKind::Enum(_, ref opt_subpatterns) => {
+ PatKind::TupleStruct(_, ref opt_subpatterns) => {
let subpatterns =
opt_subpatterns.iter()
.flat_map(|v| v.iter())
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 862ab02ee954..1424616e792f 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -932,7 +932,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
// Patterns which bind no fields are allowable (the path is check
// elsewhere).
- PatKind::Enum(_, 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() {
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 2ee62e71fab1..22b28865effd 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -2473,7 +2473,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}
- PatKind::Enum(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,
@@ -2484,13 +2484,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// qualified paths should be in PatKind::QPath.
TypecheckRequired =>
self.session.span_bug(path.span,
- "resolve_possibly_assoc_item claimed
- \
- that a path in PatKind::Enum requires typecheck
- \
- to resolve, but qualified paths should be
- \
- PatKind::QPath"),
+ "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 {
diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs
index e81fe08e7b16..c5efc9b7e228 100644
--- a/src/librustc_trans/trans/_match.rs
+++ b/src/librustc_trans/trans/_match.rs
@@ -665,7 +665,8 @@ fn get_branches<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
PatKind::Lit(ref l) => {
ConstantValue(ConstantExpr(&l), debug_loc)
}
- PatKind::Ident(..) | PatKind::Enum(..) | PatKind::Struct(..) => {
+ 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 {
@@ -798,16 +799,11 @@ fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: usize) -> bool {
let pat = br.pats[col];
match pat.node {
PatKind::Tup(_) => true,
- PatKind::Struct(..) => {
- match tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Variant(..)) => false,
- _ => true,
- }
- }
- PatKind::Enum(..) | PatKind::Ident(_, _, None) => {
- match tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Struct(..)) => true,
- _ => false
+ 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
@@ -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);
}
}
- PatKind::Enum(_, 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)) => {
@@ -2013,7 +2009,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
cleanup_scope)
});
}
- PatKind::QPath(..) | PatKind::Wild | PatKind::Lit(_) |
+ 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 1589cf648653..73fdbd54b29d 100644
--- a/src/librustc_trans/trans/debuginfo/create_scope_map.rs
+++ b/src/librustc_trans/trans/debuginfo/create_scope_map.rs
@@ -239,7 +239,7 @@ fn walk_pattern(cx: &CrateContext,
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
}
- PatKind::Enum(_, 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,7 +249,7 @@ fn walk_pattern(cx: &CrateContext,
}
}
- PatKind::QPath(..) => {
+ PatKind::Path(..) | PatKind::QPath(..) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
}
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index 2803cbe4dd96..bd2c7b391536 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -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);
}
- PatKind::Enum(..) | PatKind::Ident(..)
+ PatKind::Path(..) | PatKind::Ident(..)
if pat_is_resolved_const(&tcx.def_map.borrow(), pat) => {
- if let PatKind::Enum(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);
@@ -206,10 +200,11 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let path = hir_util::ident_to_path(path.span, path.node);
check_pat_enum(pcx, pat, &path, Some(&[]), expected, false);
}
- PatKind::Enum(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);
}
PatKind::QPath(ref qself, ref path) => {
let self_ty = fcx.to_ty(&qself.ty);
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 772652eace5b..7072f1b498bb 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2554,7 +2554,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
match p.node {
PatKind::Wild => "_".to_string(),
PatKind::Ident(_, ref p, _) => p.node.to_string(),
- PatKind::Enum(ref p, _) => path_to_string(p),
+ 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"),
PatKind::Struct(ref name, ref fields, etc) => {
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index cb79c609c1bf..23bb6fd141a4 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)`