@@ -386,34 +386,30 @@ p_stmt' pretty = \case
386386 -- since pretty printing of relevant statements (e.g., in 'trS_stmts')
387387 -- is handled through 'gatherStmt'.
388388 case (trS_form, trS_by) of
389− (ThenForm, Nothing) -> located trS_using $ \x -> do
389+ (ThenForm, Nothing) -> do
390390 txt "then"
391391 breakpoint
392− inci (p_hsExpr x)
392+ inci $ located trS_using p_hsExpr
393393 (ThenForm, Just e) -> do
394− located trS_using $ \x -> do
395− txt "then"
396− breakpoint
397− inci (p_hsExpr x)
394+ txt "then"
398395 breakpoint
399− located e $ \x -> do
400− txt "by"
401− breakpoint
402− inci (p_hsExpr x)
403− (GroupForm, Nothing) -> located trS_using $ \x -> do
396+ inci $ located trS_using p_hsExpr
397+ breakpoint
398+ txt "by"
399+ breakpoint
400+ inci $ located e p_hsExpr
401+ (GroupForm, Nothing) -> do
404402 txt "then group using"
405403 breakpoint
406− inci (p_hsExpr x)
404+ inci $ located trS_using p_hsExpr
407405 (GroupForm, Just e) -> do
408− located e $ \x -> do
409− txt "then group by"
410− breakpoint
411− inci (p_hsExpr x)
406+ txt "then group by"
412407 breakpoint
413− located trS_using $ \x -> do
414− txt "using"
415− breakpoint
416− inci (p_hsExpr x)
408+ inci $ located e p_hsExpr
409+ breakpoint
410+ txt "using"
411+ breakpoint
412+ inci $ located trS_using p_hsExpr
417413 RecStmt {..} -> do
418414 txt "rec"
419415 space
@@ -450,7 +446,7 @@ p_hsLocalBinds = \case
450446 -- NOTE When in a single-line layout, there is a chance that the inner
451447 -- elements will also contain semicolons and they will confuse the
452448 -- parser. so we request braces around every element except the last.
453− br <- vlayout (return useBraces) (return id)
449+ br <- layoutToBraces <$> getLayout
454450 sitcc $ sepSemi
455451 (\(m, i) -> (if m then br else id) $ p_item i)
456452 (markInit $ sortOn ssStart items)
@@ -623,7 +619,7 @@ p_hsExpr' s = \case
623619 let doBody header = do
624620 txt header
625621 breakpoint
626− ub <- vlayout (return useBraces) (return id)
622+ ub <- layoutToBraces <$> getLayout
627623 inci $ sepSemi (located' (ub . p_stmt' (p_hsExpr' S))) (unLoc es)
628624 compBody = brackets N $ located es $ \xs -> do
629625 let p_parBody = sep
@@ -685,10 +681,10 @@ p_hsExpr' s = \case
685681 rupd_flds
686682 ExprWithTySig affix x -> sitcc $ do
687683 located x p_hsExpr
684+ space
685+ txt "::"
688686 breakpoint
689687 inci $ do
690− txt "::"
691− space
692688 let HsWC {..} = affix
693689 HsIB {..} = hswc_body
694690 located hsib_body p_hsType
@@ -771,23 +767,25 @@ p_hsExpr' s = \case
771767
772768p_patSynBind :: PatSynBind GhcPs GhcPs -> R ()
773769p_patSynBind PSB {..} = do
774− let rhs = case psb_dir of
775− Unidirectional -> do
776− txt "<-"
777− space
778− located psb_def p_pat
779− ImplicitBidirectional -> do
780− txt "="
781− space
782− located psb_def p_pat
783− ExplicitBidirectional mgroup -> do
784− txt "<-"
785− space
786− located psb_def p_pat
787− newline
788− txt "where"
789− newline
790− inci (p_matchGroup (Function psb_id) mgroup)
770+ let rhs = do
771+ space
772+ case psb_dir of
773+ Unidirectional -> do
774+ txt "<-"
775+ breakpoint
776+ located psb_def p_pat
777+ ImplicitBidirectional -> do
778+ txt "="
779+ breakpoint
780+ located psb_def p_pat
781+ ExplicitBidirectional mgroup -> do
782+ txt "<-"
783+ breakpoint
784+ located psb_def p_pat
785+ newline
786+ txt "where"
787+ newline
788+ inci (p_matchGroup (Function psb_id) mgroup)
791789 txt "pattern"
792790 case psb_args of
793791 PrefixCon xs -> do
@@ -797,7 +795,6 @@ p_patSynBind PSB {..} = do
797795 switchLayout (getLoc <$> xs) $ do
798796 unless (null xs) breakpoint
799797 sitcc (sep breakpoint p_rdrName xs)
800− breakpoint
801798 rhs
802799 RecCon xs -> do
803800 space
@@ -807,7 +804,6 @@ p_patSynBind PSB {..} = do
807804 unless (null xs) breakpoint
808805 braces N . sitcc $
809806 sep (comma >> breakpoint) (p_rdrName . recordPatSynPatVar) xs
810− breakpoint
811807 rhs
812808 InfixCon l r -> do
813809 switchLayout [getLoc l, getLoc r] $ do
@@ -818,9 +814,7 @@ p_patSynBind PSB {..} = do
818814 p_rdrName psb_id
819815 space
820816 p_rdrName r
821− inci $ do
822− breakpoint
823− rhs
817+ inci rhs
824818p_patSynBind (XPatSynBind NoExt) = notImplemented "XPatSynBind"
825819
826820p_pat :: Pat GhcPs -> R ()
@@ -1051,6 +1045,14 @@ p_stringLit src =
10511045----------------------------------------------------------------------------
10521046-- Helpers
10531047
1048+-- | Return the wrapping function controlling the use of braces according to
1049+-- the current layout.
1050+
1051+layoutToBraces :: Layout -> R () -> R ()
1052+layoutToBraces = \case
1053+ SingleLine -> useBraces
1054+ MultiLine -> id
1055+
10541056-- | Append each element in both lists with semigroups. If one list is shorter
10551057-- than the other, return the rest of the longer list unchanged.
10561058
@@ -1159,11 +1161,12 @@ p_exprOpTree s (OpBranch x op y) = do
11591161 opWrapper = case unLoc op of
11601162 EWildPat NoExt -> backticks
11611163 _ -> id
1162− ub <- vlayout
1163− (return useBraces)
1164− (return $ case placement of
1165− Hanging -> useBraces
1166− Normal -> dontUseBraces)
1164+ layout <- getLayout
1165+ let ub = case layout of
1166+ SingleLine -> useBraces
1167+ MultiLine -> case placement of
1168+ Hanging -> useBraces
1169+ Normal -> dontUseBraces
11671170 switchLayout [opTreeLoc x] $
11681171 ub $ p_exprOpTree s x
11691172 placeHanging placement $ do