Merge pull request #1596 from topecongiro/issue-1595
Add a trailing comma if the last arg ends with comment
This commit is contained in:
commit
aad250e20e
@ -1881,6 +1881,12 @@ enum ArgumentKind<'a> {
|
||||
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)
|
||||
@ -1888,6 +1894,9 @@ enum ArgumentKind<'a> {
|
||||
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),
|
||||
};
|
||||
|
||||
|
22
tests/target/fn-args-with-last-line-comment.rs
Normal file
22
tests/target/fn-args-with-last-line-comment.rs
Normal 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
|
||||
}
|
@ -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>;
|
||||
}
|
Loading…
Reference in New Issue
Block a user