Skip to content

Migrate to span_clippy_lint #7797

Open
Open

Description

@camsteffen

We have a handful of utils for emitting lints: span_lint, span_lint_and_help, etc. We'd like to replace these with one new util named span_clippy_lint. It was already implemented in #7668, but not yet merged.

Goals

  • Be more consistent with rustc
  • Potentially improve perf since allowed lints stop before computing output messages
  • Enable trimmed paths (Enable trimmed paths #7798)

Question: Should we use .emit() like rustc, or use Drop to emit automatically?

Steps

  • Add span_clippy_lint from Enable trimmed paths #7668 and patch the metadata collector to work with it
  • Change all span_lint_* calls to span_clippy_lint
  • divide this into smaller parts?
  • Remove span_lint* utils and metadata collector support

Activity

  1. xFrednet commented on Jul 21, 2024

    @xFrednet
    Contributor

    I took a small stab at this and refactored 40 restriction lints in #13136.

    Check list
    • absolute_paths
    • alloc_instead_of_core
    • allow_attributes
    • allow_attributes_without_reason
    • arithmetic_side_effects
    • as_conversions
    • as_underscore
    • assertions_on_result_states
    • big_endian_bytes
    • cfg_not_test
    • clone_on_ref_ptr
    • create_dir
    • dbg_macro
    • decimal_literal_representation
    • default_numeric_fallback
    • default_union_representation
    • deref_by_slicing
    • disallowed_script_idents
    • else_if_without_else
    • empty_drop
    • empty_enum_variants_with_brackets
    • empty_structs_with_brackets
    • error_impl_error
    • exhaustive_enums
    • exhaustive_structs
    • exit
    • expect_used
    • field_scoped_visibility_modifiers
    • filetype_is_file
    • float_arithmetic
    • float_cmp_const
    • fn_to_numeric_cast_any
    • format_push_string
    • get_unwrap
    • host_endian_bytes
    • if_then_some_else_none
    • impl_trait_in_params
    • implicit_return
    • indexing_slicing
    • infinite_loop
    • inline_asm_x86_att_syntax
    • inline_asm_x86_intel_syntax
    • integer_division
    • integer_division_remainder_used
    • iter_over_hash_type
    • large_include_file
    • let_underscore_must_use
    • let_underscore_untyped
    • little_endian_bytes
    • lossy_float_literal
    • map_err_ignore
    • mem_forget
    • min_ident_chars
    • missing_assert_message
    • missing_asserts_for_indexing
    • missing_docs_in_private_items
    • missing_inline_in_public_items
    • missing_trait_methods
    • mixed_read_write_in_expression
    • mod_module_files
    • modulo_arithmetic
    • multiple_inherent_impl
    • multiple_unsafe_ops_per_block
    • mutex_atomic
    • needless_raw_strings
    • non_ascii_literal
    • panic
    • panic_in_result_fn
    • partial_pub_fields
    • pattern_type_mismatch
    • print_stderr
    • print_stdout
    • pub_use
    • pub_with_shorthand
    • pub_without_shorthand
    • question_mark_used
    • rc_buffer
    • rc_mutex
    • redundant_type_annotations
    • ref_patterns
    • renamed_function_params
    • rest_pat_in_fully_bound_structs
    • same_name_method
    • self_named_module_files
    • semicolon_inside_block
    • semicolon_outside_block
    • separated_literal_suffix
    • shadow_reuse
    • shadow_same
    • shadow_unrelated
    • single_call_fn
    • single_char_lifetime_names
    • std_instead_of_alloc
    • std_instead_of_core
    • str_to_string
    • string_add
    • string_lit_chars_any
    • string_slice
    • string_to_string
    • suspicious_xor_used_as_pow
    • tests_outside_test_module
    • todo
    • try_err
    • undocumented_unsafe_blocks
    • unimplemented
    • unnecessary_safety_comment
    • unnecessary_safety_doc
    • unnecessary_self_imports
    • unneeded_field_pattern
    • unreachable
    • unseparated_literal_suffix
    • unwrap_in_result
    • unwrap_used
    • use_debug
    • verbose_file_reads
    • wildcard_enum_match_arm

    @rustbot claim

  2. added a commit that references this issue on Jul 26, 2024
  3. added 2 commits that reference this issue on Aug 5, 2024
  4. ada4a commented on Aug 22, 2025

    @ada4a
    Contributor

    Sorry for necroposting (?); I wanted to ask what the status of this is, because AFAICT span_clippy_lint is not really a thing anymore.

    But also, #13136 also cites this issue as the reason for the switch from span_lint_and_{help,note,sugg} to span_lint_and_then. AFAIU that's motivated by the laziness of the latter, but I personally like the brevity of the former, so maybe (a shot in the dark here, not really familiar with this stuff) the former could be rewritten to use the latter internally, so that we get to keep both brevity and laziness?

  5. camsteffen commented on Sep 3, 2025

    @camsteffen
    ContributorAuthor

    AFAICT span_clippy_lint is not really a thing anymore

    It never was a thing. See OP:

    It was already implemented in #7668, but not yet merged.

    AFAIU that's motivated by the laziness of the latter

    I assume by "laziness" you mean being able to defer logic to the closure?

    the former could be rewritten to use the latter internally, so that we get to keep both brevity and laziness?

    The problem is that you are forced to build all the parts of the diagnostic upfront, which is a waste if the lint is not enabled.

    Personally, I like the modularity of just using the diagnostic builder instead of creating another span_lint_and_xxx for every combination. And I think those methods effectively stop folks from considering using both a suggestion and a note, or two suggestions, etc.

  6. ada4a commented on Sep 3, 2025

    @ada4a
    Contributor

    I assume by "laziness" you mean being able to defer logic to the closure?

    Yes

    The problem is that you are forced to build all the parts of the diagnostic upfront, which is a waste if the lint is not enabled.

    I thought the lint pass wouldn't run at all if the lint is disabled?.. Surely it's less expensive to check whether a particular node has the lint allowed before running visit_* on it? I guess that wouldn't quite work with passes consisting of multiple lints though, among other problems.

    And I think those methods effectively stop folks from considering using both a suggestion and a note, or two suggestions, etc.

    I see your point, but on the other hand, having these helpers does make it easier to onboard new contributors imo (based on personal experience)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-tracking-issueCategory: Tracking IssueG-performance-projectGoal: For issues and PRs related to the Clippy Performance Project

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions