Skip to content

AST refactoring: merge PatWild and PatWildMulti into one variant with a flag #16306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libregex_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
pats: vec!(box(GC) ast::Pat{
id: ast::DUMMY_NODE_ID,
span: self.sp,
node: ast::PatWild,
node: ast::PatWild(ast::PatWildSingle),
}),
guard: None,
body: body,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a> CFGBuilder<'a> {
ast::PatEnum(_, None) |
ast::PatLit(..) |
ast::PatRange(..) |
ast::PatWild | ast::PatWildMulti => {
ast::PatWild(_) => {
self.add_node(pat.id, [pred])
}

Expand Down
13 changes: 5 additions & 8 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
let fields = ty::lookup_struct_fields(cx.tcx, vid);
let field_pats: Vec<FieldPat> = fields.move_iter()
.zip(pats.iter())
.filter(|&(_, pat)| pat.node != PatWild)
.filter(|&(_, pat)| pat.node != PatWild(PatWildSingle))
.map(|(field, pat)| FieldPat {
ident: Ident::new(field.name),
pat: pat.clone()
Expand Down Expand Up @@ -372,7 +372,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
},
_ => unreachable!()
},
ty::ty_str => PatWild,
ty::ty_str => PatWild(PatWildSingle),

_ => {
assert_eq!(pats.len(), 1);
Expand All @@ -394,7 +394,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
_ => {
match *ctor {
ConstantValue(ref v) => PatLit(const_val_to_expr(v)),
_ => PatWild
_ => PatWild(PatWildSingle),
}
}
};
Expand Down Expand Up @@ -599,7 +599,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: Gc<Pat>,
},
PatBox(_) | PatTup(_) | PatRegion(..) =>
vec!(Single),
PatWild | PatWildMulti =>
PatWild(_) =>
vec!(),
PatMac(_) =>
cx.tcx.sess.bug("unexpanded macro")
Expand Down Expand Up @@ -666,10 +666,7 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
id: pat_id, node: ref node, span: pat_span
} = &(*raw_pat(r[col]));
let head: Option<Vec<Gc<Pat>>> = match node {
&PatWild =>
Some(Vec::from_elem(arity, wild())),

&PatWildMulti =>
&PatWild(_) =>
Some(Vec::from_elem(arity, wild())),

&PatIdent(_, _, _) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: String, sp: Span) {
// Check that any variables in a pattern have types with statically known size.
fn check_pat(cx: &mut Context, pat: &Pat) {
let var_name = match pat.node {
PatWild => Some("_".to_string()),
PatWild(PatWildSingle) => Some("_".to_string()),
PatIdent(_, ref path1, _) => Some(ident_to_string(&path1.node).to_string()),
_ => None
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
op(self, cmt.clone(), pat);

match pat.node {
ast::PatWild | ast::PatWildMulti => {
ast::PatWild(_) => {
// _
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn pat_is_binding(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &Pat) -> bool {
match pat.node {
PatIdent(..) => pat_is_binding(dm, pat),
PatWild | PatWildMulti => true,
PatWild(_) => true,
_ => false
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn simple_identifier<'a>(pat: &'a Pat) -> Option<&'a Ident> {
}

pub fn wild() -> Gc<Pat> {
box (GC) Pat { id: 0, node: PatWild, span: DUMMY_SP }
box (GC) Pat { id: 0, node: PatWild(PatWildSingle), span: DUMMY_SP }
}

pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
// to the default arm.
let has_default = arms.last().map_or(false, |arm| {
arm.pats.len() == 1
&& arm.pats.last().unwrap().node == ast::PatWild
&& arm.pats.last().unwrap().node == ast::PatWild(ast::PatWildSingle)
});

compile_submatch(bcx, matches.as_slice(), [discr_datum.val], &chk, has_default);
Expand Down Expand Up @@ -1762,7 +1762,7 @@ fn bind_irrefutable_pat<'a>(
ast::PatMac(..) => {
bcx.sess().span_bug(pat.span, "unexpanded macro");
}
ast::PatWild | ast::PatWildMulti | ast::PatLit(_) | ast::PatRange(_, _) => ()
ast::PatWild(_) | ast::PatLit(_) | ast::PatRange(_, _) => ()
}
return bcx;
}
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ pub fn store_ty(cx: &Block, v: ValueRef, dst: ValueRef, t: ty::t) {

pub fn ignore_lhs(_bcx: &Block, local: &ast::Local) -> bool {
match local.pat.node {
ast::PatWild => true, _ => false
ast::PatWild(ast::PatWildSingle) => true, _ => false
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3429,7 +3429,7 @@ fn populate_scope_map(cx: &CrateContext,
}
}

ast::PatWild | ast::PatWildMulti => {
ast::PatWild(_) => {
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
let tcx = pcx.fcx.ccx.tcx;

match pat.node {
ast::PatWild | ast::PatWildMulti => {
ast::PatWild(_) => {
fcx.write_ty(pat.id, expected);
}
ast::PatLit(ref lt) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
for i in decl.inputs.iter() {
match (*i).pat.node {
ast::PatIdent(_, _, _) => (),
ast::PatWild => (),
ast::PatWild(ast::PatWildSingle) => (),
_ => {
span_err!(ccx.tcx.sess, (*i).pat.span, E0130,
"patterns aren't allowed in foreign function declarations");
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1959,8 +1959,8 @@ fn name_from_pat(p: &ast::Pat) -> String {
debug!("Trying to get a name from pattern: {:?}", p);

match p.node {
PatWild => "_".to_string(),
PatWildMulti => "..".to_string(),
PatWild(PatWildSingle) => "_".to_string(),
PatWild(PatWildMulti) => "..".to_string(),
PatIdent(_, ref p, _) => token::get_ident(p.node).get().to_string(),
PatEnum(ref p, _) => path_to_string(p),
PatStruct(ref name, ref fields, etc) => {
Expand Down
14 changes: 12 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,19 @@ pub enum BindingMode {
}

#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Pat_ {
PatWild,
pub enum PatWildKind {
/// Represents the wildcard pattern `_`
PatWildSingle,

/// Represents the wildcard pattern `..`
PatWildMulti,
}

#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Pat_ {
/// Represents a wildcard pattern (either `_` or `..`)
PatWild(PatWildKind),

/// A PatIdent may either be a new bound variable,
/// or a nullary enum (in which case the third field
/// is None).
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ pub fn walk_pat(pat: &Pat, it: |&Pat| -> bool) -> bool {
after.iter().all(|p| walk_pat(&**p, |p| it(p)))
}
PatMac(_) => fail!("attempted to analyze unexpanded pattern"),
PatWild | PatWildMulti | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
PatWild(_) | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
PatEnum(_, _) => {
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl DummyResult {
pub fn raw_pat(sp: Span) -> Gc<ast::Pat> {
box(GC) ast::Pat {
id: ast::DUMMY_NODE_ID,
node: ast::PatWild,
node: ast::PatWild(ast::PatWildSingle),
span: sp,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
box(GC) ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span }
}
fn pat_wild(&self, span: Span) -> Gc<ast::Pat> {
self.pat(span, ast::PatWild)
self.pat(span, ast::PatWild(ast::PatWildSingle))
}
fn pat_lit(&self, span: Span, expr: Gc<ast::Expr>) -> Gc<ast::Pat> {
self.pat(span, ast::PatLit(expr))
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,7 @@ pub fn noop_fold_method<T: Folder>(m: &Method, folder: &mut T) -> SmallVector<Gc
pub fn noop_fold_pat<T: Folder>(p: Gc<Pat>, folder: &mut T) -> Gc<Pat> {
let id = folder.new_id(p.id);
let node = match p.node {
PatWild => PatWild,
PatWildMulti => PatWildMulti,
PatWild(k) => PatWild(k),
PatIdent(binding_mode, ref pth1, ref sub) => {
PatIdent(binding_mode,
Spanned{span: folder.new_span(pth1.span),
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, Matcher, MatchNonterminal}
use ast::{MatchSeq, MatchTok, Method, MutTy, BiMul, Mutability};
use ast::{NamedField, UnNeg, NoReturn, UnNot, P, Pat, PatEnum};
use ast::{PatIdent, PatLit, PatRange, PatRegion, PatStruct};
use ast::{PatTup, PatBox, PatWild, PatWildMulti};
use ast::{PatTup, PatBox, PatWild, PatWildMulti, PatWildSingle};
use ast::{BiRem, Required};
use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl};
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
Expand Down Expand Up @@ -2822,7 +2822,7 @@ impl<'a> Parser<'a> {
if self.token == token::COMMA || self.token == token::RBRACKET {
slice = Some(box(GC) ast::Pat {
id: ast::DUMMY_NODE_ID,
node: PatWildMulti,
node: PatWild(PatWildMulti),
span: self.span,
})
} else {
Expand Down Expand Up @@ -2920,7 +2920,7 @@ impl<'a> Parser<'a> {
// parse _
token::UNDERSCORE => {
self.bump();
pat = PatWild;
pat = PatWild(PatWildSingle);
hi = self.last_span.hi;
return box(GC) ast::Pat {
id: ast::DUMMY_NODE_ID,
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,8 @@ impl<'a> State<'a> {
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
match pat.node {
ast::PatWild => try!(word(&mut self.s, "_")),
ast::PatWildMulti => try!(word(&mut self.s, "..")),
ast::PatWild(ast::PatWildSingle) => try!(word(&mut self.s, "_")),
ast::PatWild(ast::PatWildMulti) => try!(word(&mut self.s, "..")),
ast::PatIdent(binding_mode, ref path1, sub) => {
match binding_mode {
ast::BindByRef(mutbl) => {
Expand Down Expand Up @@ -1822,7 +1822,7 @@ impl<'a> State<'a> {
for p in slice.iter() {
if !before.is_empty() { try!(self.word_space(",")); }
match **p {
ast::Pat { node: ast::PatWildMulti, .. } => {
ast::Pat { node: ast::PatWild(ast::PatWildMulti), .. } => {
// this case is handled by print_pat
}
_ => try!(word(&mut self.s, "..")),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub fn walk_pat<E: Clone, V: Visitor<E>>(visitor: &mut V, pattern: &Pat, env: E)
visitor.visit_expr(&**lower_bound, env.clone());
visitor.visit_expr(&**upper_bound, env)
}
PatWild | PatWildMulti => (),
PatWild(_) => (),
PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => {
for prepattern in prepattern.iter() {
visitor.visit_pat(&**prepattern, env.clone())
Expand Down