[−][src]Module rustc_lint::builtin

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

AnonymousParameters

Checks for use of anonymous parameters (RFC 1685).

BoxPointers
ClashingExternDeclarations
DeprecatedAttr

Check for use of attributes which have been deprecated.

EllipsisInclusiveRangePatterns
ExplicitOutlivesRequirements
HardwiredLints

Does nothing as a lint pass, but registers some Lints that are used by other parts of the compiler.

IncompleteFeatures

Check for used feature gates in INCOMPLETE_FEATURES in librustc_feature/active.rs.

InvalidNoMangleItems
InvalidValue
KeywordIdents

Check for uses of edition keywords used as an identifier.

MissingCopyImplementations
MissingDebugImplementations
MissingDoc
MutableTransmutes
NonShorthandFieldPatterns
SoftLints

Does nothing as a lint pass, but registers some Lints which are used by other parts of the compiler.

TrivialConstraints

Lint for trait and lifetime bounds that don't depend on type parameters which either do nothing, or stop the item from being used.

TypeAliasBounds

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.

UnderMacro
UnnameableTestItems
UnreachablePub

Lint for items marked pub that aren't reachable from other crates.

UnsafeCode
UnstableFeatures

Forbids using the #[feature(...)] attribute

UnusedBrokenConst

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.

UnusedDocComment
WhileTrue

Enums

SymbolName

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

HAS_MIN_FEATURES

Statics

ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE

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

AMBIGUOUS_ASSOCIATED_ITEMS

The ambiguous_associated_items lint detects ambiguity between associated items and enum variants.

ANONYMOUS_PARAMETERS

The anonymous_parameters lint detects anonymous parameters in trait definitions.

ARITHMETIC_OVERFLOW

The arithmetic_overflow lint detects that an arithmetic operation will overflow.

ASM_SUB_REGISTER

The asm_sub_register lint detects using only a subset of a register for inline asm inputs.

BARE_TRAIT_OBJECTS

The bare_trait_objects lint suggests using dyn Trait for trait objects.

BINDINGS_WITH_VARIANT_NAME

The bindings_with_variant_name lint detects pattern bindings with the same name as one of the matched variants.

BOX_POINTERS

The box_pointers lints use of the Box type.

BROKEN_INTRA_DOC_LINKS

The broken_intra_doc_links lint detects failures in resolving intra-doc link targets. This is a rustdoc only lint, see the documentation in the rustdoc book.

CENUM_IMPL_DROP_CAST

The cenum_impl_drop_cast lint detects an as cast of a field-less enum that implements Drop.

CLASHING_EXTERN_DECLARATIONS

The clashing_extern_declarations lint detects when an extern fn has been declared with the same name but different types.

COHERENCE_LEAK_CHECK

The coherence_leak_check lint detects conflicting implementations of a trait that are only distinguished by the old leak-check code.

CONFLICTING_REPR_HINTS

The conflicting_repr_hints lint detects repr attributes with conflicting hints.

CONST_ERR

The const_err lint detects an erroneous expression while doing constant evaluation.

CONST_EVALUATABLE_UNCHECKED

The const_evaluatable_unchecked lint detects a generic constant used in a type.

CONST_ITEM_MUTATION

The const_item_mutation lint detects attempts to mutate a const item.

DEAD_CODE

The dead_code lint detects unused, unexported items.

DEPRECATED

The deprecated lint detects use of deprecated items.

DEPRECATED_IN_FUTURE

The deprecated_in_future lint is internal to rustc and should not be used by user code.

ELIDED_LIFETIMES_IN_PATHS

The elided_lifetimes_in_paths lint detects the use of hidden lifetime parameters.

ELLIPSIS_INCLUSIVE_RANGE_PATTERNS

The ellipsis_inclusive_range_patterns lint detects the ... range pattern, which is deprecated.

EXPLICIT_OUTLIVES_REQUIREMENTS

The explicit_outlives_requirements lint detects unnecessary lifetime bounds that can be inferred.

EXPORTED_PRIVATE_DEPENDENCIES

The exported_private_dependencies lint detects private dependencies that are exposed in a public interface.

FUNCTION_ITEM_REFERENCES

The function_item_references lint detects function references that are formatted with fmt::Pointer or transmuted.

ILLEGAL_FLOATING_POINT_LITERAL_PATTERN

The illegal_floating_point_literal_pattern lint detects floating-point literals used in patterns.

ILL_FORMED_ATTRIBUTE_INPUT

The ill_formed_attribute_input lint detects ill-formed attribute inputs that were previously accepted and used in practice.

INCOMPLETE_FEATURES

The incomplete_features lint detects unstable features enabled with the feature attribute that may function improperly in some or all cases.

