Skip to content

Commit 6e41100

Browse files
authored
Merge pull request #2005 from topecongiro/issue-2003
Put the opening brace of fn body on the next line if it exceeds max width
2 parents ce62f0a + c66560f commit 6e41100

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/items.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,12 @@ impl<'a> FmtVisitor<'a> {
250250
true,
251251
));
252252

253-
if force_newline_brace {
253+
if self.config.fn_brace_style() == BraceStyle::AlwaysNextLine || force_newline_brace {
254254
newline_brace = true;
255-
} else if self.config.fn_brace_style() != BraceStyle::AlwaysNextLine
256-
&& !result.contains('\n')
257-
{
255+
} else if last_line_width(&result) + 2 > self.shape().width {
256+
// 2 = ` {`
257+
newline_brace = true;
258+
} else if !result.contains('\n') {
258259
newline_brace = false;
259260
}
260261

tests/source/fn-simple.rs

+7
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ pub fn waltz(cwd: &Path) -> CliAssert {
5252
}
5353
}
5454
}
55+
56+
// #2003
57+
mod foo {
58+
fn __bindgen_test_layout_i_open0_c_open1_char_a_open2_char_close2_close1_close0_instantiation() {
59+
foo();
60+
}
61+
}

tests/target/fn-simple.rs

+8
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@ pub fn waltz(cwd: &Path) -> CliAssert {
9393
}
9494
}
9595
}
96+
97+
// #2003
98+
mod foo {
99+
fn __bindgen_test_layout_i_open0_c_open1_char_a_open2_char_close2_close1_close0_instantiation()
100+
{
101+
foo();
102+
}
103+
}

0 commit comments

Comments
 (0)