Merge pull request #3010 from topecongiro/issue-3009
Refactor the corner case of handling long function
This commit is contained in:
commit
e39bd35ae1
14
src/items.rs
14
src/items.rs
@ -2040,18 +2040,16 @@ fn rewrite_fn_base(
|
||||
let used_width = last_line_used_width(&result, indent.width()) + first_line_width(&ret_str);
|
||||
// Put the closing brace on the next line if it overflows the max width.
|
||||
// 1 = `)`
|
||||
if fd.inputs.is_empty() && used_width + 1 > context.config.max_width() {
|
||||
result.push('\n');
|
||||
}
|
||||
let closing_paren_overflow_max_width =
|
||||
fd.inputs.is_empty() && used_width + 1 > context.config.max_width();
|
||||
// If the last line of args contains comment, we cannot put the closing paren
|
||||
// on the same line.
|
||||
if arg_str
|
||||
args_last_line_contains_comment = arg_str
|
||||
.lines()
|
||||
.last()
|
||||
.map_or(false, |last_line| last_line.contains("//"))
|
||||
{
|
||||
args_last_line_contains_comment = true;
|
||||
result.push_str(&arg_indent.to_string_with_newline(context.config));
|
||||
.map_or(false, |last_line| last_line.contains("//"));
|
||||
if closing_paren_overflow_max_width || args_last_line_contains_comment {
|
||||
result.push_str(&indent.to_string_with_newline(context.config));
|
||||
}
|
||||
result.push(')');
|
||||
}
|
||||
|
20
tests/source/long-fn-1.rs
Normal file
20
tests/source/long-fn-1.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// Tests that a function which is almost short enough, but not quite, gets
|
||||
// formatted correctly.
|
||||
|
||||
impl Foo {
|
||||
fn some_input(&mut self, input: Input, input_path: Option<PathBuf>, ) -> (Input, Option<PathBuf>) {}
|
||||
|
||||
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {}
|
||||
}
|
||||
|
||||
// #1843
|
||||
#[allow(non_snake_case)]
|
||||
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 > {}
|
||||
}
|
@ -19,3 +19,10 @@ pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nat
|
||||
) -> 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> {
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user