diff options
| author | bors <bors@rust-lang.org> | 2014-07-08 04:21:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-08 04:21:40 +0000 |
| commit | 6959931498820b2b784168164b53a79dceafc4da (patch) | |
| tree | 0dea0941fd67ad561345dc5100bbc2fb86407215 | |
| parent | 6f46621b335d398f3c837750d31797014f63578b (diff) | |
| parent | 947942e42c3856f4a673fe2e853e8c3f57e0993a (diff) | |
| download | rust-6959931498820b2b784168164b53a79dceafc4da.tar.gz rust-6959931498820b2b784168164b53a79dceafc4da.zip | |
auto merge of #15508 : jakub-/rust/struct-pattern-witness, r=alexcrichton
| -rw-r--r-- | src/librustc/middle/check_match.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/non-exhaustive-pattern-witness.rs | 4 | ||||
| -rw-r--r-- | src/test/run-make/graphviz-flowgraph/f06.dot-expected.dot | 4 |
4 files changed, 12 insertions, 8 deletions
diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 4758825bf0e..6ba112bf353 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -283,13 +283,15 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor, }; if is_structure { let fields = ty::lookup_struct_fields(cx.tcx, vid); - let field_pats = fields.move_iter() + let field_pats: Vec<FieldPat> = fields.move_iter() .zip(pats.iter()) + .filter(|&(_, pat)| pat.node != PatWild) .map(|(field, pat)| FieldPat { ident: Ident::new(field.name), pat: pat.clone() }).collect(); - PatStruct(def_to_path(cx.tcx, vid), field_pats, false) + let has_more_fields = field_pats.len() < pats.len(); + PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields) } else { PatEnum(def_to_path(cx.tcx, vid), Some(pats)) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4660bb337ab..bf210110829 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1745,13 +1745,14 @@ impl<'a> State<'a> { } ast::PatStruct(ref path, ref fields, etc) => { try!(self.print_path(path, true)); - try!(word(&mut self.s, "{")); + try!(self.nbsp()); + try!(self.word_space("{")); try!(self.commasep_cmnt( Consistent, fields.as_slice(), |s, f| { try!(s.cbox(indent_unit)); try!(s.print_ident(f.ident)); - try!(s.word_space(":")); + try!(s.word_nbsp(":")); try!(s.print_pat(&*f.pat)); s.end() }, @@ -1760,6 +1761,7 @@ impl<'a> State<'a> { if fields.len() != 0u { try!(self.word_space(",")); } try!(word(&mut self.s, "..")); } + try!(space(&mut self.s)); try!(word(&mut self.s, "}")); } ast::PatTup(ref elts) => { diff --git a/src/test/compile-fail/non-exhaustive-pattern-witness.rs b/src/test/compile-fail/non-exhaustive-pattern-witness.rs index 7fba306d868..6dc5ad8b606 100644 --- a/src/test/compile-fail/non-exhaustive-pattern-witness.rs +++ b/src/test/compile-fail/non-exhaustive-pattern-witness.rs @@ -23,7 +23,7 @@ enum Color { fn struct_with_a_nested_enum_and_vector() { match (Foo { first: true, second: None }) { - //~^ ERROR non-exhaustive patterns: `Foo{first: false, second: Some([_, _, _, _])}` not covered +//~^ ERROR non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered Foo { first: true, second: None } => (), Foo { first: true, second: Some(_) } => (), Foo { first: false, second: None } => (), @@ -40,7 +40,7 @@ fn enum_with_multiple_missing_variants() { fn enum_struct_variant() { match Red { - //~^ ERROR non-exhaustive patterns: `CustomRGBA{a: true, r: _, g: _, b: _}` not covered + //~^ ERROR non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered Red => (), Green => (), CustomRGBA { a: false, r: _, g: _, b: 0 } => (), diff --git a/src/test/run-make/graphviz-flowgraph/f06.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f06.dot-expected.dot index 61b40d68dd1..b431476f84a 100644 --- a/src/test/run-make/graphviz-flowgraph/f06.dot-expected.dot +++ b/src/test/run-make/graphviz-flowgraph/f06.dot-expected.dot @@ -4,8 +4,8 @@ digraph block { N2[label="expr 6"]; N3[label="expr S6{val: 6,}"]; N4[label="local _x"]; - N5[label="pat S6{val: _x}"]; - N6[label="block { let S6{val: _x} = S6{val: 6,}; }"]; + N5[label="pat S6 { val: _x }"]; + N6[label="block { let S6 { val: _x } = S6{val: 6,}; }"]; N0 -> N2; N2 -> N3; N3 -> N4; |
