diff --git a/src/items.rs b/src/items.rs index c75fe9a942f9..6ca827216899 100644 --- a/src/items.rs +++ b/src/items.rs @@ -506,10 +506,6 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - result.push('{'); if !items.is_empty() { - result.push('\n'); - let indent_str = context.block_indent.to_string(context.config); - result.push_str(&indent_str); - let mut visitor = FmtVisitor::from_codemap(context.parse_session, context.config, None); visitor.block_indent = context.block_indent.block_indent(context.config); @@ -521,8 +517,11 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) - visitor.visit_impl_item(&item); } + result.push('\n'); result.push_str(trim_newlines(&visitor.buffer.to_string())); result.push('\n'); + + let indent_str = context.block_indent.to_string(context.config); result.push_str(&indent_str); } result.push('}'); diff --git a/tests/source/impls.rs b/tests/source/impls.rs index 8e7b561ae4a6..499b07afd27b 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -21,3 +21,23 @@ impl<'a, 'b, X, Y: Foo> Foo<'a, X> for Bar<'b, Y> where X: Fooooooooooooooo { fn foo() { "hi" } } + +impl Foo { + fn foo() {} +} + +mod a { + impl Foo { + // Hello! + fn foo() {} + } +} + + +mod b { + mod a { + impl Foo { + fn foo() {} + } + } +} diff --git a/tests/target/impls.rs b/tests/target/impls.rs index 7530bf16ede0..d491dbfcea8c 100644 --- a/tests/target/impls.rs +++ b/tests/target/impls.rs @@ -36,3 +36,23 @@ impl<'a, 'b, X, Y: Foo> Foo<'a, X> for Bar<'b, Y> where X: Fooooooooooooooo "hi" } } + +impl Foo { + fn foo() {} +} + +mod a { + impl Foo { + // Hello! + fn foo() {} + } +} + + +mod b { + mod a { + impl Foo { + fn foo() {} + } + } +}