Skip to content

Commit bb27bc5

Browse files
authored
Merge pull request #1806 from topecongiro/item-brace-style
Apply item_brace_style to module
2 parents 0786efc + 3e3d3c0 commit bb27bc5

9 files changed

+47
-4
lines changed

src/visitor.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use {Indent, Shape};
1919
use codemap::{LineRangeUtils, SpanUtils};
2020
use comment::{contains_comment, FindUncommented};
2121
use comment::rewrite_comment;
22-
use config::Config;
22+
use config::{BraceStyle, Config};
2323
use expr::{format_expr, ExprType};
2424
use items::{format_impl, format_trait, rewrite_associated_impl_type, rewrite_associated_type,
2525
rewrite_static, rewrite_type_alias};
@@ -665,7 +665,11 @@ impl<'a> FmtVisitor<'a> {
665665
self.buffer.push_str(&ident.to_string());
666666

667667
if is_internal {
668-
self.buffer.push_str(" {");
668+
match self.config.item_brace_style() {
669+
BraceStyle::AlwaysNextLine => self.buffer
670+
.push_str(&format!("\n{}{{", self.block_indent.to_string(self.config))),
671+
_ => self.buffer.push_str(" {"),
672+
}
669673
// Hackery to account for the closing }.
670674
let mod_lo = self.codemap.span_after(source!(self, s), "{");
671675
let body_snippet = self.snippet(mk_sp(mod_lo, source!(self, m.inner).hi - BytePos(1)));

tests/source/configs-item_brace_style-always_next_line.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ struct Lorem {
88
struct Dolor<T> where T: Eq {
99
sit: T,
1010
}
11+
12+
#[cfg(test)]
13+
mod tests {
14+
#[test]
15+
fn it_works() {}
16+
}

tests/source/configs-item_brace_style-prefer_same_line.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ struct Lorem {
88
struct Dolor<T> where T: Eq {
99
sit: T,
1010
}
11+
12+
#[cfg(test)]
13+
mod tests {
14+
#[test]
15+
fn it_works() {}
16+
}

tests/source/configs-item_brace_style-same_line_where.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ struct Lorem {
88
struct Dolor<T> where T: Eq {
99
sit: T,
1010
}
11+
12+
#[cfg(test)]
13+
mod tests {
14+
#[test]
15+
fn it_works() {}
16+
}

tests/target/configs-item_brace_style-always_next_line.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ where
1212
{
1313
sit: T,
1414
}
15+
16+
#[cfg(test)]
17+
mod tests
18+
{
19+
#[test]
20+
fn it_works() {}
21+
}

tests/target/configs-item_brace_style-prefer_same_line.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ where
1010
T: Eq, {
1111
sit: T,
1212
}
13+
14+
#[cfg(test)]
15+
mod tests {
16+
#[test]
17+
fn it_works() {}
18+
}

tests/target/configs-item_brace_style-same_line_where.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ where
1111
{
1212
sit: T,
1313
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
#[test]
18+
fn it_works() {}
19+
}

tests/target/indented-impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// rustfmt-item_brace_style: AlwaysNextLine
2-
mod x {
2+
mod x
3+
{
34
struct X(i8);
45

56
impl Y for X

tests/target/item-brace-style-always-next-line.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// rustfmt-item_brace_style: AlwaysNextLine
22

3-
mod M {
3+
mod M
4+
{
45
enum A
56
{
67
A,

0 commit comments

Comments
 (0)