From 30aec386f407ae440b386758e7e12432b9334885 Mon Sep 17 00:00:00 2001 From: David Barnett Date: Tue, 17 Nov 2015 11:57:49 +1300 Subject: [PATCH 1/3] Comments in structs use appropriate style Fixes #491 --- src/expr.rs | 5 ++++- tests/source/struct_lits_multiline.rs | 7 +++++++ tests/target/struct_lits.rs | 2 +- tests/target/struct_lits_multiline.rs | 9 ++++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index c4b01e38b42..5a281f2df83 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1335,7 +1335,10 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext, }, indent: indent, width: budget, - ends_with_newline: false, + ends_with_newline: match context.config.struct_lit_style { + StructLitStyle::Block => true, + StructLitStyle::Visual => false, + }, config: context.config, }; let fields_str = try_opt!(write_list(&item_vec, &fmt)); diff --git a/tests/source/struct_lits_multiline.rs b/tests/source/struct_lits_multiline.rs index b6395884713..dc0470b1447 100644 --- a/tests/source/struct_lits_multiline.rs +++ b/tests/source/struct_lits_multiline.rs @@ -71,3 +71,10 @@ fn issue201() { fn issue201_2() { let s = S{a: S2{ .. c}, .. b}; } + +fn issue491() { + Foo { + guard: None, + arm: 0, // Comment + }; +} diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs index e0b29184162..445b8028340 100644 --- a/tests/target/struct_lits.rs +++ b/tests/target/struct_lits.rs @@ -25,7 +25,7 @@ fn main() { // Comment a: foo(), // Comment // Comment - b: bar(), /* Comment */ + b: bar(), // Comment }; Foo { a: Bar, b: f() }; diff --git a/tests/target/struct_lits_multiline.rs b/tests/target/struct_lits_multiline.rs index 893c9dba888..91ead9e764a 100644 --- a/tests/target/struct_lits_multiline.rs +++ b/tests/target/struct_lits_multiline.rs @@ -32,7 +32,7 @@ fn main() { // Comment a: foo(), // Comment // Comment - b: bar(), /* Comment */ + b: bar(), // Comment }; Foo { @@ -107,3 +107,10 @@ fn issue201_2() { ..b }; } + +fn issue491() { + Foo { + guard: None, + arm: 0, // Comment + }; +} From e44a7a2800c6ee516679e714f694ba2d8a0f2039 Mon Sep 17 00:00:00 2001 From: David Barnett Date: Wed, 18 Nov 2015 23:30:23 +1300 Subject: [PATCH 2/3] Test for single arm in struct --- tests/source/struct_lits.rs | 11 +++++++++++ tests/target/struct_lits.rs | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/source/struct_lits.rs b/tests/source/struct_lits.rs index 216ce08099d..98ac6fab799 100644 --- a/tests/source/struct_lits.rs +++ b/tests/source/struct_lits.rs @@ -100,3 +100,14 @@ fn issue123() { Foo { a: ddddddddddddddddddddd, b: cccccccccccccccccccccccccccccccccccccc }; } + +fn issue491() { + Foo { + guard: None, + arm: 0, // Comment + }; + + Foo { + arm: 0, // Comment + }; +} diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs index 445b8028340..3ece0cb23a3 100644 --- a/tests/target/struct_lits.rs +++ b/tests/target/struct_lits.rs @@ -132,3 +132,12 @@ fn issue123() { b: cccccccccccccccccccccccccccccccccccccc, }; } + +fn issue491() { + Foo { + guard: None, + arm: 0, // Comment + }; + + Foo { arm: 0 /* Comment */ }; +} From b3f41e82fcf9423beaf938308f2034f5dfa508cb Mon Sep 17 00:00:00 2001 From: David Barnett Date: Fri, 20 Nov 2015 10:37:00 +1300 Subject: [PATCH 3/3] Use tactic instead of config Add mixed test Mixed is unreachable as there is no input combination that could get to this value --- src/expr.rs | 7 ++++--- tests/source/struct_lits.rs | 3 +++ tests/target/struct_lits.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 5a281f2df83..7e0407465b9 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1335,9 +1335,10 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext, }, indent: indent, width: budget, - ends_with_newline: match context.config.struct_lit_style { - StructLitStyle::Block => true, - StructLitStyle::Visual => false, + ends_with_newline: match tactic { + DefinitiveListTactic::Horizontal => false, + DefinitiveListTactic::Vertical => true, + DefinitiveListTactic::Mixed => unreachable!(), }, config: context.config, }; diff --git a/tests/source/struct_lits.rs b/tests/source/struct_lits.rs index 98ac6fab799..0c30d721c4d 100644 --- a/tests/source/struct_lits.rs +++ b/tests/source/struct_lits.rs @@ -110,4 +110,7 @@ fn issue491() { Foo { arm: 0, // Comment }; + + Foo { a: aaaaaaaaaa, b: bbbbbbbb, c: cccccccccc, d: dddddddddd, /* a comment */ + e: eeeeeeeee }; } diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs index 3ece0cb23a3..a08222f8f13 100644 --- a/tests/target/struct_lits.rs +++ b/tests/target/struct_lits.rs @@ -140,4 +140,12 @@ fn issue491() { }; Foo { arm: 0 /* Comment */ }; + + Foo { + a: aaaaaaaaaa, + b: bbbbbbbb, + c: cccccccccc, + d: dddddddddd, // a comment + e: eeeeeeeee, + }; }