auto merge of #15508 : jakub-/rust/struct-pattern-witness, r=alexcrichton
This commit is contained in:
commit
6959931498
4 changed files with 12 additions and 8 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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 } => (),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue