File tree Expand file tree Collapse file tree 6 files changed +81
-4
lines changed Expand file tree Collapse file tree 6 files changed +81
-4
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ macro_rules! create_config {
130
130
pub fn $i( & mut self , value: $ty) {
131
131
( self . 0 ) . $i. 2 = value;
132
132
match stringify!( $i) {
133
- "use_small_heuristics" => self . 0 . set_heuristics( ) ,
133
+ "max_width" | " use_small_heuristics" => self . 0 . set_heuristics( ) ,
134
134
"license_template_path" => self . 0 . set_license_template( ) ,
135
135
& _ => ( ) ,
136
136
}
@@ -292,7 +292,7 @@ macro_rules! create_config {
292
292
}
293
293
294
294
match key {
295
- "use_small_heuristics" => self . set_heuristics( ) ,
295
+ "max_width" | " use_small_heuristics" => self . set_heuristics( ) ,
296
296
"license_template_path" => self . set_license_template( ) ,
297
297
& _ => ( ) ,
298
298
}
Original file line number Diff line number Diff line change @@ -242,8 +242,14 @@ impl WidthHeuristics {
242
242
243
243
// scale the default WidthHeuristics according to max_width
244
244
pub fn scaled ( max_width : usize ) -> WidthHeuristics {
245
- let mut max_width_ratio: f32 = max_width as f32 / 100.0 ; // 100 is the default width -> default ratio is 1
246
- max_width_ratio = ( max_width_ratio * 10.0 ) . round ( ) / 10.0 ; // round to the closest 0.1
245
+ const DEFAULT_MAX_WIDTH : usize = 100 ;
246
+ let max_width_ratio = if max_width > DEFAULT_MAX_WIDTH {
247
+ let ratio = max_width as f32 / DEFAULT_MAX_WIDTH as f32 ;
248
+ // round to the closest 0.1
249
+ ( ratio * 10.0 ) . round ( ) / 10.0
250
+ } else {
251
+ 1.0
252
+ } ;
247
253
WidthHeuristics {
248
254
fn_call_width : ( 60.0 * max_width_ratio) . round ( ) as usize ,
249
255
struct_lit_width : ( 18.0 * max_width_ratio) . round ( ) as usize ,
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 80
2
+ fn foo ( e : Enum ) {
3
+ match e {
4
+ Enum :: Var {
5
+ element1,
6
+ element2,
7
+ } => {
8
+ return ;
9
+ }
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 120
2
+
3
+ // elems on multiple lines for max_width 100, but same line for max_width 120
4
+ fn foo ( e : Enum ) {
5
+ match e {
6
+ Enum :: Var {
7
+ elem1,
8
+ elem2,
9
+ elem3,
10
+ } => {
11
+ return ;
12
+ }
13
+ }
14
+ }
15
+
16
+ // elems not on same line for either max_width 100 or 120
17
+ fn bar ( e : Enum ) {
18
+ match e {
19
+ Enum :: Var {
20
+ elem1,
21
+ elem2,
22
+ elem3,
23
+ elem4,
24
+ } => {
25
+ return ;
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 80
2
+ fn foo ( e : Enum ) {
3
+ match e {
4
+ Enum :: Var { element1, element2 } => {
5
+ return ;
6
+ }
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ // rustfmt-max_width: 120
2
+
3
+ // elems on multiple lines for max_width 100, but same line for max_width 120
4
+ fn foo ( e : Enum ) {
5
+ match e {
6
+ Enum :: Var { elem1, elem2, elem3 } => {
7
+ return ;
8
+ }
9
+ }
10
+ }
11
+
12
+ // elems not on same line for either max_width 100 or 120
13
+ fn bar ( e : Enum ) {
14
+ match e {
15
+ Enum :: Var {
16
+ elem1,
17
+ elem2,
18
+ elem3,
19
+ elem4,
20
+ } => {
21
+ return ;
22
+ }
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments