Expand description
Some lints that are built in to the compiler.
These are the built-in lints that are emitted direct in the main
compiler code, rather than using their own custom pass. Those
lints are all available in rustc_lint::builtin.
When removing a lint, make sure to also add a call to register_removed in
compiler/rustc_lint/src/lib.rs.
Structs§
- HardwiredLints 
- Does nothing as a lint pass, but registers some Lints that are used by other parts of the compiler.
- UnusedDocComment 
Statics§
- AARCH64_ SOFTFLOAT_ NEON 
- The aarch64_softfloat_neonlint detects usage of#[target_feature(enable = "neon")]on softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of function calls, making this attribute unsound to use.
- ABSOLUTE_PATHS_ NOT_ STARTING_ WITH_ CRATE 
- The absolute_paths_not_starting_with_cratelint detects fully qualified paths that start with a module name instead ofcrate,self, or an extern crate name
- AMBIGUOUS_ASSOCIATED_ ITEMS 
- The ambiguous_associated_itemslint detects ambiguity between associated items and enum variants.
- AMBIGUOUS_GLOB_ IMPORTS 
- The ambiguous_glob_importslint detects glob imports that should report ambiguity errors, but previously didn’t do that due to rustc bugs.
- AMBIGUOUS_GLOB_ REEXPORTS 
- The ambiguous_glob_reexportslint detects cases where names re-exported via globs collide. Downstream users trying to use the same name re-exported from multiple globs will receive a warning pointing out redefinition of the same name.
- ARITHMETIC_OVERFLOW 
- The arithmetic_overflowlint detects that an arithmetic operation will overflow.
- ASM_SUB_ REGISTER 
- The asm_sub_registerlint detects using only a subset of a register for inline asm inputs.
- BAD_ASM_ STYLE 
- The bad_asm_stylelint detects the use of the.intel_syntaxand.att_syntaxdirectives.
- BARE_TRAIT_ OBJECTS 
- The bare_trait_objectslint suggests usingdyn Traitfor trait objects.
- BINDINGS_WITH_ VARIANT_ NAME 
- The bindings_with_variant_namelint detects pattern bindings with the same name as one of the matched variants.
- BREAK_WITH_ LABEL_ AND_ LOOP 
- The break_with_label_and_looplint detects labeledbreakexpressions with an unlabeled loop as their value expression.
- COHERENCE_LEAK_ CHECK 
- The coherence_leak_checklint detects conflicting implementations of a trait that are only distinguished by the old leak-check code.
- CONFLICTING_REPR_ HINTS 
- The conflicting_repr_hintslint detectsreprattributes with conflicting hints.
- CONST_EVALUATABLE_ UNCHECKED 
- The const_evaluatable_uncheckedlint detects a generic constant used in a type.
- CONST_ITEM_ MUTATION 
- The const_item_mutationlint detects attempts to mutate aconstitem.
- DEAD_CODE 
- The dead_codelint detects unused, unexported items.
- DEPENDENCY_ON_ UNIT_ NEVER_ TYPE_ FALLBACK 
- The dependency_on_unit_never_type_fallbacklint detects cases where code compiles with never type fallback being(), but will stop compiling with fallback being!.
- DEPRECATED
- The deprecatedlint detects use of deprecated items.
- DEPRECATED_IN_ FUTURE 
- The deprecated_in_futurelint is internal to rustc and should not be used by user code.
- DEPRECATED_SAFE_ 2024 
- The deprecated_safe_2024lint detects unsafe functions being used as safe functions.
- DEPRECATED_WHERE_ CLAUSE_ LOCATION 
- The deprecated_where_clause_locationlint detects when a where clause in front of the equals in an associated type.
- DUPLICATE_MACRO_ ATTRIBUTES 
- The duplicate_macro_attributeslint detects when a#[test]-like built-in macro attribute is duplicated on an item. This lint may trigger onbench,cfg_eval,testandtest_case.
- ELIDED_LIFETIMES_ IN_ ASSOCIATED_ CONSTANT 
- The elided_lifetimes_in_associated_constantlint detects elided lifetimes in associated constants when there are other lifetimes in scope. This was accidentally supported, and this lint was later relaxed to allow eliding lifetimes to'staticwhen there are no lifetimes in scope.
- ELIDED_LIFETIMES_ IN_ PATHS 
- The elided_lifetimes_in_pathslint detects the use of hidden lifetime parameters.
- EXPLICIT_BUILTIN_ CFGS_ IN_ FLAGS 
- The explicit_builtin_cfgs_in_flagslint detects builtin cfgs set via the--cfgflag.
- EXPLICIT_OUTLIVES_ REQUIREMENTS 
- The explicit_outlives_requirementslint detects unnecessary lifetime bounds that can be inferred.
- EXPORTED_PRIVATE_ DEPENDENCIES 
- The exported_private_dependencieslint detects private dependencies that are exposed in a public interface.
- FFI_UNWIND_ CALLS 
- The ffi_unwind_callslint detects calls to foreign functions or function pointers withC-unwindor other FFI-unwind ABIs.
- FORBIDDEN_LINT_ GROUPS 
- The forbidden_lint_groupslint detects violations offorbidapplied to a lint group. Due to a bug in the compiler, these used to be overlooked entirely. They now generate a warning.
- FUNCTION_ITEM_ REFERENCES 
- The function_item_referenceslint detects function references that are formatted withfmt::Pointeror transmuted.
- FUZZY_PROVENANCE_ CASTS 
- The fuzzy_provenance_castslint detects anascast between an integer and a pointer.
- HIDDEN_GLOB_ REEXPORTS 
- The hidden_glob_reexportslint detects cases where glob re-export items are shadowed by private items.
- ILL_FORMED_ ATTRIBUTE_ INPUT 
- The ill_formed_attribute_inputlint detects ill-formed attribute inputs that were previously accepted and used in practice.
- INCOMPLETE_INCLUDE 
- The incomplete_includelint detects the use of theinclude!macro with a file that contains more than one expression.
- INEFFECTIVE_UNSTABLE_ TRAIT_ IMPL 
- The ineffective_unstable_trait_impllint detects#[unstable]attributes which are not used.
- INLINE_ALWAYS_ MISMATCHING_ TARGET_ FEATURES 
- The inline_always_mismatching_target_featureslint will trigger when a function with the#[inline(always)]and#[target_feature(enable = "...")]attributes is called and cannot be inlined due to missing target features in the caller.
- INLINE_NO_ SANITIZE 
- The inline_no_sanitizelint detects incompatible use of#[inline(always)]and#[sanitize(xyz = "off")].
- INVALID_DOC_ ATTRIBUTES 
- The invalid_doc_attributeslint detects when the#[doc(...)]is misused.
- INVALID_MACRO_ EXPORT_ ARGUMENTS 
- The invalid_macro_export_argumentslint detects cases where#[macro_export]is being used with invalid arguments.
- INVALID_TYPE_ PARAM_ DEFAULT 
- The invalid_type_param_defaultlint detects type parameter defaults erroneously allowed in an invalid location.
- IRREFUTABLE_LET_ PATTERNS 
- The irrefutable_let_patternslint detects irrefutable patterns inif lets,while lets, andif letguards.
- LARGE_ASSIGNMENTS 
- The large_assignmentslint detects when objects of large types are being moved around.
- LATE_BOUND_ LIFETIME_ ARGUMENTS 
- The late_bound_lifetime_argumentslint detects generic lifetime arguments in path segments with late bound lifetime parameters.
- LEGACY_DERIVE_ HELPERS 
- The legacy_derive_helperslint detects derive helper attributes that are used before they are introduced.
- LINKER_MESSAGES 
- The linker_messageslint forwards warnings from the linker.
- LONG_RUNNING_ CONST_ EVAL 
- The long_running_const_evallint is emitted when const eval is running for a long time to ensure rustc terminates even if you accidentally wrote an infinite loop.
- LOSSY_PROVENANCE_ CASTS 
- The lossy_provenance_castslint detects anascast between a pointer and an integer.
- MACRO_EXPANDED_ MACRO_ EXPORTS_ ACCESSED_ BY_ ABSOLUTE_ PATHS 
- The macro_expanded_macro_exports_accessed_by_absolute_pathslint detects macro-expandedmacro_exportmacros from the current crate that cannot be referred to by absolute paths.
- MACRO_USE_ EXTERN_ CRATE 
- The macro_use_extern_cratelint detects the use of themacro_useattribute.
- MALFORMED_DIAGNOSTIC_ ATTRIBUTES 
- The malformed_diagnostic_attributeslint detects malformed diagnostic attributes.
- MALFORMED_DIAGNOSTIC_ FORMAT_ LITERALS 
- The malformed_diagnostic_format_literalslint detects malformed diagnostic format literals.
- META_VARIABLE_ MISUSE 
- The meta_variable_misuselint detects possible meta-variable misuse in macro definitions.
- MISPLACED_DIAGNOSTIC_ ATTRIBUTES 
- The misplaced_diagnostic_attributeslint detects wrongly placed diagnostic attributes.
- MISSING_ABI 
- The missing_abilint detects cases where the ABI is omitted fromexterndeclarations.
- MISSING_UNSAFE_ ON_ EXTERN 
- The missing_unsafe_on_externlint detects missing unsafe keyword on extern declarations.
- MUST_NOT_ SUSPEND 
- The must_not_suspendlint guards against values that shouldn’t be held across suspend points (.await)
- NAMED_ARGUMENTS_ USED_ POSITIONALLY 
- The named_arguments_used_positionallylint detects cases where named arguments are only used positionally in format strings. This usage is valid but potentially very confusing.
- NEVER_TYPE_ FALLBACK_ FLOWING_ INTO_ UNSAFE 
- The never_type_fallback_flowing_into_unsafelint detects cases where never type fallback affects unsafe function calls.
- NON_CONTIGUOUS_ RANGE_ ENDPOINTS 
- The non_contiguous_range_endpointslint detects likely off-by-one errors when using exclusive range patterns.
- NON_EXHAUSTIVE_ OMITTED_ PATTERNS 
- The non_exhaustive_omitted_patternslint aims to help consumers of a#[non_exhaustive]struct or enum who want to match all of its fields/variants explicitly.
- OUT_OF_ SCOPE_ MACRO_ CALLS 
- The out_of_scope_macro_callslint detectsmacro_rulescalled when they are not in scope, above their definition, which may happen in key-value attributes.
- OVERLAPPING_RANGE_ ENDPOINTS 
- The overlapping_range_endpointslint detectsmatcharms that have range patterns that overlap on their endpoints.
- PATTERNS_IN_ FNS_ WITHOUT_ BODY 
- The patterns_in_fns_without_bodylint detectsmutidentifier patterns as a parameter in functions without a body.
- PRIVATE_BOUNDS 
- The private_boundslint detects types in a secondary interface of an item, that are more private than the item itself. Secondary interface of an item consists of bounds on generic parameters and where clauses, including supertraits for trait items.
- PRIVATE_INTERFACES 
- The private_interfaceslint detects types in a primary interface of an item, that are more private than the item itself. Primary interface of an item is all its interface except for bounds on generic parameters and where clauses.
- PRIVATE_MACRO_ USE 
- The private_macro_uselint detects private macros that are imported with#[macro_use].
- PROC_MACRO_ DERIVE_ RESOLUTION_ FALLBACK 
- The proc_macro_derive_resolution_fallbacklint detects proc macro derives using inaccessible names from parent modules.
- PUB_USE_ OF_ PRIVATE_ EXTERN_ CRATE 
- The pub_use_of_private_extern_cratelint detects a specific situation of re-exporting a privateextern crate.
- REDUNDANT_IMPORTS 
- The redundant_importslint detects imports that are redundant due to being imported already; either through a previous import, or being present in the prelude.
- REDUNDANT_LIFETIMES 
- The redundant_lifetimeslint detects lifetime parameters that are redundant because they are equal to another named lifetime.
- REFINING_IMPL_ TRAIT_ INTERNAL 
- The refining_impl_trait_internallint detectsimpl Traitreturn types in method signatures that are refined by a trait implementation, meaning the implementation adds information about the return type that is not present in the trait.
- REFINING_IMPL_ TRAIT_ REACHABLE 
- The refining_impl_trait_reachablelint detectsimpl Traitreturn types in method signatures that are refined by a publically reachable trait implementation, meaning the implementation adds information about the return type that is not present in the trait.
- RENAMED_AND_ REMOVED_ LINTS 
- The renamed_and_removed_lintslint detects lints that have been renamed or removed.
- REPR_TRANSPARENT_ NON_ ZST_ FIELDS 
- The repr_transparent_non_zst_fieldslint detects types marked#[repr(transparent)]that (transitively) contain a type that is not guaranteed to remain a ZST type under all configurations.
- RUST_2021_ INCOMPATIBLE_ CLOSURE_ CAPTURES 
- The rust_2021_incompatible_closure_captureslint detects variables that aren’t completely captured in Rust 2021, such that theDroporder of their fields may differ between Rust 2018 and 2021.
- RUST_2021_ INCOMPATIBLE_ OR_ PATTERNS 
- The rust_2021_incompatible_or_patternslint detects usage of old versions of or-patterns.
- RUST_2021_ PREFIXES_ INCOMPATIBLE_ SYNTAX 
- The rust_2021_prefixes_incompatible_syntaxlint detects identifiers that will be parsed as a prefix instead in Rust 2021.
- RUST_2021_ PRELUDE_ COLLISIONS 
- The rust_2021_prelude_collisionslint detects the usage of trait methods which are ambiguous with traits added to the prelude in future editions.
- RUST_2024_ GUARDED_ STRING_ INCOMPATIBLE_ SYNTAX 
- The rust_2024_guarded_string_incompatible_syntaxlint detects#tokens that will be parsed as part of a guarded string literal in Rust 2024.
- RUST_2024_ INCOMPATIBLE_ PAT 
- The rust_2024_incompatible_patlint detects patterns whose meaning will change in the Rust 2024 edition.
- RUST_2024_ PRELUDE_ COLLISIONS 
- The rust_2024_prelude_collisionslint detects the usage of trait methods which are ambiguous with traits added to the prelude in future editions.
- SELF_CONSTRUCTOR_ FROM_ OUTER_ ITEM 
- The self_constructor_from_outer_itemlint detects cases where theSelfconstructor was silently allowed due to a bug in the resolver, and which may produce surprising and unintended behavior.
- SEMICOLON_IN_ EXPRESSIONS_ FROM_ MACROS 
- The semicolon_in_expressions_from_macroslint detects trailing semicolons in macro bodies when the macro is invoked in expression position. This was previous accepted, but is being phased out.
- SINGLE_USE_ LIFETIMES 
- The single_use_lifetimeslint detects lifetimes that are only used once.
- SOFT_UNSTABLE 
- The soft_unstablelint detects unstable features that were unintentionally allowed on stable. This is a future-incompatible lint to transition this to a hard error in the future. See issue #64266 for more details.
- STABLE_FEATURES 
- The stable_featureslint detects afeatureattribute that has since been made stable.
- SUPERTRAIT_ITEM_ SHADOWING_ DEFINITION 
- The supertrait_item_shadowing_definitionlint detects when the definition of an item that is provided by both a subtrait and supertrait is shadowed, preferring the subtrait.
- SUPERTRAIT_ITEM_ SHADOWING_ USAGE 
- The supertrait_item_shadowing_usagelint detects when the usage of an item that is provided by both a subtrait and supertrait is shadowed, preferring the subtrait.
- TAIL_CALL_ TRACK_ CALLER 
- The tail_call_track_callerlint detects usage ofbecomeattempting to tail call a function marked with#[track_caller].
- TAIL_EXPR_ DROP_ ORDER 
- The tail_expr_drop_orderlint looks for those values generated at the tail expression location, that runs a customDropdestructor. Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior. This lint detects those cases and provides you information on those values and their custom destructor implementations. Your discretion on this information is required.
- TEST_UNSTABLE_ LINT 
- The test_unstable_lintlint tests unstable lints and is perma-unstable.
- TEXT_DIRECTION_ CODEPOINT_ IN_ COMMENT 
- The text_direction_codepoint_in_commentlint detects Unicode codepoints in comments that change the visual representation of text on screen in a way that does not correspond to their on memory representation.
- TEXT_DIRECTION_ CODEPOINT_ IN_ LITERAL 
- The text_direction_codepoint_in_literallint detects Unicode codepoints that change the visual representation of text on screen in a way that does not correspond to their on memory representation.
- TRIVIAL_CASTS 
- The trivial_castslint detects trivial casts which could be replaced with coercion, which may require a temporary variable.
- TRIVIAL_NUMERIC_ CASTS 
- The trivial_numeric_castslint detects trivial numeric casts of types which could be removed.
- TYVAR_BEHIND_ RAW_ POINTER 
- The tyvar_behind_raw_pointerlint detects raw pointer to an inference variable.
- UNCONDITIONAL_PANIC 
- The unconditional_paniclint detects an operation that will cause a panic at runtime.
- UNCONDITIONAL_RECURSION 
- The unconditional_recursionlint detects functions that cannot return without calling themselves.
- UNCOVERED_PARAM_ IN_ PROJECTION 
- The uncovered_param_in_projectionlint detects a violation of one of Rust’s orphan rules for foreign trait implementations that concerns the use of type parameters inside trait associated type paths (“projections”) whose output may not be a local type that is mistakenly considered to “cover” said parameters which is unsound and which may be rejected by a future version of the compiler.
- UNEXPECTED_CFGS 
- The unexpected_cfgslint detects unexpected conditional compilation conditions.
- UNFULFILLED_LINT_ EXPECTATIONS 
- The unfulfilled_lint_expectationslint detects when a lint expectation is unfulfilled.
- UNINHABITED_STATIC 
- The uninhabited_staticlint detects uninhabited statics.
- UNKNOWN_CRATE_ TYPES 
- The unknown_crate_typeslint detects an unknown crate type found in acrate_typeattribute.
- UNKNOWN_DIAGNOSTIC_ ATTRIBUTES 
- The unknown_diagnostic_attributeslint detects unknown diagnostic attributes.
- UNKNOWN_LINTS 
- The unknown_lintslint detects unrecognized lint attributes.
- UNNAMEABLE_TEST_ ITEMS 
- The unnameable_test_itemslint detects#[test]functions that are not able to be run by the test harness because they are in a position where they are not nameable.
- UNNAMEABLE_TYPES 
- The unnameable_typeslint detects types for which you can get objects of that type, but cannot name the type itself.
- UNREACHABLE_CODE 
- The unreachable_codelint detects unreachable code paths.
- UNREACHABLE_PATTERNS 
- The unreachable_patternslint detects unreachable patterns.
- UNSAFE_ATTR_ OUTSIDE_ UNSAFE 
- The unsafe_attr_outside_unsafelint detects a missing unsafe keyword on attributes considered unsafe.
- UNSAFE_OP_ IN_ UNSAFE_ FN 
- The unsafe_op_in_unsafe_fnlint detects unsafe operations in unsafe functions without an explicit unsafe block.
- UNSTABLE_NAME_ COLLISIONS 
- The unstable_name_collisionslint detects that you have used a name that the standard library plans to add in the future.
- UNSTABLE_SYNTAX_ PRE_ EXPANSION 
- The unstable_syntax_pre_expansionlint detects the use of unstable syntax that is discarded during attribute expansion.
- UNSUPPORTED_CALLING_ CONVENTIONS 
- The unsupported_calling_conventionslint is output whenever there is a use of thestdcall,fastcall, andcdeclcalling conventions (or their unwind variants) on targets that cannot meaningfully be supported for the requested target.
- UNSUPPORTED_FN_ PTR_ CALLING_ CONVENTIONS 
- The unsupported_fn_ptr_calling_conventionslint is output whenever there is a use of a target dependent calling convention on a target that does not support this calling convention on a function pointer.
- UNUSED_ASSIGNMENTS 
- The unused_assignmentslint detects assignments that will never be read.
- UNUSED_ASSOCIATED_ TYPE_ BOUNDS 
- The unused_associated_type_boundslint is emitted when an associated type bound is added to a trait object, but the associated type has awhere Self: Sizedbound, and is thus unavailable on the trait object anyway.
- UNUSED_ATTRIBUTES 
- The unused_attributeslint detects attributes that were not used by the compiler.
- UNUSED_CRATE_ DEPENDENCIES 
- The unused_crate_dependencieslint detects crate dependencies that are never used.
- UNUSED_DOC_ COMMENTS 
- The unused_doc_commentslint detects doc comments that aren’t used byrustdoc.
- UNUSED_EXTERN_ CRATES 
- The unused_extern_crateslint guards againstextern crateitems that are never used.
- UNUSED_FEATURES 
- The unused_featureslint detects unused or unknown features found in crate-levelfeatureattributes.
- UNUSED_IMPORTS 
- The unused_importslint detects imports that are never used.
- UNUSED_LABELS 
- The unused_labelslint detects labels that are never used.
- UNUSED_LIFETIMES 
- The unused_lifetimeslint detects lifetime parameters that are never used.
- UNUSED_MACROS 
- The unused_macroslint detects macros that were not used.
- UNUSED_MACRO_ RULES 
- The unused_macro_ruleslint detects macro rules that were not used.
- UNUSED_MUT 
- The unused_mutlint detects mut variables which don’t need to be mutable.
- UNUSED_QUALIFICATIONS 
- The unused_qualificationslint detects unnecessarily qualified names.
- UNUSED_UNSAFE 
- The unused_unsafelint detects unnecessary use of anunsafeblock.
- UNUSED_VARIABLES 
- The unused_variableslint detects variables which are not used in any way.
- USELESS_DEPRECATED 
- The useless_deprecatedlint detects deprecation attributes with no effect.
- WARNINGS
- The warningslint allows you to change the level of other lints which produce warnings.