Skip to content

Commit

Permalink
Auto merge of #31685 - petrochenkov:patrefact2, r=eddyb
Browse files Browse the repository at this point in the history
And split `PatKind::Enum` into `PatKind::TupleStruct` and `PatKind::Path`.
This is the HIR part of #31581.
This is also kind of a preparation for rust-lang/rfcs#1492.

r? @eddyb
  • Loading branch information
bors committed Feb 17, 2016
2 parents 82f30d2 + 06755d9 commit 0d1cd9b
Show file tree
Hide file tree
Showing 35 changed files with 416 additions and 423 deletions.
2 changes: 1 addition & 1 deletion src/librustc/front/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/front/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 15 additions & 14 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 0d1cd9b

Please sign in to comment.