Skip to content

Remove PatWildMulti #29486

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 2 commits into from
Nov 1, 2015
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/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
hir::PatQPath(..) |
hir::PatLit(..) |
hir::PatRange(..) |
hir::PatWild(_) => {
hir::PatWild => {
self.add_ast_node(pat.id, &[pred])
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
if mode == Mode::ConstFn {
for arg in &fd.inputs {
match arg.pat.node {
hir::PatWild(_) => {}
hir::PatWild => {}
hir::PatIdent(hir::BindByValue(hir::MutImmutable), _, None) => {}
_ => {
span_err!(self.tcx.sess, arg.pat.span, E0022,
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use util::nodemap::FnvHashMap;

pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
id: DUMMY_NODE_ID,
node: hir::PatWild(hir::PatWildSingle),
node: hir::PatWild,
span: DUMMY_SP
};

Expand Down Expand Up @@ -521,7 +521,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
if let VariantKind::Struct = v.kind() {
let field_pats: Vec<_> = v.fields.iter()
.zip(pats)
.filter(|&(_, ref pat)| pat.node != hir::PatWild(hir::PatWildSingle))
.filter(|&(_, ref pat)| pat.node != hir::PatWild)
.map(|(field, pat)| Spanned {
span: DUMMY_SP,
node: hir::FieldPat {
Expand Down Expand Up @@ -553,7 +553,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
},
_ => unreachable!()
},
ty::TyStr => hir::PatWild(hir::PatWildSingle),
ty::TyStr => hir::PatWild,

_ => {
assert_eq!(pats_len, 1);
Expand All @@ -570,7 +570,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
_ => {
match *ctor {
ConstantValue(ref v) => hir::PatLit(const_val_to_expr(v)),
_ => hir::PatWild(hir::PatWildSingle),
_ => hir::PatWild,
}
}
};
Expand Down Expand Up @@ -799,7 +799,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
},
hir::PatBox(_) | hir::PatTup(_) | hir::PatRegion(..) =>
vec!(Single),
hir::PatWild(_) =>
hir::PatWild =>
vec!(),
}
}
Expand Down Expand Up @@ -862,7 +862,7 @@ 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(_) =>
hir::PatWild =>
Some(vec![DUMMY_WILD_PAT; arity]),

hir::PatIdent(_, _, _) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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(hir::PatWildSingle) = pat.node.pat.node {
if let hir::PatWild = pat.node.pat.node {
continue;
}
self.insert_def_id(variant.field_named(pat.node.name).did);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
// will visit the substructure recursively.
}

hir::PatWild(_) | hir::PatTup(..) | hir::PatBox(..) |
hir::PatWild | hir::PatTup(..) | hir::PatBox(..) |
hir::PatRegion(..) | hir::PatLit(..) | hir::PatRange(..) |
hir::PatVec(..) => {
// Similarly, each of these cases does not
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 @@ -1211,7 +1211,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
};

match pat.node {
hir::PatWild(_) => {
hir::PatWild => {
// _
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ 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,
hir::PatWild => true,
_ => false
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,9 @@ 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)) => {
for (field, struct_field) in pat_fields.iter().zip(&v.fields) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve this comment somehow? Mention on this that when the second field is None, it's a .. pattern, which is okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Manishearth
It's an erroneous comment, PatWildMulti couldn't be here and Variant(..) pattern is hir::PatEnum(_, None)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an erroneous comment, but it addresses a real issue, that of Variant(..) patterns.

I'm saying we move this comment up and have it talk of why PatEnum(_, None) is ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misread it, sorry, will add a comment now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with a (pretty obvious) comment.

// a .. pattern is fine, but anything positional is
// not.
if let hir::PatWild(hir::PatWildMulti) = field.node {
continue
}
maybe_do_stability_check(tcx, struct_field.did, field.span, cb)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ 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(k) => PatWild(k),
PatWild => PatWild,
PatIdent(binding_mode, pth1, sub) => {
PatIdent(binding_mode,
Spanned {
Expand Down
14 changes: 2 additions & 12 deletions src/librustc_front/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub use self::Item_::*;
pub use self::Mutability::*;
pub use self::Pat_::*;
pub use self::PathListItem_::*;
pub use self::PatWildKind::*;
pub use self::PrimTy::*;
pub use self::Stmt_::*;
pub use self::StructFieldKind::*;
Expand Down Expand Up @@ -393,19 +392,10 @@ pub enum BindingMode {
BindByValue(Mutability),
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum PatWildKind {
/// Represents the wildcard pattern `_`
PatWildSingle,

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

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Pat_ {
/// Represents a wildcard pattern (either `_` or `..`)
PatWild(PatWildKind),
/// Represents a wildcard pattern (`_`)
PatWild,

/// A PatIdent may either be a new bound variable,
/// or a nullary enum (in which case the third field
Expand Down
11 changes: 2 additions & 9 deletions src/librustc_front/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ pub fn lower_pat(_lctx: &LoweringContext, p: &Pat) -> P<hir::Pat> {
P(hir::Pat {
id: p.id,
node: match p.node {
PatWild(k) => hir::PatWild(lower_pat_wild_kind(_lctx, k)),
PatWild => hir::PatWild,
PatIdent(ref binding_mode, pth1, ref sub) => {
hir::PatIdent(lower_binding_mode(_lctx, binding_mode),
pth1,
Expand Down Expand Up @@ -1482,13 +1482,6 @@ pub fn lower_block_check_mode(_lctx: &LoweringContext, b: &BlockCheckMode) -> hi
}
}

pub fn lower_pat_wild_kind(_lctx: &LoweringContext, p: PatWildKind) -> hir::PatWildKind {
match p {
PatWildSingle => hir::PatWildSingle,
PatWildMulti => hir::PatWildMulti,
}
}

pub fn lower_binding_mode(_lctx: &LoweringContext, b: &BindingMode) -> hir::BindingMode {
match *b {
BindByRef(m) => hir::BindByRef(lower_mutability(_lctx, m)),
Expand Down Expand Up @@ -1670,7 +1663,7 @@ fn pat_ident_binding_mode(lctx: &LoweringContext,
}

fn pat_wild(lctx: &LoweringContext, span: Span) -> P<hir::Pat> {
pat(lctx, span, hir::PatWild(hir::PatWildSingle))
pat(lctx, span, hir::PatWild)
}

fn pat(lctx: &LoweringContext, span: Span, pat: hir::Pat_) -> P<hir::Pat> {
Expand Down
12 changes: 4 additions & 8 deletions src/librustc_front/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1719,8 +1719,7 @@ impl<'a> State<'a> {
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
match pat.node {
hir::PatWild(hir::PatWildSingle) => try!(word(&mut self.s, "_")),
hir::PatWild(hir::PatWildMulti) => try!(word(&mut self.s, "..")),
hir::PatWild => try!(word(&mut self.s, "_")),
hir::PatIdent(binding_mode, ref path1, ref sub) => {
match binding_mode {
hir::BindByRef(mutbl) => {
Expand Down Expand Up @@ -1815,13 +1814,10 @@ impl<'a> State<'a> {
if !before.is_empty() {
try!(self.word_space(","));
}
try!(self.print_pat(&**p));
match **p {
hir::Pat { node: hir::PatWild(hir::PatWildMulti), .. } => {
// this case is handled by print_pat
}
_ => try!(word(&mut self.s, "..")),
if p.node != hir::PatWild {
try!(self.print_pat(&**p));
}
try!(word(&mut self.s, ".."));
if !after.is_empty() {
try!(self.word_space(","));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_front/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool
slice.iter().all(|p| walk_pat_(&**p, it)) &&
after.iter().all(|p| walk_pat_(&**p, it))
}
PatWild(_) |
PatWild |
PatLit(_) |
PatRange(_, _) |
PatIdent(_, _, _) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_front/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
visitor.visit_expr(lower_bound);
visitor.visit_expr(upper_bound)
}
PatWild(_) => (),
PatWild => (),
PatVec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
walk_list!(visitor, visit_pat, prepatterns);
walk_list!(visitor, visit_pat, slice_pattern);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/tcx/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'tcx> Mirror<'tcx> for PatNode<'tcx> {

fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Pattern<'tcx> {
let kind = match self.pat.node {
hir::PatWild(..) => PatternKind::Wild,
hir::PatWild => PatternKind::Wild,

hir::PatLit(ref value) => {
let value = const_eval::eval_const_expr(cx.tcx, value);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
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 hir::PatWild = field.node {
continue
}
self.check_field(field.span,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<usize> {

let column_contains_any_nonwild_patterns = |&col: &usize| -> bool {
m.iter().any(|row| match row.pats[col].node {
hir::PatWild(_) => false,
hir::PatWild => false,
_ => true
})
};
Expand Down Expand Up @@ -1629,7 +1629,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(hir::PatWildSingle)
&& arm.pats.last().unwrap().node == hir::PatWild
});

compile_submatch(bcx, &matches[..], &[discr_datum.match_input()], &chk, has_default);
Expand Down Expand Up @@ -1948,7 +1948,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
cleanup_scope)
});
}
hir::PatQPath(..) | hir::PatWild(_) | hir::PatLit(_) |
hir::PatQPath(..) | hir::PatWild | hir::PatLit(_) |
hir::PatRange(_, _) => ()
}
return bcx;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn walk_pattern(cx: &CrateContext,
}
}

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

Expand Down Expand Up @@ -485,4 +485,4 @@ fn walk_expr(cx: &CrateContext,
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
expected);

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

match p.node {
PatWild(PatWildSingle) => "_".to_string(),
PatWild(PatWildMulti) => "..".to_string(),
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, \
Expand Down
14 changes: 2 additions & 12 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub use self::MetaItem_::*;
pub use self::Mutability::*;
pub use self::Pat_::*;
pub use self::PathListItem_::*;
pub use self::PatWildKind::*;
pub use self::PrimTy::*;
pub use self::Sign::*;
pub use self::Stmt_::*;
Expand Down Expand Up @@ -569,19 +568,10 @@ pub enum BindingMode {
BindByValue(Mutability),
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum PatWildKind {
/// Represents the wildcard pattern `_`
PatWildSingle,

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

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Pat_ {
/// Represents a wildcard pattern (either `_` or `..`)
PatWild(PatWildKind),
/// Represents a wildcard pattern (`_`)
PatWild,

/// A PatIdent may either be a new bound variable,
/// or a nullary enum (in which case the third field
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 @@ -356,7 +356,7 @@ impl DummyResult {
pub fn raw_pat(sp: Span) -> ast::Pat {
ast::Pat {
id: ast::DUMMY_NODE_ID,
node: ast::PatWild(ast::PatWildSingle),
node: ast::PatWild,
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 @@ -801,7 +801,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
P(ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span })
}
fn pat_wild(&self, span: Span) -> P<ast::Pat> {
self.pat(span, ast::PatWild(ast::PatWildSingle))
self.pat(span, ast::PatWild)
}
fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
self.pat(span, ast::PatLit(expr))
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
p.map(|Pat {id, node, span}| Pat {
id: folder.new_id(id),
node: match node {
PatWild(k) => PatWild(k),
PatWild => PatWild,
PatIdent(binding_mode, pth1, sub) => {
PatIdent(binding_mode,
Spanned{span: folder.new_span(pth1.span),
Expand Down
Loading