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 @@ -571,13 +571,23 @@ impl Rewrite for ast::GenericParam {
571571 if let ast:: GenericParamKind :: Const {
572572 ref ty,
573573 kw_span : _,
574- default : _ ,
574+ default,
575575 } = & self . kind
576576 {
577577 result. push_str ( "const " ) ;
578578 result. push_str ( rewrite_ident ( context, self . ident ) ) ;
579579 result. push_str ( ": " ) ;
580580 result. push_str ( & ty. rewrite ( context, shape) ?) ;
581+ if let Some ( default) = default {
582+ let eq_str = match context. config . type_punctuation_density ( ) {
583+ TypeDensity :: Compressed => "=" ,
584+ TypeDensity :: Wide => " = " ,
585+ } ;
586+ result. push_str ( eq_str) ;
587+ let budget = shape. width . checked_sub ( result. len ( ) ) ?;
588+ let rewrite = default. rewrite ( context, Shape :: legacy ( budget, shape. indent ) ) ?;
589+ result. push_str ( & rewrite) ;
590+ }
581591 } else {
582592 result. push_str ( rewrite_ident ( context, self . ident ) ) ;
583593 }
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