Skip to content

change new line point in the case of no args #3294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,8 @@ fn rewrite_fn_base(
} && !fd.inputs.is_empty();

let mut args_last_line_contains_comment = false;
let mut no_args_and_over_max_width = false;

if put_args_in_block {
arg_indent = indent.block_indent(context.config);
result.push_str(&arg_indent.to_string_with_newline(context.config));
Expand All @@ -2083,10 +2085,12 @@ fn rewrite_fn_base(
.lines()
.last()
.map_or(false, |last_line| last_line.contains("//"));
result.push(')');

if closing_paren_overflow_max_width || args_last_line_contains_comment {
result.push_str(&indent.to_string_with_newline(context.config));
no_args_and_over_max_width = true;
}
result.push(')');
}

// Return type.
Expand Down Expand Up @@ -2126,7 +2130,9 @@ fn rewrite_fn_base(
result.push_str(&indent.to_string_with_newline(context.config));
indent
} else {
result.push(' ');
if arg_str.len() != 0 || !no_args_and_over_max_width {
result.push(' ');
}
Indent::new(indent.block_indent, last_line_width(&result))
};

Expand Down
3 changes: 3 additions & 0 deletions tests/source/issue-3278.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn parse_conditional<'a, I: 'a>() -> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
where I: Stream<Item = char>
{}
6 changes: 6 additions & 0 deletions tests/target/issue-3278.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub fn parse_conditional<'a, I: 'a>()
-> impl Parser<Input = I, Output = Expr, PartialState = ()> + 'a
where
I: Stream<Item = char>,
{
}
8 changes: 4 additions & 4 deletions tests/target/long-fn-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ impl Foo {

// #1843
#[allow(non_snake_case)]
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash(
) -> bool {
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash()
-> bool {
false
}

// #3009
impl Something {
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
) -> Result<(), String> {
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine()
-> Result<(), String> {
}
}