@@ -1533,8 +1533,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15331533 print_ty : bool ,
15341534 ) -> Result < ( ) , PrintError > {
15351535 define_scoped_cx ! ( self ) ;
1536- match expr {
1537- Expr :: Binop ( op, c1, c2) => {
1536+ match expr. kind {
1537+ ty:: ExprKind :: Binop ( op) => {
1538+ let ( _, _, c1, c2) = expr. binop_args ( ) ;
1539+
15381540 let precedence = |binop : rustc_middle:: mir:: BinOp | {
15391541 use rustc_ast:: util:: parser:: AssocOp ;
15401542 AssocOp :: from_ast_binop ( binop. to_hir_binop ( ) . into ( ) ) . precedence ( )
@@ -1543,22 +1545,26 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15431545 let formatted_op = op. to_hir_binop ( ) . as_str ( ) ;
15441546 let ( lhs_parenthesized, rhs_parenthesized) = match ( c1. kind ( ) , c2. kind ( ) ) {
15451547 (
1546- ty:: ConstKind :: Expr ( Expr :: Binop ( lhs_op, _ , _ ) ) ,
1547- ty:: ConstKind :: Expr ( Expr :: Binop ( rhs_op, _ , _ ) ) ,
1548+ ty:: ConstKind :: Expr ( ty :: Expr { kind : ty :: ExprKind :: Binop ( lhs_op) , .. } ) ,
1549+ ty:: ConstKind :: Expr ( ty :: Expr { kind : ty :: ExprKind :: Binop ( rhs_op) , .. } ) ,
15481550 ) => ( precedence ( lhs_op) < op_precedence, precedence ( rhs_op) < op_precedence) ,
1549- ( ty:: ConstKind :: Expr ( Expr :: Binop ( lhs_op, ..) ) , ty:: ConstKind :: Expr ( _) ) => {
1550- ( precedence ( lhs_op) < op_precedence, true )
1551- }
1552- ( ty:: ConstKind :: Expr ( _) , ty:: ConstKind :: Expr ( Expr :: Binop ( rhs_op, ..) ) ) => {
1553- ( true , precedence ( rhs_op) < op_precedence)
1554- }
1551+ (
1552+ ty:: ConstKind :: Expr ( ty:: Expr { kind : ty:: ExprKind :: Binop ( lhs_op) , .. } ) ,
1553+ ty:: ConstKind :: Expr ( _) ,
1554+ ) => ( precedence ( lhs_op) < op_precedence, true ) ,
1555+ (
1556+ ty:: ConstKind :: Expr ( _) ,
1557+ ty:: ConstKind :: Expr ( ty:: Expr { kind : ty:: ExprKind :: Binop ( rhs_op) , .. } ) ,
1558+ ) => ( true , precedence ( rhs_op) < op_precedence) ,
15551559 ( ty:: ConstKind :: Expr ( _) , ty:: ConstKind :: Expr ( _) ) => ( true , true ) ,
1556- ( ty:: ConstKind :: Expr ( Expr :: Binop ( lhs_op, ..) ) , _) => {
1557- ( precedence ( lhs_op) < op_precedence, false )
1558- }
1559- ( _, ty:: ConstKind :: Expr ( Expr :: Binop ( rhs_op, ..) ) ) => {
1560- ( false , precedence ( rhs_op) < op_precedence)
1561- }
1560+ (
1561+ ty:: ConstKind :: Expr ( ty:: Expr { kind : ty:: ExprKind :: Binop ( lhs_op) , .. } ) ,
1562+ _,
1563+ ) => ( precedence ( lhs_op) < op_precedence, false ) ,
1564+ (
1565+ _,
1566+ ty:: ConstKind :: Expr ( ty:: Expr { kind : ty:: ExprKind :: Binop ( rhs_op) , .. } ) ,
1567+ ) => ( false , precedence ( rhs_op) < op_precedence) ,
15621568 ( ty:: ConstKind :: Expr ( _) , _) => ( true , false ) ,
15631569 ( _, ty:: ConstKind :: Expr ( _) ) => ( false , true ) ,
15641570 _ => ( false , false ) ,
@@ -1574,7 +1580,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15741580 rhs_parenthesized,
15751581 ) ?;
15761582 }
1577- Expr :: UnOp ( op, ct) => {
1583+ ty:: ExprKind :: UnOp ( op) => {
1584+ let ( _, ct) = expr. unop_args ( ) ;
1585+
15781586 use rustc_middle:: mir:: UnOp ;
15791587 let formatted_op = match op {
15801588 UnOp :: Not => "!" ,
@@ -1583,7 +1591,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15831591 } ;
15841592 let parenthesized = match ct. kind ( ) {
15851593 _ if op == UnOp :: PtrMetadata => true ,
1586- ty:: ConstKind :: Expr ( Expr :: UnOp ( c_op, ..) ) => c_op != op,
1594+ ty:: ConstKind :: Expr ( ty:: Expr { kind : ty:: ExprKind :: UnOp ( c_op) , .. } ) => {
1595+ c_op != op
1596+ }
15871597 ty:: ConstKind :: Expr ( _) => true ,
15881598 _ => false ,
15891599 } ;
@@ -1593,61 +1603,37 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15931603 parenthesized,
15941604 ) ?
15951605 }
1596- Expr :: FunctionCall ( fn_def, fn_args) => {
1597- use ty:: TyKind ;
1598- match fn_def. ty ( ) . kind ( ) {
1599- TyKind :: FnDef ( def_id, gen_args) => {
1600- p ! ( print_value_path( * def_id, gen_args) , "(" ) ;
1601- if print_ty {
1602- let tcx = self . tcx ( ) ;
1603- let sig = tcx. fn_sig ( def_id) . instantiate ( tcx, gen_args) . skip_binder ( ) ;
1604-
1605- let mut args_with_ty = fn_args. iter ( ) . map ( |ct| ( ct, ct. ty ( ) ) ) ;
1606- let output_ty = sig. output ( ) ;
1607-
1608- if let Some ( ( ct, ty) ) = args_with_ty. next ( ) {
1609- self . typed_value (
1610- |this| this. pretty_print_const ( ct, print_ty) ,
1611- |this| this. pretty_print_type ( ty) ,
1612- ": " ,
1613- ) ?;
1614- for ( ct, ty) in args_with_ty {
1615- p ! ( ", " ) ;
1616- self . typed_value (
1617- |this| this. pretty_print_const ( ct, print_ty) ,
1618- |this| this. pretty_print_type ( ty) ,
1619- ": " ,
1620- ) ?;
1621- }
1622- }
1623- p ! ( write( ") -> {output_ty}" ) ) ;
1624- } else {
1625- p ! ( comma_sep( fn_args. iter( ) ) , ")" ) ;
1626- }
1627- }
1628- _ => bug ! ( "unexpected type of fn def" ) ,
1629- }
1606+ ty:: ExprKind :: FunctionCall => {
1607+ let ( _, fn_def, fn_args) = expr. call_args ( ) ;
1608+
1609+ write ! ( self , "(" ) ?;
1610+ self . pretty_print_const ( fn_def, print_ty) ?;
1611+ p ! ( ")(" , comma_sep( fn_args) , ")" ) ;
16301612 }
1631- Expr :: Cast ( kind, ct, ty) => {
1613+ ty:: ExprKind :: Cast ( kind) => {
1614+ let ( _, value, to_ty) = expr. cast_args ( ) ;
1615+
16321616 use ty:: abstract_const:: CastKind ;
16331617 if kind == CastKind :: As || ( kind == CastKind :: Use && self . should_print_verbose ( ) ) {
1634- let parenthesized = match ct. kind ( ) {
1635- ty:: ConstKind :: Expr ( Expr :: Cast ( _, _, _) ) => false ,
1618+ let parenthesized = match value. kind ( ) {
1619+ ty:: ConstKind :: Expr ( ty:: Expr {
1620+ kind : ty:: ExprKind :: Cast { .. } , ..
1621+ } ) => false ,
16361622 ty:: ConstKind :: Expr ( _) => true ,
16371623 _ => false ,
16381624 } ;
16391625 self . maybe_parenthesized (
16401626 |this| {
16411627 this. typed_value (
1642- |this| this. pretty_print_const ( ct , print_ty) ,
1643- |this| this. pretty_print_type ( ty ) ,
1628+ |this| this. pretty_print_const ( value , print_ty) ,
1629+ |this| this. pretty_print_type ( to_ty ) ,
16441630 " as " ,
16451631 )
16461632 } ,
16471633 parenthesized,
16481634 ) ?;
16491635 } else {
1650- self . pretty_print_const ( ct , print_ty) ?
1636+ self . pretty_print_const ( value , print_ty) ?
16511637 }
16521638 }
16531639 }
0 commit comments