Auto merge of #31685 - petrochenkov:patrefact2, r=eddyb
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
This commit is contained in:
commit
0d1cd9bd6a
35 changed files with 417 additions and 424 deletions
|
|
@ -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,36 @@ 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::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);
|
||||
|
|
|
|||
|
|
@ -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::TupleStruct(_, 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::Path(..) | PatKind::QPath(..) => {
|
||||
let def = self.tcx.def_map.borrow().get(&pat.id).map(|d| d.full_def());
|
||||
match def {
|
||||
Some(Def::AssociatedConst(did)) |
|
||||
|
|
@ -530,26 +530,32 @@ 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)
|
||||
.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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -558,35 +564,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 +688,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 +696,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,39 +775,25 @@ 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(..) =>
|
||||
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::Struct(..)) => vec!(Single),
|
||||
Some(Def::Variant(_, id)) => vec!(Variant(id)),
|
||||
_ => vec!()
|
||||
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::PatEnum(..) =>
|
||||
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::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() {
|
||||
|
|
@ -812,9 +804,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,25 +869,24 @@ 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(_, _, _) => {
|
||||
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(..) =>
|
||||
|
|
@ -912,12 +903,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 +925,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 +943,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 +956,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 +1095,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 +1105,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 +1193,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::TupleStruct(path, Some(pats))
|
||||
}
|
||||
|
||||
hir::ExprStruct(ref path, ref fields, None) => {
|
||||
|
|
@ -355,21 +355,19 @@ 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),
|
||||
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();
|
||||
|
|
@ -379,7 +377,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::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
|
||||
|
|
@ -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::TupleStruct 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::TupleStruct(_, None) => {
|
||||
// variant(..)
|
||||
}
|
||||
hir::PatEnum(_, Some(ref subpats)) => {
|
||||
PatKind::TupleStruct(_, Some(ref subpats)) => {
|
||||
match opt_def {
|
||||
Some(Def::Variant(..)) => {
|
||||
// variant(x, y, z)
|
||||
|
|
@ -1267,19 +1267,15 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -1288,7 +1284,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 +1296,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 +1321,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,27 +34,29 @@ 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::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
|
||||
}
|
||||
}
|
||||
|
|
@ -64,7 +66,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::Path(..) | PatKind::QPath(..) => {
|
||||
match dm.get(&pat.id).map(|d| d.full_def()) {
|
||||
Some(Def::Const(..)) | Some(Def::AssociatedConst(..)) => true,
|
||||
_ => false
|
||||
|
|
@ -78,7 +80,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::Path(..) | PatKind::QPath(..) => {
|
||||
match dm.get(&pat.id)
|
||||
.and_then(|d| if d.depth == 0 { Some(d.base_def) }
|
||||
else { None } ) {
|
||||
|
|
@ -92,7 +94,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 +104,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 +117,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 +130,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 +201,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 +226,10 @@ 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::TupleStruct(..) |
|
||||
PatKind::Path(..) |
|
||||
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::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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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::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);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue