Skip to content

Commit 2cb9a65

Browse files
committed
Auto merge of rust-lang#101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk
Compute lint levels by definition Lint levels are currently computed once for the whole crate. Any code that wants to emit a lint depends on this single `lint_levels(())` query. This query contains the `Span` for each attribute that participates in the lint level tree, so any code that wants to emit a lint basically depends on the spans in all files in the crate. Contrary to hard errors, we do not clear the incremental session on lints, so this implicit world dependency pessimizes incremental reuse. (And is furthermore invisible for allowed lints.) This PR completes rust-lang#99634 (thanks for the initial work `@fee1-dead)` and includes it in the dependency graph. The design is based on 2 queries: 1. `lint_levels_on(HirId) -> FxHashMap<LintId, LevelAndSource>` which accesses the attributes at the given `HirId` and processes them into lint levels. The `TyCtxt` is responsible for probing the HIR tree to find the user-visible level. 2. `lint_expectations(())` which lists all the `#[expect]` attributes in the crate. This PR also introduces the ability to reconstruct a `HirId` from a `DepNode` by encoding the local part of the `DefPathHash` and the `ItemLocalId` in the two `u64` of the fingerprint. This allows for the dep-graph to directly recompute `lint_levels_on` directly, without having to force the calling query. Closes rust-lang#95094. Supersedes rust-lang#99634.
2 parents 750bd1a + 42a92eb commit 2cb9a65

File tree

18 files changed

+670
-488
lines changed

18 files changed

+670
-488
lines changed

compiler/rustc_errors/src/diagnostic.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ impl Diagnostic {
338338
// The lint index inside the attribute is manually transferred here.
339339
let lint_index = expectation_id.get_lint_index();
340340
expectation_id.set_lint_index(None);
341-
let mut stable_id = *unstable_to_stable
341+
let mut stable_id = unstable_to_stable
342342
.get(&expectation_id)
343-
.expect("each unstable `LintExpectationId` must have a matching stable id");
343+
.expect("each unstable `LintExpectationId` must have a matching stable id")
344+
.normalize();
344345

345346
stable_id.set_lint_index(lint_index);
346347
*expectation_id = stable_id;

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ impl HandlerInner {
11671167

11681168
if let Some(expectation_id) = diagnostic.level.get_expectation_id() {
11691169
self.suppressed_expected_diag = true;
1170-
self.fulfilled_expectations.insert(expectation_id);
1170+
self.fulfilled_expectations.insert(expectation_id.normalize());
11711171
}
11721172

11731173
if matches!(diagnostic.level, Warning(_))

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ pub struct LateContext<'tcx> {
560560

561561
/// Context for lint checking of the AST, after expansion, before lowering to HIR.
562562
pub struct EarlyContext<'a> {
563-
pub builder: LintLevelsBuilder<'a>,
563+
pub builder: LintLevelsBuilder<'a, crate::levels::TopDown>,
564564
pub buffered: LintBuffer,
565565
}
566566

compiler/rustc_lint/src/early.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
5959
F: FnOnce(&mut Self),
6060
{
6161
let is_crate_node = id == ast::CRATE_NODE_ID;
62+
debug!(?id);
6263
let push = self.context.builder.push(attrs, is_crate_node, None);
6364

6465
self.check_id(id);

compiler/rustc_lint/src/expect.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
1616
return;
1717
}
1818

19+
let lint_expectations = tcx.lint_expectations(());
1920
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
20-
let lint_expectations = &tcx.lint_levels(()).lint_expectations;
21+
22+
tracing::debug!(?lint_expectations, ?fulfilled_expectations);
2123

2224
for (id, expectation) in lint_expectations {
2325
// This check will always be true, since `lint_expectations` only

0 commit comments

Comments
 (0)