INCOMPLETE_INCLUDE

The incomplete_include lint detects the use of the include! macro with a file that contains more than one expression.

INDIRECT_STRUCTURAL_MATCH

The indirect_structural_match lint detects a const in a pattern that manually implements PartialEq and Eq.

INEFFECTIVE_UNSTABLE_TRAIT_IMPL
INLINE_NO_SANITIZE

The inline_no_sanitize lint detects incompatible use of #[inline(always)] and #[no_sanitize(...)].

INVALID_CODEBLOCK_ATTRIBUTES

The invalid_codeblock_attributes lint detects code block attributes in documentation examples that have potentially mis-typed values. This is a rustdoc only lint, see the documentation in the rustdoc book.

INVALID_HTML_TAGS

The invalid_html_tags lint detects invalid HTML tags. This is a rustdoc only lint, see the documentation in the rustdoc book.

INVALID_TYPE_PARAM_DEFAULT

The invalid_type_param_default lint detects type parameter defaults erroneously allowed in an invalid location.

INVALID_VALUE

The invalid_value lint detects creating a value that is not valid, such as a NULL reference.

IRREFUTABLE_LET_PATTERNS

The irrefutable_let_patterns lint detects detects irrefutable patterns in if-let and while-let statements.

KEYWORD_IDENTS

The keyword_idents lint detects edition keywords being used as an identifier.

LATE_BOUND_LIFETIME_ARGUMENTS

The late_bound_lifetime_arguments lint detects generic lifetime arguments in path segments with late bound lifetime parameters.

MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS

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.

MACRO_USE_EXTERN_CRATE

The macro_use_extern_crate lint detects the use of the macro_use attribute.

META_VARIABLE_MISUSE

The meta_variable_misuse lint detects possible meta-variable misuse in macro definitions.

MISSING_COPY_IMPLEMENTATIONS

The missing_copy_implementations lint detects potentially-forgotten implementations of Copy.

MISSING_CRATE_LEVEL_DOCS

The missing_crate_level_docs lint detects if documentation is missing at the crate root. This is a rustdoc only lint, see the documentation in the rustdoc book.

MISSING_DEBUG_IMPLEMENTATIONS

The missing_debug_implementations lint detects missing implementations of fmt::Debug.

MISSING_DOCS

The missing_docs lint detects missing documentation for public items.

MISSING_DOC_CODE_EXAMPLES

The missing_doc_code_examples lint detects publicly-exported items without code samples in their documentation. This is a rustdoc only lint, see the documentation in the rustdoc book.

MUTABLE_BORROW_RESERVATION_CONFLICT

The mutable_borrow_reservation_conflict lint detects the reservation of a two-phased borrow that conflicts with other shared borrows.

MUTABLE_TRANSMUTES

The mutable_transmutes lint catches transmuting from &T to &mut T because it is undefined behavior.

NONTRIVIAL_STRUCTURAL_MATCH

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.

NON_AUTOLINKS

The non_autolinks lint detects when a URL could be written using only angle brackets. This is a rustdoc only lint, see the documentation in the rustdoc book.

NON_SHORTHAND_FIELD_PATTERNS

The non_shorthand_field_patterns lint detects using Struct { x: x } instead of Struct { x } in a pattern.

NO_MANGLE_CONST_ITEMS

The no_mangle_const_items lint detects any const items with the no_mangle attribute.

NO_MANGLE_GENERIC_ITEMS

The no_mangle_generic_items lint detects generic items that must be mangled.

ORDER_DEPENDENT_TRAIT_OBJECTS

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.

OVERLAPPING_PATTERNS

The overlapping_patterns lint detects match arms that have range patterns that overlap.

PATTERNS_IN_FNS_WITHOUT_BODY

The patterns_in_fns_without_body lint detects mut identifier patterns as a parameter in functions without a body.

POINTER_STRUCTURAL_MATCH

The pointer_structural_match lint detects pointers used in patterns whose behaviour cannot be relied upon across compiler versions and optimization levels.

PRIVATE_DOC_TESTS

The private_doc_tests lint detects code samples in docs of private items not documented by rustdoc. This is a rustdoc only lint, see the documentation in the rustdoc book.

PRIVATE_INTRA_DOC_LINKS

This is a subset of broken_intra_doc_links that warns when linking from a public item to a private one. This is a rustdoc only lint, see the documentation in the rustdoc book.

PRIVATE_IN_PUBLIC

The private_in_public lint detects private items in public interfaces not caught by the old implementation.

PROC_MACRO_DERIVE_RESOLUTION_FALLBACK

The proc_macro_derive_resolution_fallback lint detects proc macro derives using inaccessible names from parent modules.

PUB_USE_OF_PRIVATE_EXTERN_CRATE

