Skip to content

Commit 20b9897

Browse files
committed
rollup merge of #18362 : kevinmehall/pprint-struct-pat-shorthand
2 parents c381752 + e5f7090 commit 20b9897

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
421421
node: FieldPat {
422422
ident: Ident::new(field.name),
423423
pat: pat,
424-
is_shorthand: true,
424+
is_shorthand: false,
425425
}
426426
}).collect();
427427
let has_more_fields = field_pats.len() < pats_len;

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
341341
node: FieldPat {
342342
ident: field.ident.node,
343343
pat: const_expr_to_pat(tcx, &*field.expr),
344-
is_shorthand: true,
344+
is_shorthand: false,
345345
},
346346
}).collect();
347347
PatStruct(path.clone(), field_pats, false)

src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ impl<'a> TraitDef<'a> {
12501250
// id is guaranteed to be Some
12511251
codemap::Spanned {
12521252
span: pat.span,
1253-
node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: true },
1253+
node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: false },
12541254
}
12551255
}).collect();
12561256
cx.pat_struct(self.span, matching_path, field_pats)

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,8 +1997,10 @@ impl<'a> State<'a> {
19971997
Consistent, fields.as_slice(),
19981998
|s, f| {
19991999
try!(s.cbox(indent_unit));
2000-
try!(s.print_ident(f.node.ident));
2001-
try!(s.word_nbsp(":"));
2000+
if !f.node.is_shorthand {
2001+
try!(s.print_ident(f.node.ident));
2002+
try!(s.word_nbsp(":"));
2003+
}
20022004
try!(s.print_pat(&*f.node.pat));
20032005
s.end()
20042006
},

src/test/pretty/struct-pattern.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// pp-exact
12+
// pretty-compare-only
13+
// Testing that shorthand struct patterns are preserved
14+
15+
fn main() { let Foo { a, ref b, mut c, x: y, z: z } = foo; }

0 commit comments

Comments
 (0)