Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e39bd35

Browse files
authored
Merge pull request rust-lang#3010 from topecongiro/issue-3009
Refactor the corner case of handling long function
2 parents bba7dbf + d835748 commit e39bd35

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/items.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,18 +2040,16 @@ fn rewrite_fn_base(
20402040
let used_width = last_line_used_width(&result, indent.width()) + first_line_width(&ret_str);
20412041
// Put the closing brace on the next line if it overflows the max width.
20422042
// 1 = `)`
2043-
if fd.inputs.is_empty() && used_width + 1 > context.config.max_width() {
2044-
result.push('\n');
2045-
}
2043+
let closing_paren_overflow_max_width =
2044+
fd.inputs.is_empty() && used_width + 1 > context.config.max_width();
20462045
// If the last line of args contains comment, we cannot put the closing paren
20472046
// on the same line.
2048-
if arg_str
2047+
args_last_line_contains_comment = arg_str
20492048
.lines()
20502049
.last()
2051-
.map_or(false, |last_line| last_line.contains("//"))
2052-
{
2053-
args_last_line_contains_comment = true;
2054-
result.push_str(&arg_indent.to_string_with_newline(context.config));
2050+
.map_or(false, |last_line| last_line.contains("//"));
2051+
if closing_paren_overflow_max_width || args_last_line_contains_comment {
2052+
result.push_str(&indent.to_string_with_newline(context.config));
20552053
}
20562054
result.push(')');
20572055
}

tests/source/long-fn-1.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Tests that a function which is almost short enough, but not quite, gets
2+
// formatted correctly.
3+
4+
impl Foo {
5+
fn some_input(&mut self, input: Input, input_path: Option<PathBuf>, ) -> (Input, Option<PathBuf>) {}
6+
7+
fn some_inpu(&mut self, input: Input, input_path: Option<PathBuf>) -> (Input, Option<PathBuf>) {}
8+
}
9+
10+
// #1843
11+
#[allow(non_snake_case)]
12+
pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nativeContainsByHash() -> bool {
13+
false
14+
}
15+
16+
// #3009
17+
impl Something {
18+
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
19+
) -> Result< (), String > {}
20+
}

tests/target/long-fn-1.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ pub extern "C" fn Java_com_exonum_binding_storage_indices_ValueSetIndexProxy_nat
1919
) -> bool {
2020
false
2121
}
22+
23+
// #3009
24+
impl Something {
25+
fn my_function_name_is_way_to_long_but_used_as_a_case_study_or_an_example_its_fine(
26+
) -> Result<(), String> {
27+
}
28+
}

0 commit comments

Comments
 (0)