@@ -17,12 +17,11 @@ use crate::{Buf, MigrationFlags};
1717use bumpalo:: Bump ;
1818use roc_error_macros:: internal_error;
1919use roc_parse:: ast:: {
20- AbilityMember , Defs , Expr , ExtractSpaces , ImportAlias , ImportAsKeyword , ImportExposingKeyword ,
21- ImportedModuleName , IngestedFileAnnotation , IngestedFileImport , ModuleImport ,
22- ModuleImportParams , Pattern , Spaces , SpacesBefore , StrLiteral , TypeAnnotation , TypeDef ,
23- TypeHeader , ValueDef ,
20+ merge_spaces , AbilityMember , Defs , Expr , ExtractSpaces , ImportAlias , ImportAsKeyword ,
21+ ImportExposingKeyword , ImportedModuleName , IngestedFileAnnotation , IngestedFileImport ,
22+ ModuleImport , ModuleImportParams , Pattern , Spaces , SpacesBefore , StrLiteral , TypeAnnotation ,
23+ TypeDef , TypeHeader , ValueDef ,
2424} ;
25- use roc_parse:: expr:: merge_spaces;
2625use roc_parse:: header:: Keyword ;
2726use roc_region:: all:: Loc ;
2827
@@ -435,8 +434,10 @@ impl<'a> Formattable for TypeDef<'a> {
435434 typ : ann,
436435 derived : has_abilities,
437436 } => {
438- let ann_is_where_clause =
439- matches ! ( ann. extract_spaces( ) . item, TypeAnnotation :: Where ( ..) ) ;
437+ let ann_is_where_clause = matches ! (
438+ ann. extract_spaces( buf. arena) . item,
439+ TypeAnnotation :: Where ( ..)
440+ ) ;
440441
441442 // Always put the has-abilities clause on a newline if the opaque annotation
442443 // contains a where-has clause.
@@ -476,7 +477,7 @@ impl<'a> Formattable for TypeDef<'a> {
476477 } => {
477478 let header_lifted = type_head_lift_spaces ( buf. text . bump ( ) , * header) ;
478479 header_lifted. item . format ( buf, indent) ;
479- let implements = loc_implements. value . extract_spaces ( ) ;
480+ let implements = loc_implements. value . extract_spaces ( buf . arena ) ;
480481 let before_implements = merge_spaces_conservative (
481482 buf. text . bump ( ) ,
482483 header_lifted. after ,
@@ -513,7 +514,7 @@ impl<'a> Formattable for TypeDef<'a> {
513514 before,
514515 item,
515516 after,
516- } = member. name . value . extract_spaces ( ) ;
517+ } = member. name . value . extract_spaces ( buf . arena ) ;
517518 fmt_spaces ( buf, before. iter ( ) , indent + INDENT ) ;
518519 buf. ensure_ends_with_newline ( ) ;
519520
@@ -833,7 +834,7 @@ impl<'a> Formattable for ValueDef<'a> {
833834 use roc_parse:: ast:: ValueDef :: * ;
834835 match self {
835836 Annotation ( loc_pattern, loc_annotation) => {
836- let pat_parens = if ann_pattern_needs_parens ( & loc_pattern. value ) {
837+ let pat_parens = if ann_pattern_needs_parens ( buf . arena , & loc_pattern. value ) {
837838 Parens :: InApply
838839 } else {
839840 Parens :: NotNeeded
@@ -860,7 +861,7 @@ impl<'a> Formattable for ValueDef<'a> {
860861 body_pattern,
861862 body_expr,
862863 } => {
863- let pat_parens = if ann_pattern_needs_parens ( & ann_pattern. value ) {
864+ let pat_parens = if ann_pattern_needs_parens ( buf . arena , & ann_pattern. value ) {
864865 Parens :: InApply
865866 } else {
866867 Parens :: NotNeeded
@@ -888,10 +889,12 @@ impl<'a> Formattable for ValueDef<'a> {
888889 }
889890}
890891
891- fn ann_pattern_needs_parens ( value : & Pattern < ' _ > ) -> bool {
892- match value. extract_spaces ( ) . item {
892+ fn ann_pattern_needs_parens ( arena : & ' _ Bump , value : & Pattern < ' _ > ) -> bool {
893+ match value. extract_spaces ( arena ) . item {
893894 Pattern :: Tag ( _) => true ,
894- Pattern :: Apply ( func, _args) if matches ! ( func. extract_spaces( ) . item, Pattern :: Tag ( ..) ) => {
895+ Pattern :: Apply ( func, _args)
896+ if matches ! ( func. extract_spaces( arena) . item, Pattern :: Tag ( ..) ) =>
897+ {
895898 true
896899 }
897900 _ => false ,
@@ -1016,17 +1019,17 @@ pub fn fmt_body<'a>(
10161019 body : & ' a Expr < ' a > ,
10171020 indent : u16 ,
10181021) {
1019- let pattern_extracted = pattern. extract_spaces ( ) ;
1022+ let pattern_extracted = pattern. extract_spaces ( buf . arena ) ;
10201023 // Check if this is an assignment into the unit value
10211024 let is_unit_assignment = if let Pattern :: RecordDestructure ( collection) = pattern_extracted. item
10221025 {
10231026 allow_simplify_empty_record_destructure
10241027 && collection. is_empty ( )
10251028 && pattern_extracted. before . iter ( ) . all ( |s| s. is_newline ( ) )
10261029 && pattern_extracted. after . iter ( ) . all ( |s| s. is_newline ( ) )
1027- && !matches ! ( body. extract_spaces( ) . item, Expr :: Defs ( ..) )
1028- && !matches ! ( body. extract_spaces( ) . item, Expr :: Return ( ..) )
1029- && !matches ! ( body. extract_spaces( ) . item, Expr :: DbgStmt { .. } )
1030+ && !matches ! ( body. extract_spaces( buf . arena ) . item, Expr :: Defs ( ..) )
1031+ && !matches ! ( body. extract_spaces( buf . arena ) . item, Expr :: Return ( ..) )
1032+ && !matches ! ( body. extract_spaces( buf . arena ) . item, Expr :: DbgStmt { .. } )
10301033 && !starts_with_expect_ident ( body)
10311034 } else {
10321035 false
@@ -1186,7 +1189,7 @@ impl<'a> Formattable for AbilityMember<'a> {
11861189 _newlines : Newlines ,
11871190 indent : u16 ,
11881191 ) {
1189- let Spaces { before, item, .. } = self . name . value . extract_spaces ( ) ;
1192+ let Spaces { before, item, .. } = self . name . value . extract_spaces ( buf . arena ) ;
11901193 fmt_spaces ( buf, before. iter ( ) , indent) ;
11911194
11921195 buf. indent ( indent) ;
0 commit comments