Repository navigation
Document how a lint level is resolved and emitted - #3068
Closed
isHeSatoshi wants to merge 1 commit into
Closed
isHeSatoshi wants to merge 1 commit into
isHeSatoshi wants to merge 1 commit into
Conversation
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.
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 |
This comment was marked as low quality.
This comment was marked as low quality.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-lintsin 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
mainrather than reconstructed:LintLevelsBuilderproduces aShallowLintLevelMapper HIR owner, mapping a node to the levels written directly on it. Command-line levels go into theCOMMAND_LINEentry ofLintLevelSetsinstead, andget_cmd_lint_options(compiler/rustc_session/src/config.rs) sorts them by command-line position, so a later flag wins.ShallowLintLevelMap::lint_level_spec_at_nodewalks up the HIR parent chain and takes the first explicit setting, so the innermost attribute wins;raw_lint_level_specthen falls back to the command line, andreveal_actual_level_specfalls back to the lint's owndefault_level. The result carries aLintLevelSource(Default,Node { name, span, reason }, orCommandLine), which is where the "this lint isallowed by an attribute" explanations come from.warningsgroup.reveal_actual_level_speclets a configuredwarningslevel take over when the lint is about to warn, with theignore_deny_warningsexception, which is why-Awarningsworks 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, withLevelorderedAllow < Expect < Warn < ForceWarn < Deny < Forbid. The default cap isForbid(no cap), and a command-line--force-warnis exempt.Session::driver_lint_capsis applied the same way, which is how a driver caps lints without touching the command line.AllowandExpectproduce no message (Expectrecords the expectation sounfulfilled_lint_expectationscan fire later), the other four emit.Notes for reviewers
get_cmd_lint_options,reveal_actual_level_spec) to their files rather than inventing doc URLs.declare_lint!,declare_tool_lint!) are pre-existing and unrelated; I left them alone rather than mix a link fix into this change.declare_lintmoves torustc_lint_defsin Fix the dead links reported by the scheduled link check #3057, which touches this same file, andgit merge-treereports no conflict between the two.lintstore.md, say so and I will move it.Fixes #1168.