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

Chore: Add witness hint for enum_tuple_variant_field_missing lint #1214

Conversation

GlitchlessCode
Copy link
Contributor

Adds a witness hint for the enum_tuple_variant_field_missing lint.

Example

enum_tuple_variant_field_missing outputs the following witness hint for the ./test_crates/enum_tuple_variant_field_missing/ test.

match value {
    enum_tuple_variant_field_missing::PublicEnum::TupleVariantWithMissingField(_, _, destructure) => (),
    _ => (),
}

This compiles on the old version, but not on the new due to the now missing field in the tuple destructuring.

Commit Notes

  • Added witness hint for enum_tuple_variant_field_missing
  • Added new query for baseline_field_names for extra witness data

Comments

I could use some feedback on this one. I wasn't sure what to call the problem field, so I just called it destructure. Let me know if there would be a better name to call it, if anything at all. Second, in the tests there was something relating to #[doc(hidden)], which I wasn't too sure about if it was something I had to worry about or not. If someone could enlighten me on that, it would be appreciated.

+ Added witness hint for enum_tuple_variant_field_missing
+ Added new query for baseline_field_names for extra witness data
@obi1kenobi
Copy link
Owner

Ah, I reviewed the PRs in backwards order so I answered some of these questions in #1216. Sorry about that!

I'd recommend calling the field witness.

#[doc(hidden)] is a way to mark items as "not public API" even if they are pub. TL;DR: SemVer guarantees don't apply to them in that case. There's a surprising amount of nuance around the implications, and I've written about it here:

Our schema also often has good docs for tricky areas:

Overall, the PR looks great and just has the same polishing opportunities as #1216, so I'll let you do one more pass on it before merging. Thanks for putting it together!

@GlitchlessCode
Copy link
Contributor Author

GlitchlessCode commented Mar 24, 2025

Just as in #1216, destructure should become witness, and if there is a way to use @transform to count, that's preferred. I think this lint always flags the last field as the problem, so it shouldn't be too difficult to redo this. Will work on this ASAP.

Edit: just saw your message here, will address that in a moment.

obi1kenobi added a commit that referenced this pull request Mar 24, 2025
Adds a custom handlebars block helper called `repeat`. The goal of this
helper is to allow one to iterate a value `n` number of times. The
syntax of `repeat` is similar to that of the built-in `each` helper. It
assigns to the local block variables `@index`, `@first`, and `@last`.
`@index` is a number, `@first` and `@last` are booleans.

## Example
The following example handlebars template assumes the existence of an
outputted value called `field_count`, which is a `Number` type
representing the number of fields on an enum variant (for example).
```
"path_to_enum::ExampleEnum::ExampleVariant({{#repeat field_count }}_{{#unless @last }}, {{/unless}}{{/times}})"
```
This template string would produce the following output string for an
input tuple enum with 3 fields:
```
"path_to_enum::ExampleEnum::ExampleVariant(_, _, _)"
```

## Commit Notes
+ Adds a #repeat block helper, similar to the built-in #each helper

## Comments
This PR is to support the progress of #1212, #1214, and #1216. I'm
creating this because as far as I am aware, there is not currently a way
to iterate based on a Number in the existing set of handlebars helpers.
Let me know if there's any improvements I can make to this!

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
obi1kenobi added a commit that referenced this pull request Mar 25, 2025
Adds a `to_string` custom handlebars helper.

## Comments
There's not much to show for this one, it just converts a Number or Bool
to a String Value. This isn't useful most of the time, as templating
converts a variable to a string anyways. It's main use case is for
comparing a number and a string. This is currently needed in #1214 and
#1216, as although we can now iterate using the `repeat` helper, it
produces Number Values, while `field_name`, which `@index` is compared
against, is a String Value, which will always fail the `eq` test. This
helper exists to resolve that issue.

---------

Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com>
obi1kenobi pushed a commit that referenced this pull request Mar 25, 2025
…ed` lint (#1216)

Adds a witness hint for the `enum_tuple_variant_field_marked_deprecated`
lint.

## Example
`enum_tuple_variant_field_marked_deprecated` outputs the following
witness hint for one of the
`./test_crates/enum_tuple_variant_field_marked_deprecated/` tests.
```rust
match value {
    enum_tuple_variant_field_marked_deprecated::TupleVariantEnum::TupleVariant (_, to_be_deprecated, _) => (),
    _ => (),
}
```
This compiles on both versions, but demonstrates the issue with the
deprecated field, and would emit an error if compiled.

## Commit Notes
+ Added witness hint for `enum_tuple_variant_field_marked_deprecated`
+ Added new parts to query for
`enum_tuple_variant_field_marked_deprecated` to fetch relevant data for
the witness

## Comments
Once again, similar to #1214 I wasn't 100% sure on what to call the
bound variable (`to_be_deprecated`) when destructuring the tuple, but I
think this mostly works. Let me know if you think the name should get
changed!
+ Added field_count
+ Removed baseline_field_names
+ Added repeat helper
+ Removed each helper
+ Added to_string helper
+ Replaced destructure with witness
@GlitchlessCode
Copy link
Contributor Author

Really just tying up a lot of loose ends today, this one should be good to go too I think!

@obi1kenobi obi1kenobi merged commit 26fb5a5 into obi1kenobi:main Mar 25, 2025
31 of 32 checks passed
@GlitchlessCode GlitchlessCode deleted the enum_tuple_variant_field_missing-witness branch March 25, 2025 03:54
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.

2 participants