@@ -7,7 +7,7 @@ use syntax::symbol::keywords;
7
7
8
8
use crate :: config:: lists:: * ;
9
9
use crate :: config:: { IndentStyle , TypeDensity } ;
10
- use crate :: expr:: { rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix} ;
10
+ use crate :: expr:: { format_expr , rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType } ;
11
11
use crate :: lists:: { definitive_tactic, itemize_list, write_list, ListFormatting , Separator } ;
12
12
use crate :: macros:: { rewrite_macro, MacroPosition } ;
13
13
use crate :: overflow;
@@ -132,6 +132,7 @@ where
132
132
133
133
#[ derive( Debug ) ]
134
134
pub enum SegmentParam < ' a > {
135
+ Const ( & ' a ast:: AnonConst ) ,
135
136
LifeTime ( & ' a ast:: Lifetime ) ,
136
137
Type ( & ' a ast:: Ty ) ,
137
138
Binding ( & ' a ast:: TypeBinding ) ,
@@ -142,14 +143,15 @@ impl<'a> SegmentParam<'a> {
142
143
match arg {
143
144
ast:: GenericArg :: Lifetime ( ref lt) => SegmentParam :: LifeTime ( lt) ,
144
145
ast:: GenericArg :: Type ( ref ty) => SegmentParam :: Type ( ty) ,
145
- ast:: GenericArg :: Const ( .. ) => unreachable ! ( ) , // FIXME(#3336)
146
+ ast:: GenericArg :: Const ( const_ ) => SegmentParam :: Const ( const_ ) ,
146
147
}
147
148
}
148
149
}
149
150
150
151
impl < ' a > Spanned for SegmentParam < ' a > {
151
152
fn span ( & self ) -> Span {
152
153
match * self {
154
+ SegmentParam :: Const ( const_) => const_. value . span ,
153
155
SegmentParam :: LifeTime ( lt) => lt. ident . span ,
154
156
SegmentParam :: Type ( ty) => ty. span ,
155
157
SegmentParam :: Binding ( binding) => binding. span ,
@@ -160,6 +162,7 @@ impl<'a> Spanned for SegmentParam<'a> {
160
162
impl < ' a > Rewrite for SegmentParam < ' a > {
161
163
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
162
164
match * self {
165
+ SegmentParam :: Const ( const_) => const_. rewrite ( context, shape) ,
163
166
SegmentParam :: LifeTime ( lt) => lt. rewrite ( context, shape) ,
164
167
SegmentParam :: Type ( ty) => ty. rewrite ( context, shape) ,
165
168
SegmentParam :: Binding ( binding) => {
@@ -454,7 +457,7 @@ impl Rewrite for ast::GenericArg {
454
457
match * self {
455
458
ast:: GenericArg :: Lifetime ( ref lt) => lt. rewrite ( context, shape) ,
456
459
ast:: GenericArg :: Type ( ref ty) => ty. rewrite ( context, shape) ,
457
- ast:: GenericArg :: Const ( .. ) => unreachable ! ( ) , // FIXME(#3336)
460
+ ast:: GenericArg :: Const ( ref const_ ) => const_ . rewrite ( context , shape ) ,
458
461
}
459
462
}
460
463
}
@@ -482,6 +485,12 @@ fn rewrite_bounded_lifetime(
482
485
}
483
486
}
484
487
488
+ impl Rewrite for ast:: AnonConst {
489
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
490
+ format_expr ( & self . value , ExprType :: SubExpression , context, shape)
491
+ }
492
+ }
493
+
485
494
impl Rewrite for ast:: Lifetime {
486
495
fn rewrite ( & self , context : & RewriteContext < ' _ > , _: Shape ) -> Option < String > {
487
496
Some ( rewrite_ident ( context, self . ident ) . to_owned ( ) )
@@ -525,7 +534,16 @@ impl Rewrite for ast::GenericParam {
525
534
Some ( ref rw) if !rw. is_empty ( ) => result. push_str ( & format ! ( "{} " , rw) ) ,
526
535
_ => ( ) ,
527
536
}
528
- result. push_str ( rewrite_ident ( context, self . ident ) ) ;
537
+
538
+ if let syntax:: ast:: GenericParamKind :: Const { ref ty } = & self . kind {
539
+ result. push_str ( "const " ) ;
540
+ result. push_str ( rewrite_ident ( context, self . ident ) ) ;
541
+ result. push_str ( ": " ) ;
542
+ result. push_str ( & ty. rewrite ( context, shape) ?) ;
543
+ } else {
544
+ result. push_str ( rewrite_ident ( context, self . ident ) ) ;
545
+ }
546
+
529
547
if !self . bounds . is_empty ( ) {
530
548
result. push_str ( type_bound_colon ( context) ) ;
531
549
result. push_str ( & self . bounds . rewrite ( context, shape) ?)
0 commit comments