Rename hir::Pat_ and its variants
This commit is contained in:
parent
86e6e3235e
commit
9b40e1e5b3
@ -262,7 +262,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
@ -615,7 +615,7 @@ impl<'ast> Map<'ast> {
|
||||
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)
|
||||
|
@ -16,7 +16,7 @@ use middle::ty;
|
||||
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>,
|
||||
@ -99,35 +99,35 @@ impl<'a, 'tcx> CFGBuilder<'a, '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::Enum(_, None) |
|
||||
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::Enum(_, 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);
|
||||
|
@ -32,7 +32,7 @@ use std::fmt;
|
||||
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;
|
||||
@ -47,7 +47,7 @@ use util::nodemap::FnvHashMap;
|
||||
|
||||
pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
|
||||
id: DUMMY_NODE_ID,
|
||||
node: hir::PatWild,
|
||||
node: PatKind::Wild,
|
||||
span: DUMMY_SP
|
||||
};
|
||||
|
||||
@ -242,7 +242,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
|
||||
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());
|
||||
@ -274,7 +274,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
|
||||
// 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,
|
||||
@ -360,7 +360,7 @@ fn check_arms(cx: &MatchCheckCtxt,
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -377,7 +377,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
|
||||
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::Enum(_, Some(ref pats)) => match &pats[..] {
|
||||
[ref pat] => &**pat,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
@ -466,7 +466,7 @@ impl<'map> ast_util::IdVisitingOperation for RenamingRecorder<'map> {
|
||||
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::Enum(..) | PatKind::QPath(..) => {
|
||||
let def = self.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def());
|
||||
match def {
|
||||
Some(Def::AssociatedConst(did)) |
|
||||
@ -530,14 +530,14 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
|
||||
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)
|
||||
.filter(|&(_, ref pat)| pat.node != PatKind::Wild)
|
||||
.map(|(field, pat)| Spanned {
|
||||
span: DUMMY_SP,
|
||||
node: hir::FieldPat {
|
||||
@ -547,9 +547,9 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
|
||||
}
|
||||
}).collect();
|
||||
let has_more_fields = field_pats.len() < pats_len;
|
||||
hir::PatStruct(def_to_path(cx.tcx, v.did), field_pats, has_more_fields)
|
||||
PatKind::Struct(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()))
|
||||
PatKind::Enum(def_to_path(cx.tcx, v.did), Some(pats.collect()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,35 +558,35 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
|
||||
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,
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -682,7 +682,7 @@ fn is_useful(cx: &MatchCheckCtxt,
|
||||
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,
|
||||
@ -690,7 +690,7 @@ fn is_useful(cx: &MatchCheckCtxt,
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
@ -769,7 +769,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
left_ty: Ty, max_slice_length: usize) -> Vec<Constructor> {
|
||||
let pat = raw_pat(p);
|
||||
match pat.node {
|
||||
hir::PatIdent(..) =>
|
||||
PatKind::Ident(..) =>
|
||||
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 \
|
||||
@ -778,7 +778,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
Some(Def::Variant(_, id)) => vec!(Variant(id)),
|
||||
_ => vec!()
|
||||
},
|
||||
hir::PatEnum(..) =>
|
||||
PatKind::Enum(..) =>
|
||||
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 \
|
||||
@ -786,10 +786,10 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
Some(Def::Variant(_, id)) => vec!(Variant(id)),
|
||||
_ => vec!(Single)
|
||||
},
|
||||
hir::PatQPath(..) =>
|
||||
PatKind::QPath(..) =>
|
||||
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
|
||||
been rewritten"),
|
||||
hir::PatStruct(..) =>
|
||||
PatKind::Struct(..) =>
|
||||
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 \
|
||||
@ -797,11 +797,11 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
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() {
|
||||
@ -812,9 +812,9 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
@ -877,10 +877,10 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
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(_, _, _) => {
|
||||
PatKind::Ident(_, _, _) => {
|
||||
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(..)) =>
|
||||
@ -895,7 +895,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
}
|
||||
}
|
||||
|
||||
hir::PatEnum(_, ref args) => {
|
||||
PatKind::Enum(_, ref args) => {
|
||||
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
|
||||
match def {
|
||||
Def::Const(..) | Def::AssociatedConst(..) =>
|
||||
@ -912,12 +912,12 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -934,13 +934,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
}
|
||||
}
|
||||
|
||||
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![]),
|
||||
@ -952,7 +952,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -965,7 +965,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
|
||||
}
|
||||
}
|
||||
|
||||
hir::PatVec(ref before, ref slice, ref after) => {
|
||||
PatKind::Vec(ref before, ref slice, ref after) => {
|
||||
match *constructor {
|
||||
// Fixed-length vectors.
|
||||
Single => {
|
||||
@ -1104,7 +1104,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
|
||||
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,
|
||||
@ -1114,7 +1114,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
|
||||
check_move(p, sub.as_ref().map(|p| &**p));
|
||||
}
|
||||
}
|
||||
hir::PatIdent(hir::BindByRef(_), _, _) => {
|
||||
PatKind::Ident(hir::BindByRef(_), _, _) => {
|
||||
}
|
||||
_ => {
|
||||
cx.tcx.sess.span_bug(
|
||||
@ -1202,7 +1202,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -30,7 +30,7 @@ use session::Session;
|
||||
|
||||
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;
|
||||
@ -325,7 +325,7 @@ impl ConstVal {
|
||||
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();
|
||||
@ -337,13 +337,13 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
|
||||
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::Enum(path, Some(pats))
|
||||
}
|
||||
|
||||
hir::ExprStruct(ref path, ref fields, None) => {
|
||||
@ -355,21 +355,21 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
|
||||
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),
|
||||
PatKind::Struct(path.clone(), hir::HirVec::new(), false),
|
||||
Some(Def::Variant(..)) =>
|
||||
hir::PatEnum(path.clone(), None),
|
||||
PatKind::Enum(path.clone(), None),
|
||||
Some(Def::Const(def_id)) |
|
||||
Some(Def::AssociatedConst(def_id)) => {
|
||||
let expr = lookup_const_by_id(tcx, def_id, Some(expr.id), None).unwrap();
|
||||
@ -379,7 +379,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
|
||||
}
|
||||
}
|
||||
|
||||
_ => hir::PatLit(P(expr.clone()))
|
||||
_ => PatKind::Lit(P(expr.clone()))
|
||||
};
|
||||
P(hir::Pat { id: expr.id, node: pat, span: span })
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
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};
|
||||
@ -143,7 +143,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
||||
_ => 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);
|
||||
@ -268,7 +268,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
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) => {
|
||||
|
@ -27,7 +27,7 @@ use middle::mem_categorization as mc;
|
||||
use middle::ty;
|
||||
use middle::ty::adjustment;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{self, PatKind};
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ptr::P;
|
||||
@ -946,9 +946,9 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
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),
|
||||
@ -1002,14 +1002,14 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
|
||||
// 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);
|
||||
@ -1022,7 +1022,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
}
|
||||
} 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
|
||||
@ -1070,8 +1070,8 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
let tcx = typer.tcx;
|
||||
|
||||
match pat.node {
|
||||
hir::PatEnum(_, _) | hir::PatQPath(..) |
|
||||
hir::PatIdent(_, _, None) | hir::PatStruct(..) => {
|
||||
PatKind::Enum(_, _) | 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
|
||||
@ -1134,15 +1134,15 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -79,7 +79,7 @@ use middle::def::Def;
|
||||
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;
|
||||
@ -305,7 +305,7 @@ impl MutabilityCategory {
|
||||
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 {
|
||||
@ -396,7 +396,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
// *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.
|
||||
@ -1209,7 +1209,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
None
|
||||
};
|
||||
|
||||
// Note: This goes up here (rather than within the PatEnum arm
|
||||
// Note: This goes up here (rather than within the PatKind::Enum arm
|
||||
// alone) because struct patterns can refer to struct types or
|
||||
// to struct variants within enums.
|
||||
let cmt = match opt_def {
|
||||
@ -1222,14 +1222,14 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
};
|
||||
|
||||
match pat.node {
|
||||
hir::PatWild => {
|
||||
PatKind::Wild => {
|
||||
// _
|
||||
}
|
||||
|
||||
hir::PatEnum(_, None) => {
|
||||
PatKind::Enum(_, None) => {
|
||||
// variant(..)
|
||||
}
|
||||
hir::PatEnum(_, Some(ref subpats)) => {
|
||||
PatKind::Enum(_, Some(ref subpats)) => {
|
||||
match opt_def {
|
||||
Some(Def::Variant(..)) => {
|
||||
// variant(x, y, z)
|
||||
@ -1267,19 +1267,19 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
hir::PatQPath(..) => {
|
||||
PatKind::QPath(..) => {
|
||||
// Lone constant: ignore
|
||||
}
|
||||
|
||||
hir::PatIdent(_, _, Some(ref subpat)) => {
|
||||
PatKind::Ident(_, _, Some(ref subpat)) => {
|
||||
try!(self.cat_pattern_(cmt, &subpat, op));
|
||||
}
|
||||
|
||||
hir::PatIdent(_, _, None) => {
|
||||
PatKind::Ident(_, _, 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)
|
||||
@ -1288,7 +1288,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -1300,15 +1300,15 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
@ -1325,7 +1325,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
hir::PatLit(_) | hir::PatRange(_, _) => {
|
||||
PatKind::Lit(_) | PatKind::Range(_, _) => {
|
||||
/*always ok*/
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use middle::ty;
|
||||
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};
|
||||
|
||||
@ -34,25 +34,25 @@ pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
|
||||
|
||||
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::Enum(_, _) |
|
||||
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::Enum(_, _) |
|
||||
PatKind::Ident(_, _, None) |
|
||||
PatKind::Struct(..) => {
|
||||
match dm.get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(Def::Variant(..)) | Some(Def::Struct(..)) => true,
|
||||
_ => false
|
||||
@ -64,7 +64,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
|
||||
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::Enum(..) | PatKind::QPath(..) => {
|
||||
match dm.get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true,
|
||||
_ => false
|
||||
@ -78,7 +78,7 @@ pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
// 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::Enum(..) | PatKind::QPath(..) => {
|
||||
match dm.get(&pat.id)
|
||||
.and_then(|d| if d.depth == 0 { Some(d.base_def) }
|
||||
else { None } ) {
|
||||
@ -92,7 +92,7 @@ pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
|
||||
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)
|
||||
}
|
||||
@ -102,8 +102,8 @@ pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
|
||||
{
|
||||
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));
|
||||
}
|
||||
_ => {}
|
||||
@ -128,7 +128,7 @@ pub fn pat_bindings_ident<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) wh
|
||||
{
|
||||
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));
|
||||
}
|
||||
_ => {}
|
||||
@ -199,7 +199,7 @@ pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
|
||||
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)
|
||||
}
|
||||
_ => {
|
||||
@ -224,9 +224,9 @@ pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
|
||||
let mut variants = vec![];
|
||||
walk_pat(pat, |p| {
|
||||
match p.node {
|
||||
hir::PatEnum(_, _) |
|
||||
hir::PatIdent(_, _, None) |
|
||||
hir::PatStruct(..) => {
|
||||
PatKind::Enum(_, _) |
|
||||
PatKind::Ident(_, _, None) |
|
||||
PatKind::Struct(..) => {
|
||||
match dm.get(&p.id) {
|
||||
Some(&PathResolution { base_def: Def::Variant(_, id), .. }) => {
|
||||
variants.push(id);
|
||||
|
@ -32,7 +32,7 @@ use syntax::ast::{self, NodeId};
|
||||
|
||||
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,
|
||||
@ -755,7 +755,7 @@ fn resolve_pat(visitor: &mut RegionResolutionVisitor, pat: &hir::Pat) {
|
||||
// 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);
|
||||
}
|
||||
_ => { }
|
||||
@ -958,24 +958,24 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor, local: &hir::Local) {
|
||||
/// | 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::Enum(_, 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)
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ use syntax::attr::{self, Stability, Deprecation, AttrMetaMethods};
|
||||
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;
|
||||
@ -598,14 +598,14 @@ pub fn check_pat(tcx: &ty::ctxt, pat: &hir::Pat,
|
||||
};
|
||||
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::Enum(_, None)` doesn't have to be recursed into.
|
||||
PatKind::Enum(_, 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);
|
||||
|
@ -52,7 +52,7 @@ use syntax::codemap::{DUMMY_SP, Span};
|
||||
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};
|
||||
@ -1945,7 +1945,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
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));
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ use rustc::middle::ty;
|
||||
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,
|
||||
@ -98,7 +98,7 @@ pub fn gather_move_from_pat<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
|
||||
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})
|
||||
},
|
||||
|
@ -962,25 +962,25 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
|
||||
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::Enum(pth, pats) => {
|
||||
PatKind::Enum(folder.fold_path(pth),
|
||||
pats.map(|pats| pats.move_map(|x| folder.fold_pat(x))))
|
||||
}
|
||||
PatQPath(qself, 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 {
|
||||
@ -992,16 +992,16 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
|
||||
},
|
||||
}
|
||||
});
|
||||
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)))
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ pub use self::FunctionRetTy::*;
|
||||
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_::*;
|
||||
@ -475,7 +474,7 @@ pub struct Block {
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
|
||||
pub struct Pat {
|
||||
pub id: NodeId,
|
||||
pub node: Pat_,
|
||||
pub node: PatKind,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
@ -506,11 +505,11 @@ pub enum BindingMode {
|
||||
}
|
||||
|
||||
#[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,
|
||||
/// A PatKind::Ident may either be a new bound variable,
|
||||
/// or a nullary enum (in which case the third field
|
||||
/// is None).
|
||||
///
|
||||
@ -518,33 +517,33 @@ pub enum Pat_ {
|
||||
/// 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>>),
|
||||
Ident(BindingMode, Spanned<Ident>, Option<P<Pat>>),
|
||||
|
||||
/// "None" means a `Variant(..)` pattern where we don't bind the fields to names.
|
||||
PatEnum(Path, Option<HirVec<P<Pat>>>),
|
||||
Enum(Path, Option<HirVec<P<Pat>>>),
|
||||
|
||||
/// 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::Enum, 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),
|
||||
Struct(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)]
|
||||
@ -1015,7 +1014,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,
|
||||
|
@ -468,41 +468,41 @@ 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::Enum(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::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);
|
||||
|
@ -913,27 +913,27 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P<hir::Pat> {
|
||||
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::Enum(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::Enum(lower_path(lctx, pth), Some(hir::HirVec::new()))
|
||||
}
|
||||
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<hir::Pat> {
|
||||
}
|
||||
})
|
||||
.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,7 @@ fn pat_enum(lctx: &LoweringContext,
|
||||
path: hir::Path,
|
||||
subpats: hir::HirVec<P<hir::Pat>>)
|
||||
-> P<hir::Pat> {
|
||||
let pt = hir::PatEnum(path, Some(subpats));
|
||||
let pt = hir::PatKind::Enum(path, Some(subpats));
|
||||
pat(lctx, span, pt)
|
||||
}
|
||||
|
||||
@ -1763,7 +1763,7 @@ fn pat_ident_binding_mode(lctx: &LoweringContext,
|
||||
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,
|
||||
@ -1773,10 +1773,10 @@ fn pat_ident_binding_mode(lctx: &LoweringContext,
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -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,7 +1748,7 @@ impl<'a> State<'a> {
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
hir::PatEnum(ref path, ref args_) => {
|
||||
PatKind::Enum(ref path, ref args_) => {
|
||||
try!(self.print_path(path, true, 0));
|
||||
match *args_ {
|
||||
None => try!(word(&mut self.s, "(..)")),
|
||||
@ -1761,10 +1761,10 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::PatQPath(ref qself, ref path) => {
|
||||
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 +1789,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 +1797,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 +1945,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 +2210,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.
|
||||
|
@ -28,27 +28,27 @@ pub fn walk_pat<F>(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::Enum(_, 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::Enum(_, _) |
|
||||
PatKind::QPath(_, _) => {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 \
|
||||
|
@ -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 {
|
||||
|
@ -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::Enum(..) | 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(..) => {
|
||||
self.variant_or_leaf(pat, vec![])
|
||||
}
|
||||
|
||||
hir::PatEnum(_, ref opt_subpatterns) => {
|
||||
PatKind::Enum(_, 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");
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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::Enum(_, 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,
|
||||
|
@ -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::Enum(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,16 @@ 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
|
||||
that a path in PatKind::Enum requires typecheck
|
||||
\
|
||||
to resolve, but qualified paths should be
|
||||
\
|
||||
PatQPath"),
|
||||
PatKind::QPath"),
|
||||
ResolveAttempt(resolution) => resolution,
|
||||
};
|
||||
if let Some(path_res) = resolution {
|
||||
@ -2550,7 +2549,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 +2604,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 +2623,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
|
||||
PatLit(_) | PatRange(..) => {
|
||||
PatKind::Lit(_) | PatKind::Range(..) => {
|
||||
intravisit::walk_pat(self, pattern);
|
||||
}
|
||||
|
||||
|
@ -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,10 @@ 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::Enum(..) | 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 +679,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,25 +786,25 @@ 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(..) => {
|
||||
PatKind::Tup(_) => true,
|
||||
PatKind::Struct(..) => {
|
||||
match tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(Def::Variant(..)) => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
hir::PatEnum(..) | hir::PatIdent(_, _, None) => {
|
||||
PatKind::Enum(..) | PatKind::Ident(_, _, None) => {
|
||||
match tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(Def::Struct(..)) => true,
|
||||
_ => false
|
||||
@ -849,7 +849,7 @@ impl FailureHandler {
|
||||
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
|
||||
}
|
||||
@ -871,7 +871,7 @@ fn pick_column_to_specialize(def_map: &RefCell<DefMap>, m: &[Match]) -> Option<u
|
||||
|
||||
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
|
||||
})
|
||||
};
|
||||
@ -1639,7 +1639,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 +1812,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 +1849,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::Enum(_, 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 +1895,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 +1935,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 +1947,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 +1966,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 +1988,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 +2013,8 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
cleanup_scope)
|
||||
});
|
||||
}
|
||||
hir::PatQPath(..) | hir::PatWild | hir::PatLit(_) |
|
||||
hir::PatRange(_, _) => ()
|
||||
PatKind::QPath(..) | PatKind::Wild | PatKind::Lit(_) |
|
||||
PatKind::Range(_, _) => ()
|
||||
}
|
||||
return bcx;
|
||||
}
|
||||
|
@ -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::Enum(_, 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::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 {
|
||||
|
@ -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
|
||||
}
|
||||
_ => {
|
||||
|
@ -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,9 +135,9 @@ 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::Enum(..) | PatKind::Ident(..)
|
||||
if pat_is_resolved_const(&tcx.def_map.borrow(), pat) => {
|
||||
if let hir::PatEnum(ref path, ref subpats) = pat.node {
|
||||
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;
|
||||
@ -154,7 +154,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 +162,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 +202,16 @@ 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) => {
|
||||
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);
|
||||
}
|
||||
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 +248,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 +262,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 +278,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 +310,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 {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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");
|
||||
|
@ -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::Enum(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::<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));
|
||||
|
Loading…
Reference in New Issue
Block a user