File tree 3 files changed +104
-2
lines changed
source/configs/brace_style
target/configs/brace_style
3 files changed +104
-2
lines changed Original file line number Diff line number Diff line change @@ -322,8 +322,28 @@ impl<'a> FmtVisitor<'a> {
322
322
let snippet = self . snippet ( item. span ) ;
323
323
let brace_pos = snippet. find_uncommented ( "{" ) . unwrap ( ) ;
324
324
325
- self . push_str ( "{" ) ;
326
325
if !item. body . is_empty ( ) || contains_comment ( & snippet[ brace_pos..] ) {
326
+ // configure opening brace style
327
+ let brace_style = self . config . brace_style ( ) ;
328
+ match brace_style {
329
+ BraceStyle :: AlwaysNextLine => {
330
+ // ensure we don't allow a space at the end so the line doesn't end with a space
331
+ // (caused by &item.abi above => 'extern "C" ')
332
+ if self . buffer . ends_with ( ' ' ) {
333
+ self . buffer . pop ( ) ;
334
+ }
335
+
336
+ let nested_indent = self . shape ( ) . indent ;
337
+ let line = & format ! (
338
+ "{}{}" ,
339
+ nested_indent. to_string_with_newline( self . config) ,
340
+ "{"
341
+ ) ;
342
+ self . push_str ( line) ;
343
+ }
344
+ _ => self . push_str ( "{" ) ,
345
+ } ;
346
+
327
347
// FIXME: this skips comments between the extern keyword and the opening
328
348
// brace.
329
349
self . last_pos = item. span . lo ( ) + BytePos ( brace_pos as u32 + 1 ) ;
@@ -347,9 +367,12 @@ impl<'a> FmtVisitor<'a> {
347
367
self . block_indent = self . block_indent . block_unindent ( self . config ) ;
348
368
self . format_missing_with_indent ( item. span . hi ( ) - BytePos ( 1 ) ) ;
349
369
}
370
+
371
+ self . push_str ( "}" ) ;
372
+ } else {
373
+ self . push_str ( "{}" ) ;
350
374
}
351
375
352
- self . push_str ( "}" ) ;
353
376
self . last_pos = item. span . hi ( ) ;
354
377
}
355
378
Original file line number Diff line number Diff line change
1
+ // rustfmt-brace_style: AlwaysNextLine
2
+ // AlwaysNextLine brace style for extern blocks
3
+
4
+ fn main ( )
5
+ {
6
+ extern "C"
7
+ {
8
+ fn i_am_good ( x : i32 ) ;
9
+ }
10
+
11
+ extern "Rust" {
12
+ fn foo ( x : i32 ) ;
13
+ }
14
+
15
+ extern {
16
+ #[ link_name = "actual_symbol_name" ]
17
+ fn foobar ( ) ;
18
+ }
19
+
20
+ extern "cdecl" { }
21
+
22
+ extern "stdcall" { }
23
+
24
+ extern "win64" {
25
+ fn bar ( x : i32 ) ;
26
+ }
27
+
28
+ extern "aapcs" {
29
+ }
30
+
31
+ extern "fastcall"
32
+ { /* f*/ }
33
+
34
+ unsafe extern "C++" {
35
+ fn lorem ( ) ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-brace_style: AlwaysNextLine
2
+ // AlwaysNextLine brace style for extern blocks
3
+
4
+ fn main ( )
5
+ {
6
+ extern "C"
7
+ {
8
+ fn i_am_good ( x : i32 ) ;
9
+ }
10
+
11
+ extern "Rust"
12
+ {
13
+ fn foo ( x : i32 ) ;
14
+ }
15
+
16
+ extern "C"
17
+ {
18
+ #[ link_name = "actual_symbol_name" ]
19
+ fn foobar ( ) ;
20
+ }
21
+
22
+ extern "cdecl" { }
23
+
24
+ extern "stdcall" { }
25
+
26
+ extern "win64"
27
+ {
28
+ fn bar ( x : i32 ) ;
29
+ }
30
+
31
+ extern "aapcs" { }
32
+
33
+ extern "fastcall"
34
+ {
35
+ /* f*/
36
+ }
37
+
38
+ unsafe extern "C++"
39
+ {
40
+ fn lorem ( ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments