Skip to content

Commit 6959931

Browse files
committed
auto merge of rust-lang#15508 : jakub-/rust/struct-pattern-witness, r=alexcrichton
2 parents 6f46621 + 947942e commit 6959931

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/librustc/middle/check_match.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,15 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
283283
};
284284
if is_structure {
285285
let fields = ty::lookup_struct_fields(cx.tcx, vid);
286-
let field_pats = fields.move_iter()
286+
let field_pats: Vec<FieldPat> = fields.move_iter()
287287
.zip(pats.iter())
288+
.filter(|&(_, pat)| pat.node != PatWild)
288289
.map(|(field, pat)| FieldPat {
289290
ident: Ident::new(field.name),
290291
pat: pat.clone()
291292
}).collect();
292-
PatStruct(def_to_path(cx.tcx, vid), field_pats, false)
293+
let has_more_fields = field_pats.len() < pats.len();
294+
PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields)
293295
} else {
294296
PatEnum(def_to_path(cx.tcx, vid), Some(pats))
295297
}

src/libsyntax/print/pprust.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1745,13 +1745,14 @@ impl<'a> State<'a> {
17451745
}
17461746
ast::PatStruct(ref path, ref fields, etc) => {
17471747
try!(self.print_path(path, true));
1748-
try!(word(&mut self.s, "{"));
1748+
try!(self.nbsp());
1749+
try!(self.word_space("{"));
17491750
try!(self.commasep_cmnt(
17501751
Consistent, fields.as_slice(),
17511752
|s, f| {
17521753
try!(s.cbox(indent_unit));
17531754
try!(s.print_ident(f.ident));
1754-
try!(s.word_space(":"));
1755+
try!(s.word_nbsp(":"));
17551756
try!(s.print_pat(&*f.pat));
17561757
s.end()
17571758
},
@@ -1760,6 +1761,7 @@ impl<'a> State<'a> {
17601761
if fields.len() != 0u { try!(self.word_space(",")); }
17611762
try!(word(&mut self.s, ".."));
17621763
}
1764+
try!(space(&mut self.s));
17631765
try!(word(&mut self.s, "}"));
17641766
}
17651767
ast::PatTup(ref elts) => {

src/test/compile-fail/non-exhaustive-pattern-witness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum Color {
2323

2424
fn struct_with_a_nested_enum_and_vector() {
2525
match (Foo { first: true, second: None }) {
26-
//~^ ERROR non-exhaustive patterns: `Foo{first: false, second: Some([_, _, _, _])}` not covered
26+
//~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
2727
Foo { first: true, second: None } => (),
2828
Foo { first: true, second: Some(_) } => (),
2929
Foo { first: false, second: None } => (),
@@ -40,7 +40,7 @@ fn enum_with_multiple_missing_variants() {
4040

4141
fn enum_struct_variant() {
4242
match Red {
43-
//~^ ERROR non-exhaustive patterns: `CustomRGBA{a: true, r: _, g: _, b: _}` not covered
43+
//~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
4444
Red => (),
4545
Green => (),
4646
CustomRGBA { a: false, r: _, g: _, b: 0 } => (),

src/test/run-make/graphviz-flowgraph/f06.dot-expected.dot

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ digraph block {
44
N2[label="expr 6"];
55
N3[label="expr S6{val: 6,}"];
66
N4[label="local _x"];
7-
N5[label="pat S6{val: _x}"];
8-
N6[label="block { let S6{val: _x} = S6{val: 6,}; }"];
7+
N5[label="pat S6 { val: _x }"];
8+
N6[label="block { let S6 { val: _x } = S6{val: 6,}; }"];
99
N0 -> N2;
1010
N2 -> N3;
1111
N3 -> N4;

0 commit comments

Comments
 (0)