Add a trailing comma if the last arg ends with comment

This commit is contained in:
topecongiro 2017-05-27 07:33:06 +09:00
parent b43958d96e
commit 67e8a690ff
3 changed files with 31 additions and 8 deletions

View File

@ -1879,6 +1879,12 @@ fn rewrite_args(context: &RewriteContext,
item.item = Some(arg);
}
let last_line_ends_with_comment = arg_items
.iter()
.last()
.and_then(|item| item.post_comment.as_ref())
.map_or(false, |s| s.trim().starts_with("//"));
let (indent, trailing_comma, end_with_newline) = match context.config.fn_args_layout() {
IndentStyle::Block if fits_in_one_line => {
(indent.block_indent(context.config), SeparatorTactic::Never, true)
@ -1886,6 +1892,9 @@ fn rewrite_args(context: &RewriteContext,
IndentStyle::Block => {
(indent.block_indent(context.config), SeparatorTactic::Vertical, true)
}
IndentStyle::Visual if last_line_ends_with_comment => {
(arg_indent, SeparatorTactic::Vertical, true)
}
IndentStyle::Visual => (arg_indent, SeparatorTactic::Never, false),
};

View File

@ -0,0 +1,22 @@
// #1587
pub trait X {
fn a(&self) -> &'static str;
fn bcd(&self,
c: &str, // comment on this arg
d: u16, // comment on this arg
e: &Vec<String>, // comment on this arg
) -> Box<Q>;
}
// #1595
fn foo(arg1: LongTypeName,
arg2: LongTypeName,
arg3: LongTypeName,
arg4: LongTypeName,
arg5: LongTypeName,
arg6: LongTypeName,
arg7: LongTypeName,
//arg8: LongTypeName,
) {
// do stuff
}

View File

@ -1,8 +0,0 @@
pub trait X {
fn a(&self) -> &'static str;
fn bcd(&self,
c: &str, // comment on this arg
d: u16, // comment on this arg
e: &Vec<String> // comment on this arg
) -> Box<Q>;
}