@@ -17,9 +17,9 @@ use rustc_ast_pretty::pprust::state::MacHeader;
1717use rustc_ast_pretty:: pprust:: { Comments , PrintState } ;
1818use rustc_hir:: attrs:: { AttributeKind , PrintAttribute } ;
1919use rustc_hir:: {
20- BindingMode , ByRef , ConstArgKind , GenericArg , GenericBound , GenericParam , GenericParamKind ,
21- HirId , ImplicitSelfKind , LifetimeParamKind , Node , PatKind , PreciseCapturingArg , RangeEnd , Term ,
22- TyPatKind ,
20+ BindingMode , ByRef , ConstArg , ConstArgExprField , ConstArgKind , GenericArg , GenericBound ,
21+ GenericParam , GenericParamKind , HirId , ImplicitSelfKind , LifetimeParamKind , Node , PatKind ,
22+ PreciseCapturingArg , RangeEnd , Term , TyPatKind ,
2323} ;
2424use rustc_span:: source_map:: SourceMap ;
2525use rustc_span:: { FileName , Ident , Span , Symbol , kw, sym} ;
@@ -1137,16 +1137,40 @@ impl<'a> State<'a> {
11371137
11381138 fn print_const_arg ( & mut self , const_arg : & hir:: ConstArg < ' _ > ) {
11391139 match & const_arg. kind {
1140- // FIXME(mgca): proper printing for struct exprs
1141- ConstArgKind :: Struct ( ..) => self . word ( "/* STRUCT EXPR */" ) ,
1142- ConstArgKind :: TupleCall ( ..) => self . word ( "/* TUPLE CALL */" ) ,
1140+ ConstArgKind :: Struct ( qpath, fields) => self . print_const_struct ( qpath, fields) ,
1141+ ConstArgKind :: TupleCall ( qpath, args) => self . print_const_ctor ( qpath, args) ,
11431142 ConstArgKind :: Path ( qpath) => self . print_qpath ( qpath, true ) ,
11441143 ConstArgKind :: Anon ( anon) => self . print_anon_const ( anon) ,
11451144 ConstArgKind :: Error ( _, _) => self . word ( "/*ERROR*/" ) ,
11461145 ConstArgKind :: Infer ( ..) => self . word ( "_" ) ,
11471146 }
11481147 }
11491148
1149+ fn print_const_struct ( & mut self , qpath : & hir:: QPath < ' _ > , fields : & & [ & ConstArgExprField < ' _ > ] ) {
1150+ self . print_qpath ( qpath, true ) ;
1151+ self . word ( " " ) ;
1152+ self . word ( "{" ) ;
1153+ if !fields. is_empty ( ) {
1154+ self . nbsp ( ) ;
1155+ }
1156+ self . commasep ( Inconsistent , * fields, |s, field| {
1157+ s. word ( field. field . as_str ( ) . to_string ( ) ) ;
1158+ s. word ( ":" ) ;
1159+ s. nbsp ( ) ;
1160+ s. print_const_arg ( field. expr ) ;
1161+ } ) ;
1162+ self . word ( "}" ) ;
1163+ }
1164+
1165+ fn print_const_ctor ( & mut self , qpath : & hir:: QPath < ' _ > , args : & & [ & ConstArg < ' _ , ( ) > ] ) {
1166+ self . print_qpath ( qpath, true ) ;
1167+ self . word ( "(" ) ;
1168+ self . commasep ( Inconsistent , * args, |s, arg| {
1169+ s. print_const_arg ( arg) ;
1170+ } ) ;
1171+ self . word ( ")" ) ;
1172+ }
1173+
11501174 fn print_call_post ( & mut self , args : & [ hir:: Expr < ' _ > ] ) {
11511175 self . popen ( ) ;
11521176 self . commasep_exprs ( Inconsistent , args) ;
0 commit comments