From 3a7265baed591927be7c20a7a1818fec8823d49c Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Thu, 19 Dec 2024 12:04:43 -0500 Subject: [PATCH] More impls for to_node --- crates/compiler/fmt/src/annotation.rs | 12 ++++++++++++ crates/compiler/parse/src/ast.rs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/crates/compiler/fmt/src/annotation.rs b/crates/compiler/fmt/src/annotation.rs index b82375f130..3fc2f06801 100644 --- a/crates/compiler/fmt/src/annotation.rs +++ b/crates/compiler/fmt/src/annotation.rs @@ -1410,6 +1410,18 @@ impl<'a> Nodify<'a> for TypeAnnotation<'a> { item } } + TypeAnnotation::BoundVariable(text) => { + let item = Spaces::item(Node::Literal(text)); + + if *text == "implements" { + parens_around_node(arena, item) + } else { + item + } + } + TypeAnnotation::Inferred => Spaces::item(Node::Literal("_")), + TypeAnnotation::Wildcard => Spaces::item(Node::Literal("*")), + TypeAnnotation::Malformed(text) => Spaces::item(Node::Literal(text)), _ => { let lifted = ann_lift_spaces(arena, self); Spaces { diff --git a/crates/compiler/parse/src/ast.rs b/crates/compiler/parse/src/ast.rs index 03c2e012e1..501fcff1ff 100644 --- a/crates/compiler/parse/src/ast.rs +++ b/crates/compiler/parse/src/ast.rs @@ -40,6 +40,16 @@ impl<'a, T: Copy> ExtractSpaces<'a> for Spaces<'a, T> { } } +impl<'a, T> Spaces<'a, T> { + pub fn item(item: T) -> Self { + Self { + before: &[], + item, + after: &[], + } + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct SpacesBefore<'a, T> { pub before: &'a [CommentOrNewline<'a>],