Skip to content
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/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
node: FieldPat {
ident: Ident::new(field.name),
pat: pat,
is_shorthand: true,
is_shorthand: false,
}
}).collect();
let has_more_fields = field_pats.len() < pats_len;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
node: FieldPat {
ident: field.ident.node,
pat: const_expr_to_pat(tcx, &*field.expr),
is_shorthand: true,
is_shorthand: false,
},
}).collect();
PatStruct(path.clone(), field_pats, false)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ impl<'a> TraitDef<'a> {
// id is guaranteed to be Some
codemap::Spanned {
span: pat.span,
node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: true },
node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: false },
}
}).collect();
cx.pat_struct(self.span, matching_path, field_pats)
Expand Down
6 changes: 4 additions & 2 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1983,8 +1983,10 @@ impl<'a> State<'a> {
Consistent, fields.as_slice(),
|s, f| {
try!(s.cbox(indent_unit));
try!(s.print_ident(f.node.ident));
try!(s.word_nbsp(":"));
if !f.node.is_shorthand {
try!(s.print_ident(f.node.ident));
try!(s.word_nbsp(":"));
}
try!(s.print_pat(&*f.node.pat));
s.end()
},
Expand Down
15 changes: 15 additions & 0 deletions src/test/pretty/struct-pattern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// pp-exact
// pretty-compare-only
// Testing that shorthand struct patterns are preserved

fn main() { let Foo { a, ref b, mut c, x: y, z: z } = foo; }