diff --git a/src/items.rs b/src/items.rs index a23e69d6881..8d72c2a3a23 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1879,6 +1879,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) @@ -1886,6 +1892,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), }; diff --git a/tests/target/fn-args-with-last-line-comment.rs b/tests/target/fn-args-with-last-line-comment.rs new file mode 100644 index 00000000000..2e310747cc4 --- /dev/null +++ b/tests/target/fn-args-with-last-line-comment.rs @@ -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, // comment on this arg + ) -> Box; +} + +// #1595 +fn foo(arg1: LongTypeName, + arg2: LongTypeName, + arg3: LongTypeName, + arg4: LongTypeName, + arg5: LongTypeName, + arg6: LongTypeName, + arg7: LongTypeName, + //arg8: LongTypeName, + ) { + // do stuff +} diff --git a/tests/target/issue-1587.rs b/tests/target/issue-1587.rs deleted file mode 100644 index b2796ef6f3b..00000000000 --- a/tests/target/issue-1587.rs +++ /dev/null @@ -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 // comment on this arg - ) -> Box; -}