-
-
Notifications
You must be signed in to change notification settings - Fork 130
Add lint inherent_associated_pub_const_missing #714
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d1ba5a7
Added lint inherent_associated_pub_const_missing
arpity22 37702f4
fixes
arpity22 9ba6760
Modifications
arpity22 0c677cc
Modifications
arpity22 79adc6d
Merge branch 'obi1kenobi:main' into main
arpity22 6ff5d23
Adding new test cases
arpity22 bd81dc1
editing test output
arpity22 99b523d
Merge branch 'obi1kenobi:main' into main
arpity22 3995496
Adding new test cases
arpity22 8042812
Adding new test cases
arpity22 938db7d
Update src/lints/inherent_associated_pub_const_missing.ron
arpity22 ea1f008
adding test case
arpity22 f11a39f
Merge branch 'main' into main
arpity22 76b2b57
Merge branch 'obi1kenobi:main' into main
arpity22 90c3172
adding test case
arpity22 49eb155
Merge branch 'main' of github.com:arpity22/cargo-semver-checks
arpity22 4cf6944
Update src/lints/inherent_associated_pub_const_missing.ron
arpity22 4081a40
Merge branch 'main' into main
arpity22 c4062cf
Merge branch 'main' into main
obi1kenobi 11c7098
Merge branch 'main' into main
obi1kenobi afb330a
Query Modifications
arpity22 60b2ed3
Formatting
arpity22 353d8a8
Merge branch 'main' into main
arpity22 c42b06c
Apply suggestions from code review
obi1kenobi 7da4ce5
Merge branch 'main' into main
obi1kenobi 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 hidden or 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,74 @@ | ||
| SemverQuery( | ||
| id: "inherent_associated_pub_const_missing", | ||
| human_readable_name: "inherent impl's associated pub const removed", | ||
| description: "An inherent impl's associated public const removed or renamed", | ||
| required_update: Major, | ||
| reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#item-remove"), | ||
| query: r#" | ||
| { | ||
| CrateDiff { | ||
| baseline { | ||
| item { | ||
| ... on ImplOwner { | ||
| visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
|
|
||
| importable_path { | ||
| path @output @tag | ||
| public_api @filter(op: "=", value: ["$true"]) | ||
| } | ||
|
|
||
| inherent_impl { | ||
| public_api_eligible @filter(op: "=", value: ["$true"]) | ||
|
|
||
| associated_constant { | ||
| associated_constant: name @output @tag | ||
| public_api_eligible @filter(op: "=", value: ["$true"]) | ||
|
|
||
| span_: span @optional { | ||
| filename @output | ||
| begin_line @output | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| current { | ||
| item { | ||
| ... on ImplOwner { | ||
| visibility_limit @filter(op: "=", value: ["$public"]) | ||
| name @output | ||
|
|
||
| importable_path { | ||
| path @filter(op: "=", value: ["%path"]) | ||
| public_api @filter(op: "=", value: ["$true"]) | ||
| } | ||
|
|
||
| inherent_impl @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
| associated_constant { | ||
| name @filter(op: "=", value: ["%associated_constant"]) | ||
| } | ||
| } | ||
|
|
||
| impl @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
| implemented_trait { | ||
| trait { | ||
| associated_constant { | ||
| name @filter(op: "=", value: ["%associated_constant"]) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }"#, | ||
| arguments: { | ||
| "public": "public", | ||
| "true": true, | ||
| "zero": 0, | ||
| }, | ||
| error_message: "An inherent impl's associated public constant is removed or renamed", | ||
| per_result_error_template: Some("{{name}}::{{associated_constant}}, previously at {{span_filename}}:{{span_begin_line}}"), | ||
| ) | ||
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
test_crates/inherent_associated_pub_const_missing/new/Cargo.toml
This file contains hidden or 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,7 @@ | ||
| [package] | ||
| publish = false | ||
| name = "inherent_associated_pub_const_missing" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] |
76 changes: 76 additions & 0 deletions
76
test_crates/inherent_associated_pub_const_missing/new/src/lib.rs
This file contains hidden or 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,76 @@ | ||
| // Test Cases where #[doc(hidden)] is neither added or removed | ||
| pub struct StructA {} | ||
|
|
||
| impl StructA { | ||
| pub const PublicConstantB: i32 = 0; | ||
| // Should Be caught on renaming | ||
| pub const PublicConstantRenamedA: i32 = 0; | ||
| } | ||
|
|
||
| struct StructB {} | ||
|
|
||
| impl StructB { | ||
| // Should not be caught since StructB is not pub | ||
| pub const PublicConstantRenamedB: i32 = 0; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| pub struct StructC {} | ||
|
|
||
| impl StructC { | ||
| // Should not be caught on removing or renaming since the struct is #[doc(hidden)] | ||
| pub const PublicConstantRenamedC: i32 = 0; | ||
| } | ||
|
|
||
| pub struct StructD {} | ||
|
|
||
| #[doc(hidden)] | ||
| impl StructD { | ||
| pub const PublicConstantE: i32 = 0; | ||
| } | ||
|
|
||
| // Test Cases where #[doc(hidden)] is added | ||
| pub struct StructE {} | ||
|
|
||
| #[doc(hidden)] | ||
| impl StructE { | ||
| pub const PublicConstantH: i32 = 0; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| pub struct StructF {} | ||
|
|
||
| impl StructF { | ||
| pub const PublicConstantJ: i32 = 0; | ||
| } | ||
|
|
||
| // Test cases where #[doc(hidden)] is removed | ||
| pub struct DocHiddenStruct {} | ||
|
|
||
| impl DocHiddenStruct { | ||
| pub const PublicConstantL: i32 = 0; | ||
| } | ||
|
|
||
| impl DocHiddenStruct { | ||
| pub const PublicConstantO: i32 = 0; | ||
| } | ||
|
|
||
| // Test for when an inherent const is implemented as trait's const | ||
| pub trait TraitA { | ||
| const N_A: i64 = 0; | ||
| } | ||
|
|
||
| pub struct ExampleA; | ||
|
|
||
| impl TraitA for ExampleA {} | ||
|
|
||
| // Test for when an inherent const is implemented as trait's const but given a value in impl block | ||
| pub trait TraitB { | ||
| const N_B: i64; | ||
| } | ||
|
|
||
| pub struct ExampleB; | ||
|
|
||
| impl TraitB for ExampleB { | ||
| const N_B: i64 = 0; | ||
| } |
7 changes: 7 additions & 0 deletions
7
test_crates/inherent_associated_pub_const_missing/old/Cargo.toml
This file contains hidden or 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,7 @@ | ||
| [package] | ||
| publish = false | ||
| name = "inherent_associated_pub_const_missing" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [dependencies] |
104 changes: 104 additions & 0 deletions
104
test_crates/inherent_associated_pub_const_missing/old/src/lib.rs
This file contains hidden or 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,104 @@ | ||
| // Test Cases where #[doc(hidden)] is neither added or removed | ||
| pub struct StructA {} | ||
|
|
||
| impl StructA { | ||
| // Basic Test case should be caught | ||
| pub const PublicConstantA: i32 = 0; | ||
| pub const PublicConstantB: i32 = 0; | ||
| // Const that was #[doc(hidden)] will be removed | ||
| #[doc(hidden)] | ||
| pub const DocHiddenConstantA: i32 = 0; | ||
| // Should Be caught on renaming | ||
| pub const PublicConstantRenameA: i32 = 0; | ||
| // Should not be caught on removing since its not pub | ||
| const ConstantA: i32 = 0; | ||
| } | ||
|
|
||
| struct StructB {} | ||
|
|
||
| impl StructB { | ||
| // Should not be caught since StructB is not pub | ||
| pub const PublicConstantC: i32 = 0; | ||
| pub const PublicConstantRenameB: i32 = 0; | ||
| const ConstantB: i32 = 0; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| pub struct StructC {} | ||
|
|
||
| impl StructC { | ||
| // Should not be caught on removing or renaming since the struct #[doc(hidden)] | ||
| pub const PublicConstantD: i32 = 0; | ||
| pub const PublicConstantRenameC: i32 = 0; | ||
| } | ||
|
|
||
| pub struct StructD {} | ||
|
obi1kenobi marked this conversation as resolved.
|
||
|
|
||
| // The constants in this block shouldn't be flagged as removed, | ||
| // since they are `#[doc(hidden)]` as a result of the block itself. | ||
| #[doc(hidden)] | ||
| impl StructD { | ||
| pub const PublicConstantE: i32 = 0; | ||
| pub const PublicConstantF: i32 = 0; | ||
| } | ||
|
obi1kenobi marked this conversation as resolved.
|
||
|
|
||
| // Test Cases where #[doc(hidden)] is added | ||
| pub struct StructE {} | ||
|
|
||
| // This impl block will be #[doc(hidden)] | ||
| impl StructE { | ||
| pub const PublicConstantH: i32 = 0; | ||
| // This will be removed | ||
| pub const PublicConstantI: i32 = 0; | ||
| } | ||
|
|
||
| // This struct will be #[doc(hidden)] | ||
| pub struct StructF {} | ||
|
|
||
| impl StructF { | ||
| pub const PublicConstantJ: i32 = 0; | ||
| // This const will be removed | ||
| pub const PublicConstantK: i32 = 0; | ||
| } | ||
|
|
||
| // Test cases where #[doc(hidden)] is removed | ||
| #[doc(hidden)] | ||
| pub struct DocHiddenStruct {} | ||
|
|
||
| impl DocHiddenStruct { | ||
| // This const will be removed | ||
| #[doc(hidden)] | ||
| pub const DocHiddenConstantB: i32 = 0; | ||
| pub const PublicConstantL: i32 = 0; | ||
| // This const will be removed | ||
| pub const PublicConstantM: i32 = 0; | ||
| } | ||
|
|
||
| #[doc(hidden)] | ||
| impl DocHiddenStruct { | ||
| // This const will be removed | ||
| pub const PublicConstantN: i32 = 0; | ||
| pub const PublicConstantO: i32 = 0; | ||
| } | ||
|
|
||
| // Test for when an inherent const is implemented as trait's const | ||
| pub trait TraitA {} | ||
|
|
||
| pub struct ExampleA; | ||
|
|
||
| impl ExampleA { | ||
| pub const N_A: i64 = 0; | ||
| } | ||
|
|
||
| impl TraitA for ExampleA {} | ||
|
|
||
| // Test for when an inherent const is implemented as trait's const but given a value in impl | ||
| pub trait TraitB {} | ||
|
|
||
| pub struct ExampleB; | ||
|
|
||
| impl ExampleB { | ||
| pub const N_B: i64 = 0; | ||
| } | ||
|
|
||
| impl TraitB for ExampleB {} | ||
37 changes: 37 additions & 0 deletions
37
test_outputs/inherent_associated_pub_const_missing.output.ron
This file contains hidden or 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,37 @@ | ||
| { | ||
| "./test_crates/inherent_associated_pub_const_missing/": [ | ||
| { | ||
| "associated_constant": String("PublicConstantA"), | ||
| "name": String("StructA"), | ||
| "path": List([ | ||
| String("inherent_associated_pub_const_missing"), | ||
| String("StructA"), | ||
| ]), | ||
| "span_begin_line": Uint64(6), | ||
| "span_filename": String("src/lib.rs"), | ||
| "visibility_limit": String("public"), | ||
| }, | ||
| { | ||
| "associated_constant": String("PublicConstantRenameA"), | ||
| "name": String("StructA"), | ||
| "path": List([ | ||
| String("inherent_associated_pub_const_missing"), | ||
| String("StructA"), | ||
| ]), | ||
| "span_begin_line": Uint64(12), | ||
| "span_filename": String("src/lib.rs"), | ||
| "visibility_limit": String("public"), | ||
| }, | ||
| { | ||
| "associated_constant": String("PublicConstantI"), | ||
| "name": String("StructE"), | ||
| "path": List([ | ||
| String("inherent_associated_pub_const_missing"), | ||
| String("StructE"), | ||
| ]), | ||
| "span_begin_line": Uint64(52), | ||
| "span_filename": String("src/lib.rs"), | ||
| "visibility_limit": String("public"), | ||
| }, | ||
| ], | ||
| } |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.