Module rustc_lint::builtin

source ·
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 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



  • InitKind 🔒
  • 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.