-
-
Notifications
You must be signed in to change notification settings - Fork 94
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_marked_deprecated
lint
#1216
Merged
obi1kenobi
merged 4 commits into
obi1kenobi:main
from
GlitchlessCode:enum_tuple_variant_field_marked_deprecated-witness
Mar 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ac288c7
Add enum_tuple_variant_field_marked_deprecated witness
GlitchlessCode 63fa297
Merge branch 'obi1kenobi:main' into enum_tuple_variant_field_marked_d…
GlitchlessCode 0995d34
Merge branch 'obi1kenobi:main' into enum_tuple_variant_field_marked_d…
GlitchlessCode a7146ed
Swap baseline_field_names with field_count
GlitchlessCode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,6 +31,10 @@ SemverQuery( | |||||||||||||||||
public_api_eligible @filter(op: "=", value: ["$true"]) | ||||||||||||||||||
deprecated @filter(op: "!=", value: ["$true"]) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
field @fold { | ||||||||||||||||||
baseline_field_names: name @output | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
@@ -79,4 +83,10 @@ SemverQuery( | |||||||||||||||||
}, | ||||||||||||||||||
error_message: "A field in an enum's tuple variant is now #[deprecated]. Downstream crates will get a compiler warning when accessing this field.", | ||||||||||||||||||
per_result_error_template: Some("field {{enum_name}}::{{variant_name}}.{{field_name}} in {{span_filename}}:{{span_begin_line}}"), | ||||||||||||||||||
witness: ( | ||||||||||||||||||
hint_template: r#"match value { | ||||||||||||||||||
{{ join "::" path }}::{{ variant_name }} ({{#each baseline_field_names }}{{#if (eq this ../field_name)}}to_be_deprecated{{else}}_{{/if}}{{#unless @last }}, {{/unless}}{{/each}}) => (), | ||||||||||||||||||
_ => (), | ||||||||||||||||||
}"#, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent use of templating, well done! Adding my suggestion to name the deprecated field
Suggested change
|
||||||||||||||||||
), | ||||||||||||||||||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test_outputs/witnesses/enum_tuple_variant_field_marked_deprecated.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
source: src/query.rs | ||
description: "Lint `enum_tuple_variant_field_marked_deprecated` did not have the expected witness output.\nSee https://github.com/obi1kenobi/cargo-semver-checks/blob/main/CONTRIBUTING.md#testing-witnesses\nfor more information." | ||
expression: "&actual_witnesses" | ||
snapshot_kind: text | ||
--- | ||
[["./test_crates/enum_struct_variant_field_marked_deprecated/"]] | ||
filename = 'src/lib.rs' | ||
begin_line = 19 | ||
hint = ''' | ||
match value { | ||
enum_struct_variant_field_marked_deprecated::NormalEnum::TupleVariant (to_be_deprecated, _) => (), | ||
_ => (), | ||
}''' | ||
|
||
[["./test_crates/enum_tuple_variant_field_marked_deprecated/"]] | ||
filename = 'src/lib.rs' | ||
begin_line = 7 | ||
hint = ''' | ||
match value { | ||
enum_tuple_variant_field_marked_deprecated::TupleVariantEnum::TupleVariant (to_be_deprecated, _, _) => (), | ||
_ => (), | ||
}''' | ||
|
||
[["./test_crates/enum_tuple_variant_field_marked_deprecated/"]] | ||
filename = 'src/lib.rs' | ||
begin_line = 8 | ||
hint = ''' | ||
match value { | ||
enum_tuple_variant_field_marked_deprecated::TupleVariantEnum::TupleVariant (_, to_be_deprecated, _) => (), | ||
_ => (), | ||
}''' | ||
|
||
[["./test_crates/enum_tuple_variant_field_marked_deprecated/"]] | ||
filename = 'src/lib.rs' | ||
begin_line = 13 | ||
hint = ''' | ||
match value { | ||
enum_tuple_variant_field_marked_deprecated::TupleVariantEnum::AnotherTuple (_, to_be_deprecated, _) => (), | ||
_ => (), | ||
}''' | ||
|
||
[["./test_crates/enum_tuple_variant_field_marked_deprecated/"]] | ||
filename = 'src/lib.rs' | ||
begin_line = 57 | ||
hint = ''' | ||
match value { | ||
enum_tuple_variant_field_marked_deprecated::EnumWithHiddenVariant::NormalTuple (to_be_deprecated, _) => (), | ||
_ => (), | ||
}''' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a tuple variant these are just always going to be
0, 1, 2, ...
since the fields are purely positional, and not otherwise named.Consider perhaps just counting the fields instead of outputting a (potentially large) number of known-consecutive numbers? It would make the query a bit more efficient and a bit more obvious.
As another idea, it might be good to mention that this info is used for the witness hint and isn't otherwise necessary for the detection of the issue itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genuinely forgot I could do this, thanks for the reminder, probably able to use this in some of the other
enum_tuple_variant_...
lints.