Skip to content

Commit 6d43fef

Browse files
committed
Auto merge of #29486 - petrochenkov:multiwild, r=Manishearth
Motivation: - It is not actually a pattern - It is not actually needed, except for... Drawback: - Slice patterns like `[a, _.., b]` are pretty-printed as `[a, .., b]`. Great loss :( plugin-[breaking-change], as always
2 parents a5fbb3a + 306b0ef commit 6d43fef

File tree

29 files changed

+48
-89
lines changed

29 files changed

+48
-89
lines changed

src/librustc/middle/cfg/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
104104
hir::PatQPath(..) |
105105
hir::PatLit(..) |
106106
hir::PatRange(..) |
107-
hir::PatWild(_) => {
107+
hir::PatWild => {
108108
self.add_ast_node(pat.id, &[pred])
109109
}
110110

src/librustc/middle/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
176176
if mode == Mode::ConstFn {
177177
for arg in &fd.inputs {
178178
match arg.pat.node {
179-
hir::PatWild(_) => {}
179+
hir::PatWild => {}
180180
hir::PatIdent(hir::BindByValue(hir::MutImmutable), _, None) => {}
181181
_ => {
182182
span_err!(self.tcx.sess, arg.pat.span, E0022,

src/librustc/middle/check_match.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use util::nodemap::FnvHashMap;
4747

4848
pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
4949
id: DUMMY_NODE_ID,
50-
node: hir::PatWild(hir::PatWildSingle),
50+
node: hir::PatWild,
5151
span: DUMMY_SP
5252
};
5353

@@ -521,7 +521,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
521521
if let VariantKind::Struct = v.kind() {
522522
let field_pats: Vec<_> = v.fields.iter()
523523
.zip(pats)
524-
.filter(|&(_, ref pat)| pat.node != hir::PatWild(hir::PatWildSingle))
524+
.filter(|&(_, ref pat)| pat.node != hir::PatWild)
525525
.map(|(field, pat)| Spanned {
526526
span: DUMMY_SP,
527527
node: hir::FieldPat {
@@ -553,7 +553,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
553553
},
554554
_ => unreachable!()
555555
},
556-
ty::TyStr => hir::PatWild(hir::PatWildSingle),
556+
ty::TyStr => hir::PatWild,
557557

558558
_ => {
559559
assert_eq!(pats_len, 1);
@@ -570,7 +570,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
570570
_ => {
571571
match *ctor {
572572
ConstantValue(ref v) => hir::PatLit(const_val_to_expr(v)),
573-
_ => hir::PatWild(hir::PatWildSingle),
573+
_ => hir::PatWild,
574574
}
575575
}
576576
};
@@ -799,7 +799,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
799799
},
800800
hir::PatBox(_) | hir::PatTup(_) | hir::PatRegion(..) =>
801801
vec!(Single),
802-
hir::PatWild(_) =>
802+
hir::PatWild =>
803803
vec!(),
804804
}
805805
}
@@ -862,7 +862,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
862862
id: pat_id, ref node, span: pat_span
863863
} = raw_pat(r[col]);
864864
let head: Option<Vec<&Pat>> = match *node {
865-
hir::PatWild(_) =>
865+
hir::PatWild =>
866866
Some(vec![DUMMY_WILD_PAT; arity]),
867867

868868
hir::PatIdent(_, _, _) => {

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
142142
_ => self.tcx.sess.span_bug(lhs.span, "non-ADT in struct pattern")
143143
};
144144
for pat in pats {
145-
if let hir::PatWild(hir::PatWildSingle) = pat.node.pat.node {
145+
if let hir::PatWild = pat.node.pat.node {
146146
continue;
147147
}
148148
self.insert_def_id(variant.field_named(pat.node.name).did);

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
11411141
// will visit the substructure recursively.
11421142
}
11431143

1144-
hir::PatWild(_) | hir::PatTup(..) | hir::PatBox(..) |
1144+
hir::PatWild | hir::PatTup(..) | hir::PatBox(..) |
11451145
hir::PatRegion(..) | hir::PatLit(..) | hir::PatRange(..) |
11461146
hir::PatVec(..) => {
11471147
// Similarly, each of these cases does not

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
12111211
};
12121212

12131213
match pat.node {
1214-
hir::PatWild(_) => {
1214+
hir::PatWild => {
12151215
// _
12161216
}
12171217

src/librustc/middle/pat_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
101101
pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
102102
match pat.node {
103103
hir::PatIdent(..) => pat_is_binding(dm, pat),
104-
hir::PatWild(_) => true,
104+
hir::PatWild => true,
105105
_ => false
106106
}
107107
}

src/librustc/middle/stability.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,9 @@ pub fn check_pat(tcx: &ty::ctxt, pat: &hir::Pat,
541541
};
542542
match pat.node {
543543
// Foo(a, b, c)
544+
// A Variant(..) pattern `hir::PatEnum(_, None)` doesn't have to be recursed into.
544545
hir::PatEnum(_, Some(ref pat_fields)) => {
545546
for (field, struct_field) in pat_fields.iter().zip(&v.fields) {
546-
// a .. pattern is fine, but anything positional is
547-
// not.
548-
if let hir::PatWild(hir::PatWildMulti) = field.node {
549-
continue
550-
}
551547
maybe_do_stability_check(tcx, struct_field.did, field.span, cb)
552548
}
553549
}

src/librustc_front/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
10101010
Pat {
10111011
id: folder.new_id(id),
10121012
node: match node {
1013-
PatWild(k) => PatWild(k),
1013+
PatWild => PatWild,
10141014
PatIdent(binding_mode, pth1, sub) => {
10151015
PatIdent(binding_mode,
10161016
Spanned {

src/librustc_front/hir.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub use self::Item_::*;
2424
pub use self::Mutability::*;
2525
pub use self::Pat_::*;
2626
pub use self::PathListItem_::*;
27-
pub use self::PatWildKind::*;
2827
pub use self::PrimTy::*;
2928
pub use self::Stmt_::*;
3029
pub use self::StructFieldKind::*;
@@ -393,19 +392,10 @@ pub enum BindingMode {
393392
BindByValue(Mutability),
394393
}
395394

396-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
397-
pub enum PatWildKind {
398-
/// Represents the wildcard pattern `_`
399-
PatWildSingle,
400-
401-
/// Represents the wildcard pattern `..`
402-
PatWildMulti,
403-
}
404-
405395
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
406396
pub enum Pat_ {
407-
/// Represents a wildcard pattern (either `_` or `..`)
408-
PatWild(PatWildKind),
397+
/// Represents a wildcard pattern (`_`)
398+
PatWild,
409399

410400
/// A PatIdent may either be a new bound variable,
411401
/// or a nullary enum (in which case the third field

src/librustc_front/lowering.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ pub fn lower_pat(_lctx: &LoweringContext, p: &Pat) -> P<hir::Pat> {
818818
P(hir::Pat {
819819
id: p.id,
820820
node: match p.node {
821-
PatWild(k) => hir::PatWild(lower_pat_wild_kind(_lctx, k)),
821+
PatWild => hir::PatWild,
822822
PatIdent(ref binding_mode, pth1, ref sub) => {
823823
hir::PatIdent(lower_binding_mode(_lctx, binding_mode),
824824
pth1,
@@ -1482,13 +1482,6 @@ pub fn lower_block_check_mode(_lctx: &LoweringContext, b: &BlockCheckMode) -> hi
14821482
}
14831483
}
14841484

1485-
pub fn lower_pat_wild_kind(_lctx: &LoweringContext, p: PatWildKind) -> hir::PatWildKind {
1486-
match p {
1487-
PatWildSingle => hir::PatWildSingle,
1488-
PatWildMulti => hir::PatWildMulti,
1489-
}
1490-
}
1491-
14921485
pub fn lower_binding_mode(_lctx: &LoweringContext, b: &BindingMode) -> hir::BindingMode {
14931486
match *b {
14941487
BindByRef(m) => hir::BindByRef(lower_mutability(_lctx, m)),
@@ -1670,7 +1663,7 @@ fn pat_ident_binding_mode(lctx: &LoweringContext,
16701663
}
16711664

16721665
fn pat_wild(lctx: &LoweringContext, span: Span) -> P<hir::Pat> {
1673-
pat(lctx, span, hir::PatWild(hir::PatWildSingle))
1666+
pat(lctx, span, hir::PatWild)
16741667
}
16751668

16761669
fn pat(lctx: &LoweringContext, span: Span, pat: hir::Pat_) -> P<hir::Pat> {

src/librustc_front/print/pprust.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1719,8 +1719,7 @@ impl<'a> State<'a> {
17191719
/* Pat isn't normalized, but the beauty of it
17201720
is that it doesn't matter */
17211721
match pat.node {
1722-
hir::PatWild(hir::PatWildSingle) => try!(word(&mut self.s, "_")),
1723-
hir::PatWild(hir::PatWildMulti) => try!(word(&mut self.s, "..")),
1722+
hir::PatWild => try!(word(&mut self.s, "_")),
17241723
hir::PatIdent(binding_mode, ref path1, ref sub) => {
17251724
match binding_mode {
17261725
hir::BindByRef(mutbl) => {
@@ -1815,13 +1814,10 @@ impl<'a> State<'a> {
18151814
if !before.is_empty() {
18161815
try!(self.word_space(","));
18171816
}
1818-
try!(self.print_pat(&**p));
1819-
match **p {
1820-
hir::Pat { node: hir::PatWild(hir::PatWildMulti), .. } => {
1821-
// this case is handled by print_pat
1822-
}
1823-
_ => try!(word(&mut self.s, "..")),
1817+
if p.node != hir::PatWild {
1818+
try!(self.print_pat(&**p));
18241819
}
1820+
try!(word(&mut self.s, ".."));
18251821
if !after.is_empty() {
18261822
try!(self.word_space(","));
18271823
}

src/librustc_front/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool
4444
slice.iter().all(|p| walk_pat_(&**p, it)) &&
4545
after.iter().all(|p| walk_pat_(&**p, it))
4646
}
47-
PatWild(_) |
47+
PatWild |
4848
PatLit(_) |
4949
PatRange(_, _) |
5050
PatIdent(_, _, _) |

src/librustc_front/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
466466
visitor.visit_expr(lower_bound);
467467
visitor.visit_expr(upper_bound)
468468
}
469-
PatWild(_) => (),
469+
PatWild => (),
470470
PatVec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
471471
walk_list!(visitor, visit_pat, prepatterns);
472472
walk_list!(visitor, visit_pat, slice_pattern);

src/librustc_mir/tcx/pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'tcx> Mirror<'tcx> for PatNode<'tcx> {
139139

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

144144
hir::PatLit(ref value) => {
145145
let value = const_eval::eval_const_expr(cx.tcx, value);

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
962962
match self.tcx.pat_ty(pattern).sty {
963963
ty::TyStruct(def, _) => {
964964
for (i, field) in fields.iter().enumerate() {
965-
if let hir::PatWild(..) = field.node {
965+
if let hir::PatWild = field.node {
966966
continue
967967
}
968968
self.check_field(field.span,

src/librustc_trans/trans/_match.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<usize> {
866866

867867
let column_contains_any_nonwild_patterns = |&col: &usize| -> bool {
868868
m.iter().any(|row| match row.pats[col].node {
869-
hir::PatWild(_) => false,
869+
hir::PatWild => false,
870870
_ => true
871871
})
872872
};
@@ -1629,7 +1629,7 @@ fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>,
16291629
// to the default arm.
16301630
let has_default = arms.last().map_or(false, |arm| {
16311631
arm.pats.len() == 1
1632-
&& arm.pats.last().unwrap().node == hir::PatWild(hir::PatWildSingle)
1632+
&& arm.pats.last().unwrap().node == hir::PatWild
16331633
});
16341634

16351635
compile_submatch(bcx, &matches[..], &[discr_datum.match_input()], &chk, has_default);
@@ -1948,7 +1948,7 @@ pub fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
19481948
cleanup_scope)
19491949
});
19501950
}
1951-
hir::PatQPath(..) | hir::PatWild(_) | hir::PatLit(_) |
1951+
hir::PatQPath(..) | hir::PatWild | hir::PatLit(_) |
19521952
hir::PatRange(_, _) => ()
19531953
}
19541954
return bcx;

src/librustc_trans/trans/debuginfo/create_scope_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn walk_pattern(cx: &CrateContext,
235235
}
236236
}
237237

238-
hir::PatWild(_) => {
238+
hir::PatWild => {
239239
scope_map.insert(pat.id, scope_stack.last().unwrap().scope_metadata);
240240
}
241241

@@ -485,4 +485,4 @@ fn walk_expr(cx: &CrateContext,
485485
}
486486
}
487487
}
488-
}
488+
}

src/librustc_typeck/check/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
4444
expected);
4545

4646
match pat.node {
47-
hir::PatWild(_) => {
47+
hir::PatWild => {
4848
fcx.write_ty(pat.id, expected);
4949
}
5050
hir::PatLit(ref lt) => {

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
22182218
for i in &decl.inputs {
22192219
match (*i).pat.node {
22202220
hir::PatIdent(_, _, _) => (),
2221-
hir::PatWild(hir::PatWildSingle) => (),
2221+
hir::PatWild => (),
22222222
_ => {
22232223
span_err!(ccx.tcx.sess, (*i).pat.span, E0130,
22242224
"patterns aren't allowed in foreign function declarations");

src/librustdoc/clean/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2528,8 +2528,7 @@ fn name_from_pat(p: &hir::Pat) -> String {
25282528
debug!("Trying to get a name from pattern: {:?}", p);
25292529

25302530
match p.node {
2531-
PatWild(PatWildSingle) => "_".to_string(),
2532-
PatWild(PatWildMulti) => "..".to_string(),
2531+
PatWild => "_".to_string(),
25332532
PatIdent(_, ref p, _) => p.node.to_string(),
25342533
PatEnum(ref p, _) => path_to_string(p),
25352534
PatQPath(..) => panic!("tried to get argument name from PatQPath, \

src/libsyntax/ast.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub use self::MetaItem_::*;
3131
pub use self::Mutability::*;
3232
pub use self::Pat_::*;
3333
pub use self::PathListItem_::*;
34-
pub use self::PatWildKind::*;
3534
pub use self::PrimTy::*;
3635
pub use self::Sign::*;
3736
pub use self::Stmt_::*;
@@ -569,19 +568,10 @@ pub enum BindingMode {
569568
BindByValue(Mutability),
570569
}
571570

572-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
573-
pub enum PatWildKind {
574-
/// Represents the wildcard pattern `_`
575-
PatWildSingle,
576-
577-
/// Represents the wildcard pattern `..`
578-
PatWildMulti,
579-
}
580-
581571
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
582572
pub enum Pat_ {
583-
/// Represents a wildcard pattern (either `_` or `..`)
584-
PatWild(PatWildKind),
573+
/// Represents a wildcard pattern (`_`)
574+
PatWild,
585575

586576
/// A PatIdent may either be a new bound variable,
587577
/// or a nullary enum (in which case the third field

src/libsyntax/ext/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ impl DummyResult {
356356
pub fn raw_pat(sp: Span) -> ast::Pat {
357357
ast::Pat {
358358
id: ast::DUMMY_NODE_ID,
359-
node: ast::PatWild(ast::PatWildSingle),
359+
node: ast::PatWild,
360360
span: sp,
361361
}
362362
}

src/libsyntax/ext/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
801801
P(ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, span: span })
802802
}
803803
fn pat_wild(&self, span: Span) -> P<ast::Pat> {
804-
self.pat(span, ast::PatWild(ast::PatWildSingle))
804+
self.pat(span, ast::PatWild)
805805
}
806806
fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> {
807807
self.pat(span, ast::PatLit(expr))

src/libsyntax/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
11251125
p.map(|Pat {id, node, span}| Pat {
11261126
id: folder.new_id(id),
11271127
node: match node {
1128-
PatWild(k) => PatWild(k),
1128+
PatWild => PatWild,
11291129
PatIdent(binding_mode, pth1, sub) => {
11301130
PatIdent(binding_mode,
11311131
Spanned{span: folder.new_span(pth1.span),

0 commit comments

Comments
 (0)