-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semver check for unit structs becoming plain structs. (#3)
* Add semver check for unit structs becoming plain structs. * Fix test output format. * Ensure the reported struct was not #[non_exhaustive].
- Loading branch information
1 parent
c6b1eb5
commit dde1a79
Showing
6 changed files
with
85 additions
and
0 deletions.
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
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
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
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
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,59 @@ | ||
SemverQuery( | ||
id: "unit_struct_changed_kind", | ||
human_readable_name: "unit struct changed kind", | ||
description: "A public struct that was previously a unit struct is now a plain struct. The unit struct was not marked #[non_exhaustive], so it could be constructed outside of the defining crate. Plain structs cannot be constructed using the syntax allowed for unit structs, so this is a major breaking change for code that depends on it.", | ||
required_update: Major, | ||
|
||
// TODO: Change the reference link once this cargo docs PR merges: | ||
// https://github.com/rust-lang/cargo/pull/10871 | ||
// | ||
// Change to this link: | ||
// https://doc.rust-lang.org/cargo/reference/semver.html#struct-unit-to-normal | ||
reference_link: Some("https://github.com/rust-lang/cargo/pull/10871"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
baseline { | ||
item { | ||
... on Struct { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
name @output @tag | ||
struct_type @filter(op: "=", value: ["$unit"]) | ||
attrs @filter(op: "not_contains", value: ["$non_exhaustive"]) | ||
path { | ||
path @output @tag | ||
} | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
current @fold @transform(op: "count") @filter(op: ">=", value: ["$one"]) { | ||
item { | ||
... on Struct { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
name @filter(op: "=", value: ["%name"]) | ||
struct_type @filter(op: "=", value: ["$plain"]) | ||
path { | ||
path @filter(op: "=", value: ["%path"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"unit": "unit", | ||
"plain": "plain", | ||
"one": 1, | ||
"non_exhaustive": "#[non_exhaustive]", | ||
}, | ||
error_message: "A public unit struct has been changed to a normal (curly-braces) struct, which cannot be constructed using the same struct literal syntax.", | ||
per_result_error_template: Some("struct {{name}}, previously in file {{span_filename}}:{{span_begin_line}}"), | ||
) |
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,9 @@ | ||
[ | ||
{ | ||
"name": String("UnitStructToPlain"), | ||
"path": List([String("semver_tests"), String("test_cases"), String("UnitStructToPlain")]), | ||
"visibility_limit": String("public"), | ||
"span_filename": String("src/test_cases/mod.rs"), | ||
"span_begin_line": Uint64(28), | ||
} | ||
] |