@@ -144,20 +144,6 @@ impl Printer for LeanPrinter {
144144 fn resugaring_phases ( ) -> Vec < Box < dyn Resugaring > > {
145145 vec ! [
146146 Box :: new( RecursiveFunctions ) ,
147- Box :: new( BinOp :: new( & [
148- binops:: add,
149- binops:: sub,
150- binops:: mul,
151- binops:: rem,
152- binops:: div,
153- binops:: shr,
154- binops:: shl,
155- binops:: bitand,
156- binops:: bitxor,
157- binops:: logical_op_and,
158- binops:: logical_op_or,
159- binops:: Index :: index,
160- ] ) ) ,
161147 Box :: new( FunctionsToConstants ) ,
162148 Box :: new( LetPure ) ,
163149 ]
@@ -901,6 +887,49 @@ const _: () = {
901887 ( [ arg] , [ ] , ExprKind :: GlobalId ( binops:: neg) ) => {
902888 docs ! [ "-?" , softline!( ) , arg] . parens ( )
903889 }
890+ ( [ lhs, rhs] , [ ] , ExprKind :: GlobalId ( binops:: Index :: index) ) => {
891+ docs ! [ lhs, "[" , line_!( ) , rhs, line_!( ) , "]_?" ]
892+ . nest ( INDENT )
893+ . group ( )
894+ }
895+ // TODO: Replace this match pattern with an `if let` guard when the feature stabilizes
896+ // Tracking PR: https://github.com/rust-lang/rust/pull/141295
897+ (
898+ [ lhs, rhs] ,
899+ [ ] ,
900+ ExprKind :: GlobalId (
901+ op @ ( binops:: add
902+ | binops:: sub
903+ | binops:: mul
904+ | binops:: div
905+ | binops:: rem
906+ | binops:: shr
907+ | binops:: shl
908+ | binops:: bitand
909+ | binops:: bitxor
910+ | binops:: logical_op_and
911+ | binops:: logical_op_or) ,
912+ ) ,
913+ ) => {
914+ let symbol = match * op {
915+ binops:: add => "+?" ,
916+ binops:: sub => "-?" ,
917+ binops:: mul => "*?" ,
918+ binops:: div => "/?" ,
919+ binops:: rem => "%?" ,
920+ binops:: shr => ">>>?" ,
921+ binops:: shl => "<<<?" ,
922+ binops:: bitand => "&&&?" ,
923+ binops:: bitxor => "^^^?" ,
924+ binops:: logical_op_and => "&&?" ,
925+ binops:: logical_op_or => "||?" ,
926+ _ => unreachable ! ( ) ,
927+ } ;
928+ docs ! [ lhs, line!( ) , docs![ symbol, softline!( ) , rhs] . group( ) ]
929+ . group ( )
930+ . nest ( INDENT )
931+ . parens ( )
932+ }
904933 _ => {
905934 // Fallback for any application
906935 docs ! [
@@ -1015,33 +1044,6 @@ const _: () = {
10151044 . group ( )
10161045 . nest ( INDENT ) ,
10171046
1018- ExprKind :: Resugared ( ResugaredExprKind :: BinOp { op, lhs, rhs, .. } ) => {
1019- // TODO : refactor this, moving this code directly in the `App` node (see
1020- // https://github.com/cryspen/hax/issues/1705)
1021- if * op == binops:: Index :: index {
1022- return docs ! [ lhs, "[" , line_!( ) , rhs, line_!( ) , "]_?" ]
1023- . nest ( INDENT )
1024- . group ( ) ;
1025- }
1026- let symbol = match * op {
1027- binops:: add => "+?" ,
1028- binops:: sub => "-?" ,
1029- binops:: mul => "*?" ,
1030- binops:: div => "/?" ,
1031- binops:: rem => "%?" ,
1032- binops:: shr => ">>>?" ,
1033- binops:: shl => "<<<?" ,
1034- binops:: bitand => "&&&?" ,
1035- binops:: bitxor => "^^^?" ,
1036- binops:: logical_op_and => "&&?" ,
1037- binops:: logical_op_or => "||?" ,
1038- _ => unreachable ! ( ) ,
1039- } ;
1040- docs ! [ lhs, line!( ) , docs![ symbol, softline!( ) , rhs] . group( ) ]
1041- . group ( )
1042- . nest ( INDENT )
1043- . parens ( )
1044- }
10451047 ExprKind :: Resugared ( ResugaredExprKind :: Tuple { .. } ) => {
10461048 unreachable ! ( "This printer doesn't use the tuple resugaring" )
10471049 }
0 commit comments