File tree Expand file tree Collapse file tree 3 files changed +56
-1
lines changed Expand file tree Collapse file tree 3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -605,13 +605,23 @@ impl Rewrite for ast::GenericParam {
605
605
if let ast:: GenericParamKind :: Const {
606
606
ref ty,
607
607
kw_span : _,
608
- default : _ ,
608
+ default,
609
609
} = & self . kind
610
610
{
611
611
result. push_str ( "const " ) ;
612
612
result. push_str ( rewrite_ident ( context, self . ident ) ) ;
613
613
result. push_str ( ": " ) ;
614
614
result. push_str ( & ty. rewrite ( context, shape) ?) ;
615
+ if let Some ( default) = default {
616
+ let eq_str = match context. config . type_punctuation_density ( ) {
617
+ TypeDensity :: Compressed => "=" ,
618
+ TypeDensity :: Wide => " = " ,
619
+ } ;
620
+ result. push_str ( eq_str) ;
621
+ let budget = shape. width . checked_sub ( result. len ( ) ) ?;
622
+ let rewrite = default. rewrite ( context, Shape :: legacy ( budget, shape. indent ) ) ?;
623
+ result. push_str ( & rewrite) ;
624
+ }
615
625
} else {
616
626
result. push_str ( rewrite_ident ( context, self . ident ) ) ;
617
627
}
Original file line number Diff line number Diff line change
1
+ #![ feature( const_generics_defaults) ]
2
+ struct Foo < const N : usize = 1 , const N2 : usize = 2 > ;
3
+ struct Bar < const N : usize , const N2 : usize = { N +
4
+ 1 } > ;
5
+ struct Lots < const N1BlahFooUwU : usize = { 10 + 28 + 1872 / 10 * 3 } , const N2SecondParamOhmyyy : usize = { N1BlahFooUwU / 2 + 10 * 2 } , > ;
6
+ struct NamesRHard < const N : usize = { 1 + 1 + 1 + 1 + 1 + 1 } > ;
7
+ struct FooBar <
8
+ const LessThan100ButClose : usize = { 1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 }
9
+ > ;
10
+ struct FooBarrrrrrrr <const N : usize = { 13478234326456456444323871 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +1 +1 +1 + 1 } , >;
Original file line number Diff line number Diff line change
1
+ #![ feature( const_generics_defaults) ]
2
+ struct Foo < const N : usize = 1 , const N2 : usize = 2 > ;
3
+ struct Bar < const N : usize , const N2 : usize = { N + 1 } > ;
4
+ struct Lots <
5
+ const N1BlahFooUwU : usize = { 10 + 28 + 1872 / 10 * 3 } ,
6
+ const N2SecondParamOhmyyy : usize = { N1BlahFooUwU / 2 + 10 * 2 } ,
7
+ > ;
8
+ struct NamesRHard < const N : usize = { 1 + 1 + 1 + 1 + 1 + 1 } > ;
9
+ struct FooBar <
10
+ const LessThan100ButClose : usize = {
11
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
12
+ } ,
13
+ > ;
14
+ struct FooBarrrrrrrr <
15
+ const N : usize = {
16
+ 13478234326456456444323871
17
+ + 1
18
+ + 1
19
+ + 1
20
+ + 1
21
+ + 1
22
+ + 1
23
+ + 1
24
+ + 1
25
+ + 1
26
+ + 1
27
+ + 1
28
+ + 1
29
+ + 1
30
+ + 1
31
+ + 1
32
+ + 1
33
+ + 1
34
+ } ,
35
+ >;
You can’t perform that action at this time.
0 commit comments