And split `PatKind::Enum` into `PatKind::TupleStruct` and `PatKind::Path`.
This is the HIR part of https://github.com/rust-lang/rust/pull/31581.
This is also kind of a preparation for https://github.com/rust-lang/rfcs/pull/1492.
r? @eddyb
fn visit_pat(&mut self, pat: &'ast Pat) {
let maybe_binding = match pat.node {
- PatIdent(_, id, _) => Some(id.node),
+ PatKind::Ident(_, id, _) => Some(id.node),
_ => None
};
NodeVariant(v) => PathName(v.node.name),
NodeLifetime(lt) => PathName(lt.name),
NodeTyParam(tp) => PathName(tp.name),
- NodeLocal(&Pat { node: PatIdent(_,l,_), .. }) => {
+ NodeLocal(&Pat { node: PatKind::Ident(_,l,_), .. }) => {
PathName(l.node.name)
},
_ => panic!("no path elem for {:?}", node)
use syntax::ast;
use syntax::ptr::P;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
struct CFGBuilder<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
match pat.node {
- hir::PatIdent(_, _, None) |
- hir::PatEnum(_, None) |
- hir::PatQPath(..) |
- hir::PatLit(..) |
- hir::PatRange(..) |
- hir::PatWild => {
+ PatKind::Ident(_, _, None) |
+ PatKind::TupleStruct(_, None) |
+ PatKind::Path(..) |
+ PatKind::QPath(..) |
+ PatKind::Lit(..) |
+ PatKind::Range(..) |
+ PatKind::Wild => {
self.add_ast_node(pat.id, &[pred])
}
- hir::PatBox(ref subpat) |
- hir::PatRegion(ref subpat, _) |
- hir::PatIdent(_, _, Some(ref subpat)) => {
+ PatKind::Box(ref subpat) |
+ PatKind::Ref(ref subpat, _) |
+ PatKind::Ident(_, _, Some(ref subpat)) => {
let subpat_exit = self.pat(&subpat, pred);
self.add_ast_node(pat.id, &[subpat_exit])
}
- hir::PatEnum(_, Some(ref subpats)) |
- hir::PatTup(ref subpats) => {
+ PatKind::TupleStruct(_, Some(ref subpats)) |
+ PatKind::Tup(ref subpats) => {
let pats_exit = self.pats_all(subpats.iter(), pred);
self.add_ast_node(pat.id, &[pats_exit])
}
- hir::PatStruct(_, ref subpats, _) => {
+ PatKind::Struct(_, ref subpats, _) => {
let pats_exit =
self.pats_all(subpats.iter().map(|f| &f.node.pat), pred);
self.add_ast_node(pat.id, &[pats_exit])
}
- hir::PatVec(ref pre, ref vec, ref post) => {
+ PatKind::Vec(ref pre, ref vec, ref post) => {
let pre_exit = self.pats_all(pre.iter(), pred);
let vec_exit = self.pats_all(vec.iter(), pre_exit);
let post_exit = self.pats_all(post.iter(), vec_exit);
use std::iter::{FromIterator, IntoIterator, repeat};
use rustc_front::hir;
-use rustc_front::hir::Pat;
+use rustc_front::hir::{Pat, PatKind};
use rustc_front::intravisit::{self, Visitor, FnKind};
use rustc_front::util as front_util;
use rustc_back::slice;
pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
id: DUMMY_NODE_ID,
- node: hir::PatWild,
+ node: PatKind::Wild,
span: DUMMY_SP
};
fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat) {
front_util::walk_pat(pat, |p| {
match p.node {
- hir::PatIdent(hir::BindByValue(hir::MutImmutable), ident, None) => {
+ PatKind::Ident(hir::BindByValue(hir::MutImmutable), ident, None) => {
let pat_ty = cx.tcx.pat_ty(p);
if let ty::TyEnum(edef, _) = pat_ty.sty {
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
// Check that we do not match against a static NaN (#6804)
fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
front_util::walk_pat(pat, |p| {
- if let hir::PatLit(ref expr) = p.node {
+ if let PatKind::Lit(ref expr) = p.node {
match eval_const_expr_partial(cx.tcx, &expr, ExprTypeChecked, None) {
Ok(ConstVal::Float(f)) if f.is_nan() => {
span_warn!(cx.tcx.sess, p.span, E0003,
fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
match p.node {
- hir::PatIdent(_, _, Some(ref s)) => raw_pat(&s),
+ PatKind::Ident(_, _, Some(ref s)) => raw_pat(&s),
_ => p
}
}
hir::MatchSource::ForLoopDesugar => {
// `witnesses[0]` has the form `Some(<head>)`, peel off the `Some`
let witness = match witnesses[0].node {
- hir::PatEnum(_, Some(ref pats)) => match &pats[..] {
+ PatKind::TupleStruct(_, Some(ref pats)) => match &pats[..] {
[ref pat] => &**pat,
_ => unreachable!(),
},
impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
fn fold_pat(&mut self, pat: P<Pat>) -> P<Pat> {
return match pat.node {
- hir::PatIdent(..) | hir::PatEnum(..) | hir::PatQPath(..) => {
+ PatKind::Ident(..) | PatKind::Path(..) | PatKind::QPath(..) => {
let def = self.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def());
match def {
Some(Def::AssociatedConst(did)) |
let pats_len = pats.len();
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
let pat = match left_ty.sty {
- ty::TyTuple(_) => hir::PatTup(pats.collect()),
+ ty::TyTuple(_) => PatKind::Tup(pats.collect()),
ty::TyEnum(adt, _) | ty::TyStruct(adt, _) => {
let v = adt.variant_of_ctor(ctor);
- if let VariantKind::Struct = v.kind() {
- let field_pats: hir::HirVec<_> = v.fields.iter()
- .zip(pats)
- .filter(|&(_, ref pat)| pat.node != hir::PatWild)
- .map(|(field, pat)| Spanned {
- span: DUMMY_SP,
- node: hir::FieldPat {
- name: field.name,
- pat: pat,
- is_shorthand: false,
- }
- }).collect();
- let has_more_fields = field_pats.len() < pats_len;
- hir::PatStruct(def_to_path(cx.tcx, v.did), field_pats, has_more_fields)
- } else {
- hir::PatEnum(def_to_path(cx.tcx, v.did), Some(pats.collect()))
+ match v.kind() {
+ VariantKind::Struct => {
+ let field_pats: hir::HirVec<_> = v.fields.iter()
+ .zip(pats)
+ .filter(|&(_, ref pat)| pat.node != PatKind::Wild)
+ .map(|(field, pat)| Spanned {
+ span: DUMMY_SP,
+ node: hir::FieldPat {
+ name: field.name,
+ pat: pat,
+ is_shorthand: false,
+ }
+ }).collect();
+ let has_more_fields = field_pats.len() < pats_len;
+ PatKind::Struct(def_to_path(cx.tcx, v.did), field_pats, has_more_fields)
+ }
+ VariantKind::Tuple => {
+ PatKind::TupleStruct(def_to_path(cx.tcx, v.did), Some(pats.collect()))
+ }
+ VariantKind::Unit => {
+ PatKind::Path(def_to_path(cx.tcx, v.did))
+ }
}
}
ty::TyArray(_, n) => match ctor {
&Single => {
assert_eq!(pats_len, n);
- hir::PatVec(pats.collect(), None, hir::HirVec::new())
+ PatKind::Vec(pats.collect(), None, hir::HirVec::new())
},
_ => unreachable!()
},
ty::TySlice(_) => match ctor {
&Slice(n) => {
assert_eq!(pats_len, n);
- hir::PatVec(pats.collect(), None, hir::HirVec::new())
+ PatKind::Vec(pats.collect(), None, hir::HirVec::new())
},
_ => unreachable!()
},
- ty::TyStr => hir::PatWild,
+ ty::TyStr => PatKind::Wild,
_ => {
assert_eq!(pats_len, 1);
- hir::PatRegion(pats.nth(0).unwrap(), mutbl)
+ PatKind::Ref(pats.nth(0).unwrap(), mutbl)
}
}
}
ty::TyArray(_, len) => {
assert_eq!(pats_len, len);
- hir::PatVec(pats.collect(), None, hir::HirVec::new())
+ PatKind::Vec(pats.collect(), None, hir::HirVec::new())
}
_ => {
match *ctor {
- ConstantValue(ref v) => hir::PatLit(const_val_to_expr(v)),
- _ => hir::PatWild,
+ ConstantValue(ref v) => PatKind::Lit(const_val_to_expr(v)),
+ _ => PatKind::Wild,
}
}
};
let left_ty = cx.tcx.pat_ty(&real_pat);
match real_pat.node {
- hir::PatIdent(hir::BindByRef(..), _, _) => {
+ PatKind::Ident(hir::BindByRef(..), _, _) => {
left_ty.builtin_deref(false, NoPreference).unwrap().ty
}
_ => left_ty,
};
let max_slice_length = rows.iter().filter_map(|row| match row[0].node {
- hir::PatVec(ref before, _, ref after) => Some(before.len() + after.len()),
+ PatKind::Vec(ref before, _, ref after) => Some(before.len() + after.len()),
_ => None
}).max().map_or(0, |v| v + 1);
left_ty: Ty, max_slice_length: usize) -> Vec<Constructor> {
let pat = raw_pat(p);
match pat.node {
- hir::PatIdent(..) =>
- match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
- cx.tcx.sess.span_bug(pat.span, "const pattern should've \
- been rewritten"),
- Some(Def::Struct(..)) => vec!(Single),
- Some(Def::Variant(_, id)) => vec!(Variant(id)),
- _ => vec!()
- },
- hir::PatEnum(..) =>
- match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
+ PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::Ident(..) =>
+ match cx.tcx.def_map.borrow().get(&pat.id).unwrap().full_def() {
+ Def::Const(..) | Def::AssociatedConst(..) =>
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
been rewritten"),
- Some(Def::Variant(_, id)) => vec!(Variant(id)),
- _ => vec!(Single)
+ Def::Struct(..) | Def::TyAlias(..) => vec![Single],
+ Def::Variant(_, id) => vec![Variant(id)],
+ Def::Local(..) => vec![],
+ def => cx.tcx.sess.span_bug(pat.span, &format!("pat_constructors: unexpected \
+ definition {:?}", def)),
},
- hir::PatQPath(..) =>
+ PatKind::QPath(..) =>
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
been rewritten"),
- hir::PatStruct(..) =>
- match cx.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
- cx.tcx.sess.span_bug(pat.span, "const pattern should've \
- been rewritten"),
- Some(Def::Variant(_, id)) => vec!(Variant(id)),
- _ => vec!(Single)
- },
- hir::PatLit(ref expr) =>
+ PatKind::Lit(ref expr) =>
vec!(ConstantValue(eval_const_expr(cx.tcx, &expr))),
- hir::PatRange(ref lo, ref hi) =>
+ PatKind::Range(ref lo, ref hi) =>
vec!(ConstantRange(eval_const_expr(cx.tcx, &lo), eval_const_expr(cx.tcx, &hi))),
- hir::PatVec(ref before, ref slice, ref after) =>
+ PatKind::Vec(ref before, ref slice, ref after) =>
match left_ty.sty {
ty::TyArray(_, _) => vec!(Single),
_ => if slice.is_some() {
vec!(Slice(before.len() + after.len()))
}
},
- hir::PatBox(_) | hir::PatTup(_) | hir::PatRegion(..) =>
+ PatKind::Box(_) | PatKind::Tup(_) | PatKind::Ref(..) =>
vec!(Single),
- hir::PatWild =>
+ PatKind::Wild =>
vec!(),
}
}
id: pat_id, ref node, span: pat_span
} = raw_pat(r[col]);
let head: Option<Vec<&Pat>> = match *node {
- hir::PatWild =>
+ PatKind::Wild =>
Some(vec![DUMMY_WILD_PAT; arity]),
- hir::PatIdent(_, _, _) => {
- let opt_def = cx.tcx.def_map.borrow().get(&pat_id).map(|d| d.full_def());
- match opt_def {
- Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) =>
+ PatKind::Path(..) | PatKind::Ident(..) => {
+ let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
+ match def {
+ Def::Const(..) | Def::AssociatedConst(..) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
been rewritten"),
- Some(Def::Variant(_, id)) => if *constructor == Variant(id) {
- Some(vec!())
- } else {
- None
- },
- _ => Some(vec![DUMMY_WILD_PAT; arity])
+ Def::Variant(_, id) if *constructor != Variant(id) => None,
+ Def::Variant(..) | Def::Struct(..) => Some(Vec::new()),
+ Def::Local(..) => Some(vec![DUMMY_WILD_PAT; arity]),
+ _ => cx.tcx.sess.span_bug(pat_span, &format!("specialize: unexpected \
+ definition {:?}", def)),
}
}
- hir::PatEnum(_, ref args) => {
+ PatKind::TupleStruct(_, ref args) => {
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
match def {
Def::Const(..) | Def::AssociatedConst(..) =>
}
}
- hir::PatQPath(_, _) => {
+ PatKind::QPath(_, _) => {
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
been rewritten")
}
- hir::PatStruct(_, ref pattern_fields, _) => {
+ PatKind::Struct(_, ref pattern_fields, _) => {
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
let adt = cx.tcx.node_id_to_type(pat_id).ty_adt_def().unwrap();
let variant = adt.variant_of_ctor(constructor);
}
}
- hir::PatTup(ref args) =>
+ PatKind::Tup(ref args) =>
Some(args.iter().map(|p| &**p).collect()),
- hir::PatBox(ref inner) | hir::PatRegion(ref inner, _) =>
+ PatKind::Box(ref inner) | PatKind::Ref(ref inner, _) =>
Some(vec![&**inner]),
- hir::PatLit(ref expr) => {
+ PatKind::Lit(ref expr) => {
let expr_value = eval_const_expr(cx.tcx, &expr);
match range_covered_by_constructor(constructor, &expr_value, &expr_value) {
Some(true) => Some(vec![]),
}
}
- hir::PatRange(ref from, ref to) => {
+ PatKind::Range(ref from, ref to) => {
let from_value = eval_const_expr(cx.tcx, &from);
let to_value = eval_const_expr(cx.tcx, &to);
match range_covered_by_constructor(constructor, &from_value, &to_value) {
}
}
- hir::PatVec(ref before, ref slice, ref after) => {
+ PatKind::Vec(ref before, ref slice, ref after) => {
match *constructor {
// Fixed-length vectors.
Single => {
front_util::walk_pat(&pat, |p| {
if pat_is_binding(&def_map.borrow(), &p) {
match p.node {
- hir::PatIdent(hir::BindByValue(_), _, ref sub) => {
+ PatKind::Ident(hir::BindByValue(_), _, ref sub) => {
let pat_ty = tcx.node_id_to_type(p.id);
//FIXME: (@jroesch) this code should be floated up as well
let infcx = infer::new_infer_ctxt(cx.tcx,
check_move(p, sub.as_ref().map(|p| &**p));
}
}
- hir::PatIdent(hir::BindByRef(_), _, _) => {
+ PatKind::Ident(hir::BindByRef(_), _, _) => {
}
_ => {
cx.tcx.sess.span_bug(
}
match pat.node {
- hir::PatIdent(_, _, Some(_)) => {
+ PatKind::Ident(_, _, Some(_)) => {
let bindings_were_allowed = self.bindings_allowed;
self.bindings_allowed = false;
intravisit::walk_pat(self, pat);
use graphviz::IntoCow;
use syntax::ast;
-use rustc_front::hir::Expr;
+use rustc_front::hir::{Expr, PatKind};
use rustc_front::hir;
use rustc_front::intravisit::FnKind;
use syntax::codemap::Span;
pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat> {
let pat = match expr.node {
hir::ExprTup(ref exprs) =>
- hir::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &expr, span)).collect()),
+ PatKind::Tup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &expr, span)).collect()),
hir::ExprCall(ref callee, ref args) => {
let def = *tcx.def_map.borrow().get(&callee.id).unwrap();
Def::Variant(_, variant_did) => def_to_path(tcx, variant_did),
Def::Fn(..) => return P(hir::Pat {
id: expr.id,
- node: hir::PatLit(P(expr.clone())),
+ node: PatKind::Lit(P(expr.clone())),
span: span,
}),
_ => unreachable!()
};
let pats = args.iter().map(|expr| const_expr_to_pat(tcx, &expr, span)).collect();
- hir::PatEnum(path, Some(pats))
+ PatKind::TupleStruct(path, Some(pats))
}
hir::ExprStruct(ref path, ref fields, None) => {
is_shorthand: false,
},
}).collect();
- hir::PatStruct(path.clone(), field_pats, false)
+ PatKind::Struct(path.clone(), field_pats, false)
}
hir::ExprVec(ref exprs) => {
let pats = exprs.iter().map(|expr| const_expr_to_pat(tcx, &expr, span)).collect();
- hir::PatVec(pats, None, hir::HirVec::new())
+ PatKind::Vec(pats, None, hir::HirVec::new())
}
hir::ExprPath(_, ref path) => {
let opt_def = tcx.def_map.borrow().get(&expr.id).map(|d| d.full_def());
match opt_def {
- Some(Def::Struct(..)) =>
- hir::PatStruct(path.clone(), hir::HirVec::new(), false),
- Some(Def::Variant(..)) =>
- hir::PatEnum(path.clone(), None),
+ Some(Def::Struct(..)) | Some(Def::Variant(..)) =>
+ PatKind::Path(path.clone()),
Some(Def::Const(def_id)) |
Some(Def::AssociatedConst(def_id)) => {
let expr = lookup_const_by_id(tcx, def_id, Some(expr.id), None).unwrap();
}
}
- _ => hir::PatLit(P(expr.clone()))
+ _ => PatKind::Lit(P(expr.clone()))
};
P(hir::Pat { id: expr.id, node: pat, span: span })
}
use dep_graph::DepNode;
use front::map as ast_map;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::intravisit::{self, Visitor};
use middle::{pat_util, privacy, ty};
_ => self.tcx.sess.span_bug(lhs.span, "non-ADT in struct pattern")
};
for pat in pats {
- if let hir::PatWild = pat.node.pat.node {
+ if let PatKind::Wild = pat.node.pat.node {
continue;
}
self.insert_def_id(variant.field_named(pat.node.name).did);
fn visit_pat(&mut self, pat: &hir::Pat) {
let def_map = &self.tcx.def_map;
match pat.node {
- hir::PatStruct(_, ref fields, _) => {
+ PatKind::Struct(_, ref fields, _) => {
self.handle_field_pattern_match(pat, fields);
}
_ if pat_util::pat_is_const(&def_map.borrow(), pat) => {
use middle::ty;
use middle::ty::adjustment;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use syntax::ast;
use syntax::ptr::P;
let def_map = &self.tcx().def_map;
if pat_util::pat_is_binding(&def_map.borrow(), pat) {
match pat.node {
- hir::PatIdent(hir::BindByRef(_), _, _) =>
+ PatKind::Ident(hir::BindByRef(_), _, _) =>
mode.lub(BorrowingMatch),
- hir::PatIdent(hir::BindByValue(_), _, _) => {
+ PatKind::Ident(hir::BindByValue(_), _, _) => {
match copy_or_move(self.typer, &cmt_pat, PatBindingMove) {
Copy => mode.lub(CopyingMatch),
Move(_) => mode.lub(MovingMatch),
// It is also a borrow or copy/move of the value being matched.
match pat.node {
- hir::PatIdent(hir::BindByRef(m), _, _) => {
+ PatKind::Ident(hir::BindByRef(m), _, _) => {
if let ty::TyRef(&r, _) = pat_ty.sty {
let bk = ty::BorrowKind::from_mutbl(m);
delegate.borrow(pat.id, pat.span, cmt_pat,
r, bk, RefBinding);
}
}
- hir::PatIdent(hir::BindByValue(_), _, _) => {
+ PatKind::Ident(hir::BindByValue(_), _, _) => {
let mode = copy_or_move(typer, &cmt_pat, PatBindingMove);
debug!("walk_pat binding consuming pat");
delegate.consume_pat(pat, cmt_pat, mode);
}
} else {
match pat.node {
- hir::PatVec(_, Some(ref slice_pat), _) => {
+ PatKind::Vec(_, Some(ref slice_pat), _) => {
// The `slice_pat` here creates a slice into
// the original vector. This is effectively a
// borrow of the elements of the vector being
let tcx = typer.tcx;
match pat.node {
- hir::PatEnum(_, _) | hir::PatQPath(..) |
- hir::PatIdent(_, _, None) | hir::PatStruct(..) => {
+ PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::QPath(..) |
+ PatKind::Ident(_, _, None) | PatKind::Struct(..) => {
match def_map.get(&pat.id).map(|d| d.full_def()) {
None => {
// no definition found: pat is not a
}
}
- hir::PatIdent(_, _, Some(_)) => {
+ PatKind::Ident(_, _, Some(_)) => {
// Do nothing; this is a binding (not an enum
// variant or struct), and the cat_pattern call
// will visit the substructure recursively.
}
- hir::PatWild | hir::PatTup(..) | hir::PatBox(..) |
- hir::PatRegion(..) | hir::PatLit(..) | hir::PatRange(..) |
- hir::PatVec(..) => {
+ PatKind::Wild | PatKind::Tup(..) | PatKind::Box(..) |
+ PatKind::Ref(..) | PatKind::Lit(..) | PatKind::Range(..) |
+ PatKind::Vec(..) => {
// Similarly, each of these cases does not
// correspond to an enum variant or struct, so we
// do not do any `matched_pat` calls for these
use middle::ty::adjustment;
use middle::ty::{self, Ty};
-use rustc_front::hir::{MutImmutable, MutMutable};
+use rustc_front::hir::{MutImmutable, MutMutable, PatKind};
use rustc_front::hir;
use syntax::ast;
use syntax::codemap::Span;
fn from_local(tcx: &ty::ctxt, id: ast::NodeId) -> MutabilityCategory {
let ret = match tcx.map.get(id) {
ast_map::NodeLocal(p) => match p.node {
- hir::PatIdent(bind_mode, _, _) => {
+ PatKind::Ident(bind_mode, _, _) => {
if bind_mode == hir::BindByValue(hir::MutMutable) {
McDeclared
} else {
// *being borrowed* is. But ideally we would put in a more
// fundamental fix to this conflated use of the node id.
let ret_ty = match pat.node {
- hir::PatIdent(hir::BindByRef(_), _, _) => {
+ PatKind::Ident(hir::BindByRef(_), _, _) => {
// a bind-by-ref means that the base_ty will be the type of the ident itself,
// but what we want here is the type of the underlying value being borrowed.
// So peel off one-level, turning the &T into T.
None
};
- // Note: This goes up here (rather than within the PatEnum arm
+ // Note: This goes up here (rather than within the PatKind::TupleStruct arm
// alone) because struct patterns can refer to struct types or
// to struct variants within enums.
let cmt = match opt_def {
};
match pat.node {
- hir::PatWild => {
+ PatKind::Wild => {
// _
}
- hir::PatEnum(_, None) => {
+ PatKind::TupleStruct(_, None) => {
// variant(..)
}
- hir::PatEnum(_, Some(ref subpats)) => {
+ PatKind::TupleStruct(_, Some(ref subpats)) => {
match opt_def {
Some(Def::Variant(..)) => {
// variant(x, y, z)
}
}
- hir::PatQPath(..) => {
- // Lone constant: ignore
+ PatKind::Path(..) | PatKind::QPath(..) | PatKind::Ident(_, _, None) => {
+ // Lone constant, or unit variant or identifier: ignore
}
- hir::PatIdent(_, _, Some(ref subpat)) => {
+ PatKind::Ident(_, _, Some(ref subpat)) => {
try!(self.cat_pattern_(cmt, &subpat, op));
}
- hir::PatIdent(_, _, None) => {
- // nullary variant or identifier: ignore
- }
-
- hir::PatStruct(_, ref field_pats, _) => {
+ PatKind::Struct(_, ref field_pats, _) => {
// {f1: p1, ..., fN: pN}
for fp in field_pats {
let field_ty = try!(self.pat_ty(&fp.node.pat)); // see (*2)
}
}
- hir::PatTup(ref subpats) => {
+ PatKind::Tup(ref subpats) => {
// (p1, ..., pN)
for (i, subpat) in subpats.iter().enumerate() {
let subpat_ty = try!(self.pat_ty(&subpat)); // see (*2)
}
}
- hir::PatBox(ref subpat) | hir::PatRegion(ref subpat, _) => {
+ PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => {
// box p1, &p1, &mut p1. we can ignore the mutability of
- // PatRegion since that information is already contained
+ // PatKind::Ref since that information is already contained
// in the type.
let subcmt = try!(self.cat_deref(pat, cmt, 0, None));
try!(self.cat_pattern_(subcmt, &subpat, op));
}
- hir::PatVec(ref before, ref slice, ref after) => {
+ PatKind::Vec(ref before, ref slice, ref after) => {
let context = InteriorOffsetKind::Pattern;
let vec_cmt = try!(self.deref_vec(pat, cmt, context));
let elt_cmt = try!(self.cat_index(pat, vec_cmt, context));
}
}
- hir::PatLit(_) | hir::PatRange(_, _) => {
+ PatKind::Lit(_) | PatKind::Range(_, _) => {
/*always ok*/
}
}
use util::nodemap::FnvHashMap;
use syntax::ast;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
use rustc_front::util::walk_pat;
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatLit(_) | hir::PatRange(_, _) | hir::PatQPath(..) => true,
- hir::PatEnum(_, _) |
- hir::PatIdent(_, _, None) |
- hir::PatStruct(..) => {
+ PatKind::Lit(_) | PatKind::Range(_, _) | PatKind::QPath(..) => true,
+ PatKind::TupleStruct(..) |
+ PatKind::Path(..) |
+ PatKind::Ident(_, _, None) |
+ PatKind::Struct(..) => {
match dm.get(&pat.id).map(|d| d.full_def()) {
Some(Def::Variant(..)) => true,
_ => false
}
}
- hir::PatVec(_, _, _) => true,
+ PatKind::Vec(_, _, _) => true,
_ => false
}
}
pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatEnum(_, _) |
- hir::PatIdent(_, _, None) |
- hir::PatStruct(..) => {
+ PatKind::TupleStruct(..) |
+ PatKind::Path(..) |
+ PatKind::Ident(_, _, None) |
+ PatKind::Struct(..) => {
match dm.get(&pat.id).map(|d| d.full_def()) {
- Some(Def::Variant(..)) | Some(Def::Struct(..)) => true,
+ Some(Def::Variant(..)) | Some(Def::Struct(..)) | Some(Def::TyAlias(..)) => true,
_ => false
}
}
pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
+ PatKind::Ident(_, _, None) | PatKind::Path(..) | PatKind::QPath(..) => {
match dm.get(&pat.id).map(|d| d.full_def()) {
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true,
_ => false
// returned instead of a panic.
pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
+ PatKind::Ident(_, _, None) | PatKind::Path(..) | PatKind::QPath(..) => {
match dm.get(&pat.id)
.and_then(|d| if d.depth == 0 { Some(d.base_def) }
else { None } ) {
pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatIdent(..) => {
+ PatKind::Ident(..) => {
!pat_is_variant_or_struct(dm, pat) &&
!pat_is_const(dm, pat)
}
pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatIdent(..) => pat_is_binding(dm, pat),
- hir::PatWild => true,
+ PatKind::Ident(..) => pat_is_binding(dm, pat),
+ PatKind::Wild => true,
_ => false
}
}
{
walk_pat(pat, |p| {
match p.node {
- hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
+ PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name));
}
_ => {}
{
walk_pat(pat, |p| {
match p.node {
- hir::PatIdent(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
+ PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node));
}
_ => {}
pub fn simple_name<'a>(pat: &'a hir::Pat) -> Option<ast::Name> {
match pat.node {
- hir::PatIdent(hir::BindByValue(_), ref path1, None) => {
+ PatKind::Ident(hir::BindByValue(_), ref path1, None) => {
Some(path1.node.name)
}
_ => {
let mut variants = vec![];
walk_pat(pat, |p| {
match p.node {
- hir::PatEnum(_, _) |
- hir::PatIdent(_, _, None) |
- hir::PatStruct(..) => {
+ PatKind::TupleStruct(..) |
+ PatKind::Path(..) |
+ PatKind::Ident(_, _, None) |
+ PatKind::Struct(..) => {
match dm.get(&p.id) {
Some(&PathResolution { base_def: Def::Variant(_, id), .. }) => {
variants.push(id);
use rustc_front::hir;
use rustc_front::intravisit::{self, Visitor, FnKind};
-use rustc_front::hir::{Block, Item, FnDecl, Arm, Pat, Stmt, Expr, Local};
+use rustc_front::hir::{Block, Item, FnDecl, Arm, Pat, PatKind, Stmt, Expr, Local};
use rustc_front::util::stmt_id;
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
// If this is a binding (or maybe a binding, I'm too lazy to check
// the def map) then record the lifetime of that binding.
match pat.node {
- hir::PatIdent(..) => {
+ PatKind::Ident(..) => {
record_var_lifetime(visitor, pat.id, pat.span);
}
_ => { }
/// | box P&
fn is_binding_pat(pat: &hir::Pat) -> bool {
match pat.node {
- hir::PatIdent(hir::BindByRef(_), _, _) => true,
+ PatKind::Ident(hir::BindByRef(_), _, _) => true,
- hir::PatStruct(_, ref field_pats, _) => {
+ PatKind::Struct(_, ref field_pats, _) => {
field_pats.iter().any(|fp| is_binding_pat(&fp.node.pat))
}
- hir::PatVec(ref pats1, ref pats2, ref pats3) => {
+ PatKind::Vec(ref pats1, ref pats2, ref pats3) => {
pats1.iter().any(|p| is_binding_pat(&p)) ||
pats2.iter().any(|p| is_binding_pat(&p)) ||
pats3.iter().any(|p| is_binding_pat(&p))
}
- hir::PatEnum(_, Some(ref subpats)) |
- hir::PatTup(ref subpats) => {
+ PatKind::TupleStruct(_, Some(ref subpats)) |
+ PatKind::Tup(ref subpats) => {
subpats.iter().any(|p| is_binding_pat(&p))
}
- hir::PatBox(ref subpat) => {
+ PatKind::Box(ref subpat) => {
is_binding_pat(&subpat)
}
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
use rustc_front::hir;
-use rustc_front::hir::{Item, Generics, StructField, Variant};
+use rustc_front::hir::{Item, Generics, StructField, Variant, PatKind};
use rustc_front::intravisit::{self, Visitor};
use std::mem::replace;
};
match pat.node {
// Foo(a, b, c)
- // A Variant(..) pattern `hir::PatEnum(_, None)` doesn't have to be recursed into.
- hir::PatEnum(_, Some(ref pat_fields)) => {
+ // A Variant(..) pattern `PatKind::TupleStruct(_, None)` doesn't have to be recursed into.
+ PatKind::TupleStruct(_, Some(ref pat_fields)) => {
for (field, struct_field) in pat_fields.iter().zip(&v.fields) {
maybe_do_stability_check(tcx, struct_field.did, field.span, cb)
}
}
// Foo { a, b, c }
- hir::PatStruct(_, ref pat_fields, _) => {
+ PatKind::Struct(_, ref pat_fields, _) => {
for field in pat_fields {
let did = v.field_named(field.node.name).did;
maybe_do_stability_check(tcx, did, field.span, cb);
use syntax::parse::token::InternedString;
use rustc_front::hir;
-use rustc_front::hir::{ItemImpl, ItemTrait};
+use rustc_front::hir::{ItemImpl, ItemTrait, PatKind};
use rustc_front::intravisit::Visitor;
pub use self::sty::{Binder, DebruijnIndex};
match self.map.find(id) {
Some(ast_map::NodeLocal(pat)) => {
match pat.node {
- hir::PatIdent(_, ref path1, _) => path1.node.name.as_str(),
+ PatKind::Ident(_, ref path1, _) => path1.node.name.as_str(),
_ => {
self.sess.bug(&format!("Variable id {} maps to {:?}, not local", id, pat));
},
use std::rc::Rc;
use syntax::ast;
use syntax::codemap::Span;
-use rustc_front::hir;
+use rustc_front::hir::{self, PatKind};
struct GatherMoveInfo<'tcx> {
id: ast::NodeId,
move_pat: &hir::Pat,
cmt: mc::cmt<'tcx>) {
let pat_span_path_opt = match move_pat.node {
- hir::PatIdent(_, ref path1, _) => {
+ PatKind::Ident(_, ref path1, _) => {
Some(MoveSpanAndPath{span: move_pat.span,
name: path1.node.name})
},
Pat {
id: folder.new_id(id),
node: match node {
- PatWild => PatWild,
- PatIdent(binding_mode, pth1, sub) => {
- PatIdent(binding_mode,
+ PatKind::Wild => PatKind::Wild,
+ PatKind::Ident(binding_mode, pth1, sub) => {
+ PatKind::Ident(binding_mode,
Spanned {
span: folder.new_span(pth1.span),
node: folder.fold_ident(pth1.node),
},
sub.map(|x| folder.fold_pat(x)))
}
- PatLit(e) => PatLit(folder.fold_expr(e)),
- PatEnum(pth, pats) => {
- PatEnum(folder.fold_path(pth),
+ PatKind::Lit(e) => PatKind::Lit(folder.fold_expr(e)),
+ PatKind::TupleStruct(pth, pats) => {
+ PatKind::TupleStruct(folder.fold_path(pth),
pats.map(|pats| pats.move_map(|x| folder.fold_pat(x))))
}
- PatQPath(qself, pth) => {
+ PatKind::Path(pth) => {
+ PatKind::Path(folder.fold_path(pth))
+ }
+ PatKind::QPath(qself, pth) => {
let qself = QSelf { ty: folder.fold_ty(qself.ty), ..qself };
- PatQPath(qself, folder.fold_path(pth))
+ PatKind::QPath(qself, folder.fold_path(pth))
}
- PatStruct(pth, fields, etc) => {
+ PatKind::Struct(pth, fields, etc) => {
let pth = folder.fold_path(pth);
let fs = fields.move_map(|f| {
Spanned {
},
}
});
- PatStruct(pth, fs, etc)
+ PatKind::Struct(pth, fs, etc)
}
- PatTup(elts) => PatTup(elts.move_map(|x| folder.fold_pat(x))),
- PatBox(inner) => PatBox(folder.fold_pat(inner)),
- PatRegion(inner, mutbl) => PatRegion(folder.fold_pat(inner), mutbl),
- PatRange(e1, e2) => {
- PatRange(folder.fold_expr(e1), folder.fold_expr(e2))
+ PatKind::Tup(elts) => PatKind::Tup(elts.move_map(|x| folder.fold_pat(x))),
+ PatKind::Box(inner) => PatKind::Box(folder.fold_pat(inner)),
+ PatKind::Ref(inner, mutbl) => PatKind::Ref(folder.fold_pat(inner), mutbl),
+ PatKind::Range(e1, e2) => {
+ PatKind::Range(folder.fold_expr(e1), folder.fold_expr(e2))
}
- PatVec(before, slice, after) => {
- PatVec(before.move_map(|x| folder.fold_pat(x)),
+ PatKind::Vec(before, slice, after) => {
+ PatKind::Vec(before.move_map(|x| folder.fold_pat(x)),
slice.map(|x| folder.fold_pat(x)),
after.move_map(|x| folder.fold_pat(x)))
}
pub use self::ForeignItem_::*;
pub use self::Item_::*;
pub use self::Mutability::*;
-pub use self::Pat_::*;
pub use self::PathListItem_::*;
pub use self::PrimTy::*;
pub use self::Stmt_::*;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub struct Pat {
pub id: NodeId,
- pub node: Pat_,
+ pub node: PatKind,
pub span: Span,
}
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
-pub enum Pat_ {
+pub enum PatKind {
/// Represents a wildcard pattern (`_`)
- PatWild,
+ Wild,
- /// A PatIdent may either be a new bound variable,
- /// or a nullary enum (in which case the third field
- /// is None).
+ /// A `PatKind::Ident` may either be a new bound variable,
+ /// or a unit struct/variant pattern, or a const pattern (in the last two cases
+ /// the third field must be `None`).
///
- /// In the nullary enum case, the parser can't determine
+ /// In the unit or const pattern case, the parser can't determine
/// which it is. The resolver determines this, and
- /// records this pattern's NodeId in an auxiliary
- /// set (of "PatIdents that refer to nullary enums")
- PatIdent(BindingMode, Spanned<Ident>, Option<P<Pat>>),
+ /// records this pattern's `NodeId` in an auxiliary
+ /// set (of "PatIdents that refer to unit patterns or constants").
+ Ident(BindingMode, Spanned<Ident>, Option<P<Pat>>),
+ /// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`.
+ /// The `bool` is `true` in the presence of a `..`.
+ Struct(Path, HirVec<Spanned<FieldPat>>, 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<HirVec<P<Pat>>>),
+ TupleStruct(Path, Option<HirVec<P<Pat>>>),
+
+ /// 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 `<T>::CONST` or
/// `<T as Trait>::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<Spanned<FieldPat>>, bool),
/// A tuple pattern `(a, b)`
- PatTup(HirVec<P<Pat>>),
+ Tup(HirVec<P<Pat>>),
/// A `box` pattern
- PatBox(P<Pat>),
+ Box(P<Pat>),
/// A reference pattern, e.g. `&mut (a, b)`
- PatRegion(P<Pat>, Mutability),
+ Ref(P<Pat>, Mutability),
/// A literal
- PatLit(P<Expr>),
+ Lit(P<Expr>),
/// A range pattern, e.g. `1...2`
- PatRange(P<Expr>, P<Expr>),
+ Range(P<Expr>, P<Expr>),
/// `[a, b, ..i, y, z]` is represented as:
- /// `PatVec(box [a, b], Some(i), box [y, z])`
- PatVec(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
+ /// `PatKind::Vec(box [a, b], Some(i), box [y, z])`
+ Vec(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
}),
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,
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);
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);
}
})
.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())
}
path: hir::Path,
subpats: hir::HirVec<P<hir::Pat>>)
-> P<hir::Pat> {
- 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)
}
ident: hir::Ident,
bm: hir::BindingMode)
-> P<hir::Pat> {
- let pat_ident = hir::PatIdent(bm,
+ let pat_ident = hir::PatKind::Ident(bm,
Spanned {
span: span,
node: ident,
}
fn pat_wild(lctx: &LoweringContext, span: Span) -> P<hir::Pat> {
- pat(lctx, span, hir::PatWild)
+ pat(lctx, span, hir::PatKind::Wild)
}
-fn pat(lctx: &LoweringContext, span: Span, pat: hir::Pat_) -> P<hir::Pat> {
+fn pat(lctx: &LoweringContext, span: Span, pat: hir::PatKind) -> P<hir::Pat> {
P(hir::Pat {
id: lctx.next_id(),
node: pat,
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};
// 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"));
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("{"));
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 {
}
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, ".."));
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,
},
};
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.
}
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
}
}
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)]
}
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));
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);
}
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};
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;
}
});
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 \
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;
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 {
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;
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);
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();
}
}
- 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) =>
}
}
- hir::PatTup(ref subpatterns) => {
+ PatKind::Tup(ref subpatterns) => {
let subpatterns =
subpatterns.iter()
.enumerate()
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 {
}
}
- 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())
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,
self.variant_or_leaf(pat, subpatterns)
}
- hir::PatQPath(..) => {
+ PatKind::QPath(..) => {
self.cx.tcx.sess.span_bug(pat.span, "unexpanded macro or bad constant etc");
}
};
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;
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);
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;
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);
// 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,
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;
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
}
}
- 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,
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 {
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),
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);
intravisit::walk_path(self, path);
}
- PatLit(_) | PatRange(..) => {
+ PatKind::Lit(_) | PatKind::Range(..) => {
intravisit::walk_pat(self, pattern);
}
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;
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,
_ => ()
}
}
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
},
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());
};
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 {
_ => 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
}
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
fn pick_column_to_specialize(def_map: &RefCell<DefMap>, m: &[Match]) -> Option<usize> {
fn pat_score(def_map: &RefCell<DefMap>, 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
}
let column_contains_any_nonwild_patterns = |&col: &usize| -> bool {
m.iter().any(|row| match row.pats[col].node {
- hir::PatWild => false,
+ PatKind::Wild => false,
_ => true
})
};
// 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);
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
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)) => {
}
}
}
- 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);
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() {
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)
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)
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 {
cleanup_scope)
});
}
- hir::PatQPath(..) | hir::PatWild | hir::PatLit(_) |
- hir::PatRange(_, _) => ()
+ PatKind::Path(..) | PatKind::QPath(..) | PatKind::Wild | PatKind::Lit(_) |
+ PatKind::Range(_, _) => ()
}
return bcx;
}
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.
// 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
}
}
- 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 {
}
}
- 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 {
}
}
- 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 {
}
}
- 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 {
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};
}
Some(hir_map::NodeLocal(pat)) => {
match pat.node {
- hir::PatIdent(_, ref path1, _) => {
+ PatKind::Ident(_, ref path1, _) => {
path1.node.name
}
_ => {
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;
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(<);
// 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);
// 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);
// 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);
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) => {
}
}
}
- 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 {
}
}
}
- 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();
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);
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
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 {
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;
// 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);
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;
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,
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;
{
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");
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)))
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::<Vec<String>>().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));
/// An associated const named using the qualified path `<T>::CONST` or
/// `<T as Trait>::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)`