-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add enum_no_longer_non_exhaustive
lint.
#1181
Changes from 3 commits
3b50f08
0743f8d
e535e7b
1029f96
0049cfb
b0ac12d
d871b72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
SemverQuery( | ||
id: "enum_unmarked_non_exhaustive", | ||
human_readable_name: "enum unmarked #[non_exhaustive]", | ||
description: "A Public API enum is no longer #[non_exhaustive]", | ||
required_update: Minor, | ||
lint_level: Allow, | ||
reference_link: Some("https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
current { | ||
item { | ||
... on Enum { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
name @output @tag | ||
|
||
attrs @filter(op: "not_contains", value: ["$non_exhaustive"]) | ||
|
||
importable_path { | ||
path @output @tag | ||
} | ||
|
||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
baseline { | ||
item { | ||
... on Enum { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
name @filter(op: "=", value: ["%name"]) | ||
|
||
attrs @filter(op: "contains", value: ["$non_exhaustive"]) | ||
|
||
importable_path { | ||
path @filter(op: "=", value: ["%path"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"non_exhaustive": "#[non_exhaustive]", | ||
}, | ||
error_message: "A Public API enum is no longer #[non_exhaustive]. External code may assume all variants are known, causing breaking changes if new ones are added.", | ||
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. Same here: please pay close attention to capitalization and style and ensure everything matches existing lints. For example, we don't capitalize |
||
per_result_error_template: Some("enum {{name}} in {{span_filename}}:{{span_begin_line}}"), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1246,6 +1246,7 @@ add_lints!( | |
enum_tuple_variant_field_missing, | ||
enum_tuple_variant_field_now_doc_hidden, | ||
enum_unit_variant_changed_kind, | ||
enum_unmarked_non_exhaustive, | ||
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. Would you mind renaming this lint to follow the implicit convention for items that have stopped being ? For example, consider |
||
enum_variant_added, | ||
enum_variant_marked_deprecated, | ||
enum_variant_marked_non_exhaustive, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
publish = false | ||
name = "enum_unmarked_non_exhaustive" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![no_std] | ||
|
||
pub enum SimpleEnum { | ||
VariantA, | ||
VariantB, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
publish = false | ||
name = "enum_unmarked_non_exhaustive" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#![no_std] | ||
|
||
#[non_exhaustive] | ||
pub enum SimpleEnum { | ||
VariantA, | ||
VariantB, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
source: src/query.rs | ||
expression: "&query_execution_results" | ||
--- | ||
{ | ||
"./test_crates/enum_repr_variant_discriminant_changed/": [ | ||
{ | ||
"name": String("DiscriminantIsChangedButAVariantIsNonExhaustive"), | ||
"path": List([ | ||
String("enum_repr_variant_discriminant_changed"), | ||
String("DiscriminantIsChangedButAVariantIsNonExhaustive"), | ||
]), | ||
"span_begin_line": Uint64(23), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/enum_unmarked_non_exhaustive/": [ | ||
{ | ||
"name": String("SimpleEnum"), | ||
"path": List([ | ||
String("enum_unmarked_non_exhaustive"), | ||
String("SimpleEnum"), | ||
]), | ||
"span_begin_line": Uint64(3), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/type_mismatched_generic_lifetimes/": [ | ||
{ | ||
"name": String("Either"), | ||
"path": List([ | ||
String("type_mismatched_generic_lifetimes"), | ||
String("Either"), | ||
]), | ||
"span_begin_line": Uint64(7), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
} |
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.
Please ensure your capitalization and word/style choices match existing lints.