Skip to content

Commit c719d68

Browse files
committed
Merge pull request #500 from marcusklaas/pub-statix
Format visibility for statics and consts
2 parents 8a9bbd9 + 7e0456b commit c719d68

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/items.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,13 +1118,18 @@ impl<'a> FmtVisitor<'a> {
11181118
}
11191119

11201120
pub fn rewrite_static(prefix: &str,
1121+
vis: ast::Visibility,
11211122
ident: ast::Ident,
11221123
ty: &ast::Ty,
11231124
mutability: ast::Mutability,
11241125
expr: &ast::Expr,
11251126
context: &RewriteContext)
11261127
-> Option<String> {
1127-
let prefix = format!("{} {}{}: ", prefix, format_mutability(mutability), ident);
1128+
let prefix = format!("{}{} {}{}: ",
1129+
format_visibility(vis),
1130+
prefix,
1131+
format_mutability(mutability),
1132+
ident);
11281133
// 2 = " =".len()
11291134
let ty_str = try_opt!(ty.rewrite(context,
11301135
context.config.max_width - context.block_indent.width() -

src/visitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
219219
}
220220
ast::Item_::ItemStatic(ref ty, mutability, ref expr) => {
221221
let rewrite = rewrite_static("static",
222+
item.vis,
222223
item.ident,
223224
ty,
224225
mutability,
@@ -228,6 +229,7 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
228229
}
229230
ast::Item_::ItemConst(ref ty, ref expr) => {
230231
let rewrite = rewrite_static("const",
232+
item.vis,
231233
item.ident,
232234
ty,
233235
ast::Mutability::MutImmutable,

tests/source/static.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
pub const FILE_GENERIC_READ: DWORD =
1+
const FILE_GENERIC_READ: DWORD =
22
STANDARD_RIGHTS_READ | FILE_READ_DATA |
33
FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE;
44

5-
pub static boolnames: &'static[&'static str] = &["bw", "am", "xsb", "xhp", "xenl", "eo",
5+
static boolnames: &'static[&'static str] = &["bw", "am", "xsb", "xhp", "xenl", "eo",
66
"gn", "hc", "km", "hs", "in", "db", "da", "mir", "msgr", "os", "eslok", "xt", "hz", "ul", "xon",
77
"nxon", "mc5i", "chts", "nrrmc", "npc", "ndscr", "ccc", "bce", "hls", "xhpa", "crxm", "daisy",
88
"xvpa", "sam", "cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];
99

1010
static mut name: SomeType = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
11+
12+
pub static count : u8 = 10 ;
13+
14+
pub const test: &Type = &val;

tests/target/static.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ static boolnames: &'static [&'static str] = &["bw", "am", "xsb", "xhp", "xenl",
1111

1212
static mut name: SomeType =
1313
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
14+
15+
pub static count: u8 = 10;
16+
17+
pub const test: &Type = &val;

0 commit comments

Comments
 (0)