diff --git a/src/visitor.rs b/src/visitor.rs index 6461fa89d6c..e6e7f038ce7 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -19,7 +19,7 @@ use {Indent, Shape}; use codemap::{LineRangeUtils, SpanUtils}; use comment::{contains_comment, FindUncommented}; use comment::rewrite_comment; -use config::Config; +use config::{BraceStyle, Config}; use expr::{format_expr, ExprType}; use items::{format_impl, format_trait, rewrite_associated_impl_type, rewrite_associated_type, rewrite_static, rewrite_type_alias}; @@ -665,7 +665,11 @@ impl<'a> FmtVisitor<'a> { self.buffer.push_str(&ident.to_string()); if is_internal { - self.buffer.push_str(" {"); + match self.config.item_brace_style() { + BraceStyle::AlwaysNextLine => self.buffer + .push_str(&format!("\n{}{{", self.block_indent.to_string(self.config))), + _ => self.buffer.push_str(" {"), + } // Hackery to account for the closing }. let mod_lo = self.codemap.span_after(source!(self, s), "{"); let body_snippet = self.snippet(mk_sp(mod_lo, source!(self, m.inner).hi - BytePos(1))); diff --git a/tests/source/configs-item_brace_style-always_next_line.rs b/tests/source/configs-item_brace_style-always_next_line.rs index f60977d015c..aa84801fe5d 100644 --- a/tests/source/configs-item_brace_style-always_next_line.rs +++ b/tests/source/configs-item_brace_style-always_next_line.rs @@ -8,3 +8,9 @@ struct Lorem { struct Dolor where T: Eq { sit: T, } + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/tests/source/configs-item_brace_style-prefer_same_line.rs b/tests/source/configs-item_brace_style-prefer_same_line.rs index 81438f1194f..a67f7e6478e 100644 --- a/tests/source/configs-item_brace_style-prefer_same_line.rs +++ b/tests/source/configs-item_brace_style-prefer_same_line.rs @@ -8,3 +8,9 @@ struct Lorem { struct Dolor where T: Eq { sit: T, } + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/tests/source/configs-item_brace_style-same_line_where.rs b/tests/source/configs-item_brace_style-same_line_where.rs index 4dc4439c176..11d4015d4c9 100644 --- a/tests/source/configs-item_brace_style-same_line_where.rs +++ b/tests/source/configs-item_brace_style-same_line_where.rs @@ -8,3 +8,9 @@ struct Lorem { struct Dolor where T: Eq { sit: T, } + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/tests/target/configs-item_brace_style-always_next_line.rs b/tests/target/configs-item_brace_style-always_next_line.rs index b9334677e1f..eb264446bde 100644 --- a/tests/target/configs-item_brace_style-always_next_line.rs +++ b/tests/target/configs-item_brace_style-always_next_line.rs @@ -12,3 +12,10 @@ where { sit: T, } + +#[cfg(test)] +mod tests +{ + #[test] + fn it_works() {} +} diff --git a/tests/target/configs-item_brace_style-prefer_same_line.rs b/tests/target/configs-item_brace_style-prefer_same_line.rs index 3d2e4fd537e..1b5dbfa9d49 100644 --- a/tests/target/configs-item_brace_style-prefer_same_line.rs +++ b/tests/target/configs-item_brace_style-prefer_same_line.rs @@ -10,3 +10,9 @@ where T: Eq, { sit: T, } + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/tests/target/configs-item_brace_style-same_line_where.rs b/tests/target/configs-item_brace_style-same_line_where.rs index 21a10cb28a1..ab88c1ca3ab 100644 --- a/tests/target/configs-item_brace_style-same_line_where.rs +++ b/tests/target/configs-item_brace_style-same_line_where.rs @@ -11,3 +11,9 @@ where { sit: T, } + +#[cfg(test)] +mod tests { + #[test] + fn it_works() {} +} diff --git a/tests/target/indented-impl.rs b/tests/target/indented-impl.rs index 9acab7d757e..422ed55b2db 100644 --- a/tests/target/indented-impl.rs +++ b/tests/target/indented-impl.rs @@ -1,5 +1,6 @@ // rustfmt-item_brace_style: AlwaysNextLine -mod x { +mod x +{ struct X(i8); impl Y for X diff --git a/tests/target/item-brace-style-always-next-line.rs b/tests/target/item-brace-style-always-next-line.rs index 0c0f2163102..270cd35eb2e 100644 --- a/tests/target/item-brace-style-always-next-line.rs +++ b/tests/target/item-brace-style-always-next-line.rs @@ -1,6 +1,7 @@ // rustfmt-item_brace_style: AlwaysNextLine -mod M { +mod M +{ enum A { A,