Github New lint: exhaustive_enums, exhaustive_structs by Manishearth · Pull Requ...
source link: https://github.com/rust-lang/rust-clippy/pull/6617
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Collaborator
camsteffen left a comment
Sure! A couple minor things.
clippy_lints/src/exhaustive_items.rs
Outdated
if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
then {
let lint = if let ItemKind::Enum(..) = item.kind {
EXHAUSTIVE_STRUCTS
clippy_lints/src/exhaustive_items.rs
Outdated
EXHAUSTIVE_STRUCTS
};
if let Some(snippet) = snippet_opt(cx, item.span) {
camsteffen 8 days ago
Collaborator
Consider using span_lint_and_then
and span_suggestion(item.span.shrink_to_lo(), ..)
so that you don't need to include the snippet in the suggestion.
camsteffen 8 days ago
Collaborator
Hmm you didn't do the shrink_to_lo()
part... the point of using span_lint_and_then
was to use a different Span
for the suggestion. The suggestion would be an insertion rather than replacing the entire item. I'm not entirely certain this is possible but it would be cleaner!
clippy_lints/src/exhaustive_items.rs
Outdated
cx,
lint,
item.span,
"enums should not be exhaustive",
camsteffen 8 days ago
Collaborator
A couple nits. The message should be about "this enum" instead of "all enums". I think it would be good to mention that the item is "public" or "exported". So maybe: "declared a public, exhaustive enum"
Manishearth 8 days ago
Author
Member
I picked "Exported foo should not be exhaustive". Lmk if you prefer the other way!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK