Module rustc_lint::builtin [−][src]
Expand description
Lints in the Rust compiler.
This contains lints which can feasibly be implemented as their own
AST visitor. Also see rustc_session::lint::builtin, which contains the
definitions of lints that are emitted directly inside the main compiler.
To add a new lint to rustc, declare it here using declare_lint!().
Then add code to emit the new lint in the appropriate circumstances.
You can do that in an existing LintPass if it makes sense, or in a
new LintPass, or using Session::add_lint elsewhere in the
compiler. Only do the latter if the check can’t be written cleanly as a
LintPass (also, note that such lints will need to be defined in
rustc_session::lint::builtin, not here).
If you define a new EarlyLintPass, you will also need to add it to the
add_early_builtin! or add_early_builtin_with_new! invocation in
lib.rs. Use the former for unit-like structs and the latter for structs
with a pub fn new().
If you define a new LateLintPass, you will also need to add it to the
late_lint_methods! invocation in lib.rs.
Structs
Checks for use of anonymous parameters (RFC 1685).
Check for use of attributes which have been deprecated.
Does nothing as a lint pass, but registers some Lints
that are used by other parts of the compiler.
Check for used feature gates in INCOMPLETE_FEATURES in rustc_feature/src/active.rs.
Check for uses of edition keywords used as an identifier.
Does nothing as a lint pass, but registers some Lints
which are used by other parts of the compiler.
Lint for trait and lifetime bounds that don’t depend on type parameters which either do nothing, or stop the item from being used.
Lint for trait and lifetime bounds in type aliases being mostly ignored. They are relevant when using associated types, but otherwise neither checked at definition site nor enforced at use site.
Lint for items marked pub that aren’t reachable from other crates.
Forbids using the #[feature(...)] attribute
Lint constants that are erroneous. Without this lint, we might not get any diagnostic if the constant is unused within this crate, even though downstream crates can’t use it without producing an error.
Enums
Differentiate between whether the name for an extern decl came from the link_name attribute or just from declaration itself. This is important because we don’t want to report clashes on symbol name if they don’t actually clash because one or the other links against a symbol with a different name.
Constants
Statics
The absolute_paths_not_starting_with_crate lint detects fully
qualified paths that start with a module name instead of crate,
self, or an extern crate name
The ambiguous_associated_items lint detects ambiguity between
associated items and enum variants.
The anonymous_parameters lint detects anonymous parameters in trait
definitions.
The arithmetic_overflow lint detects that an arithmetic operation
will overflow.
The asm_sub_register lint detects using only a subset of a register
for inline asm inputs.
The bad_asm_style lint detects the use of the .intel_syntax and
.att_syntax directives.
The bare_trait_objects lint suggests using dyn Trait for trait
objects.
The bindings_with_variant_name lint detects pattern bindings with
the same name as one of the matched variants.
The box_pointers lints use of the Box type.
The break_with_label_and_loop lint detects labeled break expressions with
an unlabeled loop as their value expression.
The cenum_impl_drop_cast lint detects an as cast of a field-less
enum that implements Drop.
The clashing_extern_declarations lint detects when an extern fn
has been declared with the same name but different types.
The coherence_leak_check lint detects conflicting implementations of
a trait that are only distinguished by the old leak-check code.
The conflicting_repr_hints lint detects repr attributes with
conflicting hints.
The const_err lint detects an erroneous expression while doing
constant evaluation.
The const_evaluatable_unchecked lint detects a generic constant used
in a type.
The const_item_mutation lint detects attempts to mutate a const
item.
The dead_code lint detects unused, unexported items.
The deprecated lint detects use of deprecated items.
The deprecated_in_future lint is internal to rustc and should not be
used by user code.
The deref_into_dyn_supertrait lint is output whenever there is a use of the
Deref implementation with a dyn SuperTrait type as Output.
The deref_nullptr lint detects when an null pointer is dereferenced,
which causes undefined behavior.
The elided_lifetimes_in_paths lint detects the use of hidden
lifetime parameters.
The ellipsis_inclusive_range_patterns lint detects the ... range
pattern, which is deprecated.
The explicit_outlives_requirements lint detects unnecessary
lifetime bounds that can be inferred.
The exported_private_dependencies lint detects private dependencies
that are exposed in a public interface.
The forbidden_lint_groups lint detects violations of
forbid applied to a lint group. Due to a bug in the compiler,
these used to be overlooked entirely. They now generate a warning.
The function_item_references lint detects function references that are
formatted with fmt::Pointer or transmuted.
The illegal_floating_point_literal_pattern lint detects
floating-point literals used in patterns.
The ill_formed_attribute_input lint detects ill-formed attribute
inputs that were previously accepted and used in practice.
The incomplete_features lint detects unstable features enabled with
the feature attribute that may function improperly in some or all
cases.
The incomplete_include lint detects the use of the include!
macro with a file that contains more than one expression.
The ineffective_unstable_trait_impl lint detects #[unstable] attributes which are not used.
The inline_no_sanitize lint detects incompatible use of
#[inline(always)] and #[no_sanitize(...)].
The invalid_doc_attributes lint detects when the #[doc(...)] is
misused.
The invalid_type_param_default lint detects type parameter defaults
erroneously allowed in an invalid location.
The invalid_value lint detects creating a value that is not valid,
such as a null reference.
The irrefutable_let_patterns lint detects irrefutable patterns
in if lets, while lets, and if let guards.
The keyword_idents lint detects edition keywords being used as an
identifier.
The large_assignments lint detects when objects of large
types are being moved around.
The late_bound_lifetime_arguments lint detects generic lifetime
arguments in path segments with late bound lifetime parameters.
The legacy_derive_helpers lint detects derive helper attributes
that are used before they are introduced.
The macro_expanded_macro_exports_accessed_by_absolute_paths lint
detects macro-expanded macro_export macros from the current crate
that cannot be referred to by absolute paths.
The macro_use_extern_crate lint detects the use of the
macro_use attribute.
The meta_variable_misuse lint detects possible meta-variable misuse
in macro definitions.
The missing_abi lint detects cases where the ABI is omitted from
extern declarations.
The missing_copy_implementations lint detects potentially-forgotten
implementations of Copy.
The missing_debug_implementations lint detects missing
implementations of fmt::Debug.
The missing_docs lint detects missing documentation for public items.
The missing_fragment_specifier lint is issued when an unused pattern in a
macro_rules! macro definition has a meta-variable (e.g. $e) that is not
followed by a fragment specifier (e.g. :expr).
The must_not_suspend lint guards against values that shouldn’t be held across suspend points
(.await)
The mutable_borrow_reservation_conflict lint detects the reservation
of a two-phased borrow that conflicts with other shared borrows.
The mutable_transmutes lint catches transmuting from &T to &mut T because it is undefined behavior.
The named_asm_labels lint detects the use of named labels in the
inline asm! macro.
The nontrivial_structural_match lint detects constants that are used in patterns,
whose type is not structural-match and whose initializer body actually uses values
that are not structural-match. So Option<NotStruturalMatch> is ok if the constant
is just None.
The non_exhaustive_omitted_patterns lint detects when a wildcard (_ or ..) in a
pattern for a #[non_exhaustive] struct or enum is reachable.
The non_shorthand_field_patterns lint detects using Struct { x: x }
instead of Struct { x } in a pattern.
The no_mangle_const_items lint detects any const items with the
no_mangle attribute.
The no_mangle_generic_items lint detects generic items that must be
mangled.
The order_dependent_trait_objects lint detects a trait coherency
violation that would allow creating two trait impls for the same
dynamic trait object involving marker traits.
The overlapping_range_endpoints lint detects match arms that have range patterns that
overlap on their endpoints.
The patterns_in_fns_without_body lint detects mut identifier
patterns as a parameter in functions without a body.
The pointer_structural_match lint detects pointers used in patterns whose behaviour
cannot be relied upon across compiler versions and optimization levels.
The private_in_public lint detects private items in public
interfaces not caught by the old implementation.
The proc_macro_back_compat lint detects uses of old versions of certain
proc-macro crates, which have hardcoded workarounds in the compiler.
The proc_macro_derive_resolution_fallback lint detects proc macro
derives using inaccessible names from parent modules.
The pub_use_of_private_extern_crate lint detects a specific
situation of re-exporting a private extern crate.
The renamed_and_removed_lints lint detects lints that have been
renamed or removed.
The rust_2021_incompatible_closure_captures lint detects variables that aren’t completely
captured in Rust 2021, such that the Drop order of their fields may differ between
Rust 2018 and 2021.
The rust_2021_incompatible_or_patterns lint detects usage of old versions of or-patterns.
The rust_2021_prefixes_incompatible_syntax lint detects identifiers that will be parsed as a
prefix instead in Rust 2021.
The rust_2021_prelude_collisions lint detects the usage of trait methods which are ambiguous
with traits added to the prelude in future editions.
The semicolon_in_expressions_from_macros lint detects trailing semicolons
in macro bodies when the macro is invoked in expression position.
This was previous accepted, but is being phased out.
The single_use_lifetimes lint detects lifetimes that are only used
once.
The soft_unstable lint detects unstable features that were
unintentionally allowed on stable.
The stable_features lint detects a feature attribute that
has since been made stable.
The trivial_bounds lint detects trait bounds that don’t depend on
any type parameters.
The trivial_casts lint detects trivial casts which could be replaced
with coercion, which may require type ascription or a temporary
variable.
The trivial_numeric_casts lint detects trivial numeric casts of types
which could be removed.
The type_alias_bounds lint detects bounds in type aliases.
The tyvar_behind_raw_pointer lint detects raw pointer to an
inference variable.
The unaligned_references lint detects unaligned references to fields
of packed structs.
The unconditional_panic lint detects an operation that will cause a
panic at runtime.
The unconditional_recursion lint detects functions that cannot
return without calling themselves.
The undefined_naked_function_abi lint detects naked function definitions that
either do not specify an ABI or specify the Rust ABI.
The uninhabited_static lint detects uninhabited statics.
The unknown_crate_types lint detects an unknown crate type found in
a crate_type attribute.
The unknown_lints lint detects unrecognized lint attribute.
The unnameable_test_items lint 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.
The unreachable_code lint detects unreachable code paths.
The unreachable_patterns lint detects unreachable patterns.
The unreachable_pub lint triggers for pub items not reachable from
the crate root.
The unsafe_code lint catches usage of unsafe code.
The unsafe_op_in_unsafe_fn lint detects unsafe operations in unsafe
functions without an explicit unsafe block.
The unstable_features is deprecated and should no longer be used.
The unstable_name_collisions lint detects that you have used a name
that the standard library plans to add in the future.
The unsupported_calling_conventions lint is output whenever there is a use of the
stdcall, fastcall, thiscall, vectorcall calling conventions (or their unwind
variants) on targets that cannot meaningfully be supported for the requested target.
The unsupported_naked_functions lint detects naked function
definitions that are unsupported but were previously accepted.
The unused_assignments lint detects assignments that will never be read.
The unused_attributes lint detects attributes that were not used by
the compiler.
The unused_crate_dependencies lint detects crate dependencies that
are never used.
The unused_doc_comments lint detects doc comments that aren’t used
by rustdoc.
The unused_extern_crates lint guards against extern crate items
that are never used.
The unused_features lint detects unused or unknown features found in
crate-level feature attributes.
The unused_imports lint detects imports that are never used.
The unused_labels lint detects labels that are never used.
The unused_lifetimes lint detects lifetime parameters that are never
used.
The unused_macros lint detects macros that were not used.
The unused_mut lint detects mut variables which don’t need to be
mutable.
The unused_qualifications lint detects unnecessarily qualified
names.
The unused_unsafe lint detects unnecessary use of an unsafe block.
The unused_variables lint detects variables which are not used in
any way.
The useless_deprecated lint detects deprecation attributes with no effect.
The warnings lint allows you to change the level of other
lints which produce warnings.
The where_clauses_object_safety lint detects for object safety of
where clauses.
The while_true lint detects while true { }.
Functions
Traverse through any amount of parenthesis and return the first non-parens expression.