Skip to content

Commit 6bf1382

Browse files
luke-cliftonnrc
authored andcommitted
Indent open brace for impl when nested. (#1227)
* Indent open brace for impl when nested. Fixes #1226 * Added test case for indented impl with brace on newline
1 parent 1cc4f0c commit 6bf1382

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/items.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,10 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
497497
result.push_str(&where_clause_str);
498498

499499
match context.config.item_brace_style {
500-
BraceStyle::AlwaysNextLine => result.push('\n'),
500+
BraceStyle::AlwaysNextLine => {
501+
result.push('\n');
502+
result.push_str(&offset.to_string(context.config));
503+
}
501504
BraceStyle::PreferSameLine => result.push(' '),
502505
BraceStyle::SameLineWhere => {
503506
if !where_clause_str.is_empty() {

tests/target/indented-impl.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// rustfmt-item_brace_style: AlwaysNextLine
2+
mod x {
3+
struct X(i8);
4+
5+
impl Y for X
6+
{
7+
fn y(self) -> () {
8+
println!("ok");
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)