Open flip1995 opened 3 years ago
Make it possible to dump a statistics file when running Clippy (allowed lints, ...?)
https://github.com/flip1995/rust-clippy/commit/fa539c9d85a8b1ae9e88bc777a495c2cebf554bc is a first attempt at implementing this as a PoC.
Notes on existing groups:
cargo
: 5 lints; seems finecomplexity
: has more lints than I care to count; vague sub-groups are:
bool_comparison
, borrow_deref_ref
, clone_on_copy
, deref_addrof
bind_instead_of_map
, bytes_count_to_len
, char_lit_as_u8
, deprecated_cfg_attr
, derivable_impls
, double_comparisons
, duration_subsec
borrowed_box
crosspointer_transmute
diverging_sub_expression
double_parens
correctness
: many lints; again, vague sub-groups:
almost_swapped
, clone_double_ref
(issues list false positives), cast_slice_different_sizes
, derive_hash_xor_eq
, derive_ord_xor_partial_ord
bad_bit_mask
, cast_ref_to_mut
, cmp_nan
, deprecated_semver
absurd_extreme_comparisons
, approx_constant
drop_copy
async_yields_async
nursery
:
as_ptr_cast_mut
, debug_assert_with_mut_call
derive_partial_eq_without_eq
branches_sharing_code
(but lint has open issues)cognitive_complexity
pedantic
:
borrow_as_ptr
, checked_conversions
case_sensitive_file_extensions_comparisons
, cast_precision_loss
, cast_ptr_alignment
, cast_sign_loss
, cast_possible_truncation
, cast_possible_wrap
, copy_iterator
, doc_link_with_quotes
doc_markdown
cast_lossless
, cloned_instead_of_copied
, default_trait_access
perf
(note: uses same sub-categories as above but with potential perf issues):
box_collection
, boxed_local
, collapsible_str_replace
box_default
, cmp_owned
restriction
(even more pedantic
?):
alloc_instead_of_core
allow_attributes_without_reason
, assertions_on_result_states
arithmetic_side_effects
as_conversions
, as_underscore
, default_union_representation
create_dir
, dbg_macro
, default_numerical_fallback
, disallowed_script_idents
clone_on_ref_ptr
, decimal_literal_representation
, deref_by_slicing
style
:
assign_op_pattern
, bool_assert_comparison
, bool_to_int_with_if
, chars_last_cmp
, chars_next_cmp
, default_instead_of_iter_empty
assertions_on_constants
, double_must_use
blocks_in_if_conditions
borrow_interior_mutable_const
(why is this in style?), builtin_type_shadow
, declare_interior_mutable_const
, double_neg
, duplicate_underscore_argument
(maybe)bytes_nth
, comparison_to_empty
cmp_null
collapsible_else_if
, collapsible_if
, collapsibile_match
comparison_chain
disallowed_macros
, disallowed_ methods
, disallowed_names
, disallowed_types
suspicious
:
almost_complete_letter_range
, crate_in_macro_def
await_holding_lock
, await_holding_refcell_ref
cast_enum_constructor
, duplicate_mod
cast_enum_truncation
, cast_nan_to_int
cast_abs_to_unsigned
, cast_slice_from_raw_parts
drop_non_drop
blanket_clippy_restriction_lints
await_holding_invalid_type
I only looked at lints starting a..=d
for the larger groups. Let me know if you want me to go through the rest for re-categorisation purposes.
The following lint sub-categories occur in multiple groups:
Both correctness
and suspicious
groups both concern probable mistakes.
(Possibly I am missing the distinction, beyond that suspicious
lints are less certain?)
Several other categories also have "probably wrong" lints. A possible distinction is
"probably a bug" and "probably incorrect but harmless" (the latter should probably
be categorised elsewhere).
"Style" is an odd mix of lints. Possibly simply some lints here are mis-categorised. There is also significant divide between lints which concern redundant stuff and lints which concern complexity, with other lints suggesting "more readable" alternatives.
"Utility" lints (from multiple groups) do nothing unless specific configuration is added, therefore they should be at least "warn" level by default; these could be placed in a new group.
Special sub-categories:
collapsible_else_if
, comparison_chain
lints would possibly be better put in complexity?I tried to take an un-biased view on these categories, though certainly do have opinions (e.g. collapsible_if
's suggestions are often less readable). Ideally it would be easy to disable this type of "style" lint while keeping others such as needless_borrow
.
Is a simple list of groups enough? Would hierarchical groups or non-exclusive categories (as in Venn diagram) be better?
Is introducing more categories an issue, e.g. because people use config like #[warn(clippy::pedantic)]
which would affect fewer lints than previously? Is allowing lints in multiple groups a satisfactory solution?
Some lints are strongly related, e.g. collapsible_if
and collapsible_else_if
or chars_last_cmp
and chars_next_cmp
. Ideally it would be easier to en/dis-able these as a group. Motivation for hierarchical groups?
Potentially new categories:
Possibly mis-categorised lints:
crosspointer_transmute
is in complexity
but should be in correctness
or suspicious
?async_yields_async
is in correctness
but is purely a performance issue?borrow_interior_mutable_const
and declare_interior_mutable_const
are under style
but concern possible bugsdrop_non_drop
is under suspicious
but is harmless (other than the possibility that the wrong object was dropped)My 2¢ on this:
drop_copy
would come up in correct code, and manual drops are usually only ever issued to trigger some guard and/or uphold some invariants. So the lint is less about the code found, more about the code that's likely missing.pedantic
in the past that should probably be in nursery because of false positives. I feel that pedantic as a group is probably the least strongly defined one.borrow_interior_mutable_const´,
builtin_type_shadow,
declare_interior_mutable_constshould likely be in
suspiciousinstead of
style. I think their placement is simply due to the fact that the
suspicious` lint group is quite young and the lints probably predate it.disallowed_*
lints are probably only in style to warn
by default, because conceptually, they are clearly restriction lints.drop_copy
, drop_non_drop
is linting something that is not by itself problematic but likely masks an issue because of code that isn't there instead. So suspicious
or correctness
seem to be the correct group for them.shadow
lint group before, but it was removed when we got our current system. We could in theory reinstate some of the smaller groups of similar lints, but I doubt it makes much of a difference in practical use.Regarding drop
, I have in the past used it with (mutable) references to get around borrow-checker restrictions. None of the examples I have now which require an explicit drop trip these lints, however.
The current lint groups focus on the why something is linted. Your proposed groups as I understand them focus on the what instead.
I guess so, though sometimes the why eludes me. E.g. why are bytes_count_to_len
and derivable_impls
complexity lints while bool_to_int_with_if
and chars_last_cmp
are style lints? My best guess is that style is one of the oldest groups and a lot of its contents never got re-assigned. Should they be moved to complexity (or even a new group)?
A few of those from above are a little hard to place:
diverging_sub_expression
: this could be considered a style lint but is probably closest to being a restriction lint. I guess it is not in that category mainly to enable it by default. Maybe there should be a default_restriction
category (also including disallowed_*
lints)?borrowed_box
is in complexity; it seems more like a default_restriction
lintcognitive_complexity
doc_markdown
(possibly only in pedantic
due to known issues; I guess this is okay)blocks_in_if_conditions
could almost be in suspiciousawait_holding_invalid_type
is another lint for the hypothetical default_restriction
groupMy best guess is that style is one of the oldest groups and a lot of its contents never got re-assigned. Should they be moved to complexity (or even a new group)?
Lint groups are just assigned by whatever the author + reviewer think is the best group. We try to find the best group, but sometimes some lints might slip through into the arguably wrong group. If you think a lint should be moved to a different group, it is as easy as changing the group in the lint definition and running cargo dev update_lints
.
I don't think we will introduce non-exclusive groups in Clippy. The groups we have need to stay, as they were defined in an RFC. Additional groups that might overlap (with existing groups) will just make configuring lints confusing.
Sub-groups maybe. (I brought this up for pedantic
) But now, I don't really see a practical use for this in our warn-by-default lint groups.
There are more and more issues about managing lints in Clippy popping up. Lints are hard to implement with a guarantee of no/few false positives (FPs). One way to address this might be to introduce more lint groups to give users the ability to better manage lints, or improve the process of classifying lints, so that disabling lints due to FPs becomes rare. It is important to note, that Clippy lints are less conservative than
rustc
lints, which won't change in the future.5537 (production lints)
6366 (
suspicious
group)Steps to completion:
suspicious
lint groupexpect
attribute (https://github.com/rust-lang/rust/issues/54503)