The pub_use_of_private_extern_crate lint detects a specific situation of re-exporting a private extern crate.

RENAMED_AND_REMOVED_LINTS

The renamed_and_removed_lints lint detects lints that have been renamed or removed.

SAFE_PACKED_BORROWS

The safe_packed_borrows lint detects borrowing a field in the interior of a packed structure with alignment other than 1.

SINGLE_USE_LIFETIMES

The single_use_lifetimes lint detects lifetimes that are only used once.

SOFT_UNSTABLE

The soft_unstable lint detects unstable features that were unintentionally allowed on stable.

STABLE_FEATURES

The stable_features lint detects a feature attribute that has since been made stable.

TRIVIAL_BOUNDS

The trivial_bounds lint detects trait bounds that don't depend on any type parameters.

TRIVIAL_CASTS

The trivial_casts lint detects trivial casts which could be replaced with coercion, which may require type ascription or a temporary variable.

TRIVIAL_NUMERIC_CASTS

The trivial_numeric_casts lint detects trivial numeric casts of types which could be removed.

TYPE_ALIAS_BOUNDS

The type_alias_bounds lint detects bounds in type aliases.

TYVAR_BEHIND_RAW_POINTER

The tyvar_behind_raw_pointer lint detects raw pointer to an inference variable.

UNALIGNED_REFERENCES

The unaligned_references lint detects unaligned references to fields of packed structs.

UNCONDITIONAL_PANIC

The unconditional_panic lint detects an operation that will cause a panic at runtime.

UNCONDITIONAL_RECURSION

The unconditional_recursion lint detects functions that cannot return without calling themselves.

UNINHABITED_STATIC

The uninhabited_static lint detects uninhabited statics.

UNKNOWN_CRATE_TYPES

The unknown_crate_types lint detects an unknown crate type found in a crate_type attribute.

UNKNOWN_LINTS

The unknown_lints lint detects unrecognized lint attribute.

UNNAMEABLE_TEST_ITEMS

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.

UNREACHABLE_CODE

The unreachable_code lint detects unreachable code paths.

UNREACHABLE_PATTERNS

The unreachable_patterns lint detects unreachable patterns.

UNREACHABLE_PUB

The unreachable_pub lint triggers for pub items not reachable from the crate root.

UNSAFE_CODE

The unsafe_code lint catches usage of unsafe code.

UNSAFE_OP_IN_UNSAFE_FN

The unsafe_op_in_unsafe_fn lint detects unsafe operations in unsafe functions without an explicit unsafe block. This lint only works on the nightly channel with the #![feature(unsafe_block_in_unsafe_fn)] feature.

UNSTABLE_FEATURES

The unstable_features is deprecated and should no longer be used.

UNSTABLE_NAME_COLLISIONS

The unstable_name_collisions lint detects that you have used a name that the standard library plans to add in the future.

UNUSED_ASSIGNMENTS

The unused_assignments lint detects assignments that will never be read.

UNUSED_ATTRIBUTES

The unused_attributes lint detects attributes that were not used by the compiler.

UNUSED_CRATE_DEPENDENCIES

The unused_crate_dependencies lint detects crate dependencies that are never used.

UNUSED_DOC_COMMENTS

The unused_doc_comments lint detects doc comments that aren't used by rustdoc.

UNUSED_EXTERN_CRATES

The unused_extern_crates lint guards against extern crate items that are never used.

UNUSED_FEATURES

The unused_features lint detects unused or unknown features found in crate-level feature attributes.

UNUSED_IMPORTS

The unused_imports lint detects imports that are never used.

UNUSED_LABELS

The unused_labels lint detects labels that are never used.

UNUSED_LIFETIMES

The unused_lifetimes lint detects lifetime parameters that are never used.

UNUSED_MACROS

The unused_macros lint detects macros that were not used.

UNUSED_MUT

The unused_mut lint detects mut variables which don't need to be mutable.

UNUSED_QUALIFICATIONS

The unused_qualifications lint detects unnecessarily qualified names.

UNUSED_UNSAFE

The unused_unsafe lint detects unnecessary use of an unsafe block.

UNUSED_VARIABLES

The unused_variables lint detects variables which are not used in any way.

USELESS_DEPRECATED

The useless_deprecated lint detects deprecation attributes with no effect.

WARNINGS

The warnings lint allows you to change the level of other lints which produce warnings.

WHERE_CLAUSES_OBJECT_SAFETY

The where_clauses_object_safety lint detects for object safety of where clauses.

WHILE_TRUE

The while_true lint detects while true { }.

Functions

has_doc
lint_deprecated_attr
pierce_parens

Traverse through any amount of parenthesis and return the first non-parens expression.

warn_if_doc