mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 16:15:03 +00:00
Add a trailing comma if the last arg ends with comment
This commit is contained in:
parent
b43958d96e
commit
67e8a690ff
@ -1879,6 +1879,12 @@ fn rewrite_args(context: &RewriteContext,
|
|||||||
item.item = Some(arg);
|
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() {
|
let (indent, trailing_comma, end_with_newline) = match context.config.fn_args_layout() {
|
||||||
IndentStyle::Block if fits_in_one_line => {
|
IndentStyle::Block if fits_in_one_line => {
|
||||||
(indent.block_indent(context.config), SeparatorTactic::Never, true)
|
(indent.block_indent(context.config), SeparatorTactic::Never, true)
|
||||||
@ -1886,6 +1892,9 @@ fn rewrite_args(context: &RewriteContext,
|
|||||||
IndentStyle::Block => {
|
IndentStyle::Block => {
|
||||||
(indent.block_indent(context.config), SeparatorTactic::Vertical, true)
|
(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),
|
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