12

Github New lint: exhaustive_enums, exhaustive_structs by Manishearth · Pull Requ...

 3 years ago
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.
neoserver,ios ssh client

Collaborator

camsteffen left a comment

Sure! A couple minor things.

if !item.attrs.iter().any(|a| a.has_name(sym::non_exhaustive));

then {

let lint = if let ItemKind::Enum(..) = item.kind {

EXHAUSTIVE_STRUCTS

camsteffen 8 days ago

Collaborator

Suggested change
EXHAUSTIVE_STRUCTS EXHAUSTIVE_ENUMS

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!

Manishearth 6 days ago

Author

Member

Ahh. I'm not sure that works so well

Manishearth 6 days ago

Author

Member

Will try, r=you if it doesn't?

cx,

lint,

item.span,

"enums should not be exhaustive",

camsteffen 8 days ago

Collaborator

"enums" should be a variable

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!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK