Skip to content

Document how a lint level is resolved and emitted - #3068

Closed
isHeSatoshi wants to merge 1 commit into
rust-lang:mainfrom
isHeSatoshi:document-lint-emission
Closed

isHeSatoshi wants to merge 1 commit into
rust-lang:mainfrom
isHeSatoshi:document-lint-emission

Conversation

@isHeSatoshi

@isHeSatoshi isHeSatoshi commented Oct 19, 2026 •

Copy link
Copy Markdown

The page documented how lints are declared and registered, but not the step between "a lint pass reported this" and "the user sees it", which is what this issue asks about. --cap-lints in particular was not mentioned anywhere in the guide except a passing note in the editions guide.

What the new section covers, and where each claim comes from

All of it was read out of current main rather than reconstructed:

  • Where levels are recorded. LintLevelsBuilder produces a ShallowLintLevelMap per HIR owner, mapping a node to the levels written directly on it. Command-line levels go into the COMMAND_LINE entry of LintLevelSets instead, and get_cmd_lint_options (compiler/rustc_session/src/config.rs) sorts them by command-line position, so a later flag wins.
  • Resolving a level for a node. ShallowLintLevelMap::lint_level_spec_at_node walks up the HIR parent chain and takes the first explicit setting, so the innermost attribute wins; raw_lint_level_spec then falls back to the command line, and reveal_actual_level_spec falls back to the lint's own default_level. The result carries a LintLevelSource (Default, Node { name, span, reason }, or CommandLine), which is where the "this lint is allowed by an attribute" explanations come from.
  • The warnings group. reveal_actual_level_spec lets a configured warnings level take over when the lint is about to warn, with the ignore_deny_warnings exception, which is why -Awarnings works but some warnings can only be denied individually.
  • --cap-lints. level_spec.level = min(level_spec.level, sess.opts.lint_cap.unwrap_or(Level::Forbid)), i.e. a minimum against the cap, with Level ordered Allow < Expect < Warn < ForceWarn < Deny < Forbid. The default cap is Forbid (no cap), and a command-line --force-warn is exempt.
  • Driver caps. Session::driver_lint_caps is applied the same way, which is how a driver caps lints without touching the command line.
  • What emits. Allow and Expect produce no message (Expect records the expectation so unfulfilled_lint_expectations can fire later), the other four emit.

Notes for reviewers

  • I linked the two functions that have no rustdoc page (get_cmd_lint_options, reveal_actual_level_spec) to their files rather than inventing doc URLs.
  • The two 404s already in this file's link list (declare_lint!, declare_tool_lint!) are pre-existing and unrelated; I left them alone rather than mix a link fix into this change. declare_lint moves to rustc_lint_defs in Fix the dead links reported by the scheduled link check #3057, which touches this same file, and git merge-tree reports no conflict between the two.
  • This is a "how it works" section, so if you would rather it live in the diagnostics chapter than in lintstore.md, say so and I will move it.

Fixes #1168.

The page explained how lints are declared and registered, but not how the
compiler decides whether a lint that a pass reported is actually shown.

Add a section covering the level resolution: the shallow per-owner map the
builder produces from attributes, the walk up the HIR parent chain, the
command-line levels, the lint's default level, the `warnings` group,
`--cap-lints` and driver caps, and finally which levels emit and which do not.
@rustbot

rustbot commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR. If you have write access, feel free to merge this PR if it does not need reviews. You can request a review using r? rustc-dev-guide or r? <username>.

@rustbot rustbot added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Oct 19, 2026
@isHeSatoshi

This comment was marked as low quality.

@BoxyUwU BoxyUwU closed this Oct 19, 2026
@rustbot rustbot removed the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document how lints are actually emitted

4 participants