Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align PNC Apply Pattern with Expr #7490

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

gamebox
Copy link
Collaborator

@gamebox gamebox commented Jan 9, 2025

This doesn't actually solve #7486 but it aligns things so that it can be fixed. That issue is a little contentious and based on looking at the output and not liking what it looks like without considering the original source (that source is just completely artificial and not helpful).

I think that if #7470 gets merged with this, the fuzzer will be much more stable.

Copy link
Collaborator

@smores56 smores56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the println!, it looks good to me

crates/compiler/fmt/src/collection.rs Outdated Show resolved Hide resolved
@@ -108,6 +110,37 @@ where
}
}

pub trait FieldValue {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not immediately obvious to me what this does, maybe add a doc comment?

crates/compiler/fmt/src/annotation.rs Show resolved Hide resolved
Mapper(&'a Loc<Field>),
}

pub(crate) fn fmt_record_like<'a, 'b: 'a, Field, ToSpacesAround>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, it might be nice to use this for other types of collections like lists. I don't think we need to make any changes right now, but food for thought for the future.

@@ -1702,7 +1678,13 @@ fn fmt_when<'a>(

buf.spaces(1);

fmt_pattern(buf, &pattern.value, indent + INDENT, Parens::NotNeeded);
let lifted = pattern_lift_spaces(buf.text.bump(), &pattern.value);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a call to format lifted.after?

@@ -1715,7 +1697,11 @@ fn fmt_when<'a>(

buf.indent(indent + INDENT);
let line_indent = buf.cur_line_indent();
buf.push_str(" ->");
if buf.ends_with_space() || buf.ends_with_newline() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pro tip: you should be able to just use buf.ensure_ends_with_whitespace(), followed by buf.push_str("->")

/// Can only occur inside of a RecordDestructure
OptionalField(&'a str, &'a Loc<Expr<'a>>),
RecordDestructure(Collection<'a, Loc<AssignedField<'a, Pattern<'a>>>>),
ExprWrapped(Expr<'a>),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants