diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index 3cb2a03f8f..8cb34c1089 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -428,7 +428,7 @@ pub fn to_type2<'a>( Type2::Record(field_types, ext_type) } TagUnion { tags, ext, .. } => { - let tag_types_vec = can_tags(env, scope, references, tags, region); + let tag_types_vec = can_tags(env, scope, references, tags.items, region); let tag_types = PoolVec::with_capacity(tag_types_vec.len() as u32, env.pool); diff --git a/compiler/can/src/annotation.rs b/compiler/can/src/annotation.rs index 17e0441542..a649bb850c 100644 --- a/compiler/can/src/annotation.rs +++ b/compiler/can/src/annotation.rs @@ -417,7 +417,7 @@ fn can_annotation_help( TagUnion { tags, ext, .. } => { let tag_types = can_tags( env, - tags, + tags.items, region, scope, var_store, diff --git a/compiler/fmt/src/annotation.rs b/compiler/fmt/src/annotation.rs index 4e73d91b7e..41170c7f48 100644 --- a/compiler/fmt/src/annotation.rs +++ b/compiler/fmt/src/annotation.rs @@ -1,6 +1,6 @@ use crate::spaces::{fmt_comments_only, fmt_spaces, newline, NewlineAt, INDENT}; use bumpalo::collections::String; -use roc_parse::ast::{AssignedField, Collection, Expr, Tag, TypeAnnotation}; +use roc_parse::ast::{AssignedField, Expr, Tag, TypeAnnotation}; use roc_region::all::Located; /// Does an AST node need parens around it? @@ -81,9 +81,9 @@ where } macro_rules! format_sequence { - ($buf: expr, $indent:expr, $start:expr, $end:expr, $items:expr, $final_comments:expr, $newline:expr, $t:ident) => { - let is_multiline = - $items.iter().any(|item| item.value.is_multiline()) || !$final_comments.is_empty(); + ($buf: expr, $indent:expr, $start:expr, $end:expr, $items:expr, $newline:expr, $t:ident) => { + let is_multiline = $items.iter().any(|item| item.value.is_multiline()) + || !$items.final_comments.is_empty(); if is_multiline { let braces_indent = $indent + INDENT; @@ -138,7 +138,12 @@ macro_rules! format_sequence { } } } - fmt_comments_only($buf, $final_comments.iter(), NewlineAt::Top, item_indent); + fmt_comments_only( + $buf, + $items.final_comments.iter(), + NewlineAt::Top, + item_indent, + ); newline($buf, braces_indent); $buf.push($end); } else { @@ -192,11 +197,7 @@ impl<'a> Formattable<'a> for TypeAnnotation<'a> { fields.items.iter().any(|field| field.value.is_multiline()) } - TagUnion { - tags, - ext, - final_comments: _, - } => { + TagUnion { tags, ext } => { match ext { Some(ann) if ann.value.is_multiline() => return true, _ => {} @@ -279,36 +280,16 @@ impl<'a> Formattable<'a> for TypeAnnotation<'a> { BoundVariable(v) => buf.push_str(v), Wildcard => buf.push('*'), - TagUnion { - tags, - ext, - final_comments, - } => { - format_sequence!(buf, indent, '[', ']', tags, final_comments, newlines, Tag); + TagUnion { tags, ext } => { + format_sequence!(buf, indent, '[', ']', tags, newlines, Tag); if let Some(loc_ext_ann) = *ext { loc_ext_ann.value.format(buf, indent); } } - Record { - fields: - Collection { - items, - final_comments, - }, - ext, - } => { - format_sequence!( - buf, - indent, - '{', - '}', - items, - final_comments, - newlines, - AssignedField - ); + Record { fields, ext } => { + format_sequence!(buf, indent, '{', '}', fields, newlines, AssignedField); if let Some(loc_ext_ann) = *ext { loc_ext_ann.value.format(buf, indent); diff --git a/compiler/load/src/docs.rs b/compiler/load/src/docs.rs index 0cbc74ea83..edadfbcd5b 100644 --- a/compiler/load/src/docs.rs +++ b/compiler/load/src/docs.rs @@ -235,16 +235,12 @@ fn generate_entry_doc<'a>( fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) -> TypeAnnotation { match type_annotation { - ast::TypeAnnotation::TagUnion { - tags, - ext, - final_comments: _, - } => { + ast::TypeAnnotation::TagUnion { tags, ext } => { let mut tags_to_render: Vec = Vec::new(); let mut any_tags_are_private = false; - for tag in tags { + for tag in tags.iter() { match tag_to_doc(in_func_type_ann, tag.value) { None => { any_tags_are_private = true; diff --git a/compiler/parse/src/ast.rs b/compiler/parse/src/ast.rs index d9661f2f37..797c360018 100644 --- a/compiler/parse/src/ast.rs +++ b/compiler/parse/src/ast.rs @@ -266,11 +266,10 @@ pub enum TypeAnnotation<'a> { /// A tag union, e.g. `[ TagUnion { - tags: &'a [Loc>], /// The row type variable in an open tag union, e.g. the `a` in `[ Foo, Bar ]a`. /// This is None if it's a closed tag union like `[ Foo, Bar]`. ext: Option<&'a Loc>>, - final_comments: &'a [CommentOrNewline<'a>], + tags: Collection<'a, Loc>>, }, /// The `*` type variable, e.g. in (List *) diff --git a/compiler/parse/src/type_annotation.rs b/compiler/parse/src/type_annotation.rs index 40628eb622..29065c5ed6 100644 --- a/compiler/parse/src/type_annotation.rs +++ b/compiler/parse/src/type_annotation.rs @@ -40,11 +40,7 @@ fn tag_union_type<'a>(min_indent: u16) -> impl Parser<'a, TypeAnnotation<'a>, ET ))) .parse(arena, state)?; - let result = TypeAnnotation::TagUnion { - tags: tags.items, - ext, - final_comments: tags.final_comments, - }; + let result = TypeAnnotation::TagUnion { tags, ext }; Ok((MadeProgress, result, state)) }