Skip to content

Commit 57f097e

Browse files
committed
Auto merge of #102236 - cjgillot:compute_lint_levels_by_def, r=oli-obk
Compute lint levels by definition Second attempt to #101620. I think that I have removed the perf regression.
2 parents 56a35bc + fec53fd commit 57f097e

File tree

17 files changed

+791
-499
lines changed

17 files changed

+791
-499
lines changed

compiler/rustc_data_structures/src/sorted_map.rs

+17
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,23 @@ impl<K: Ord, V> SortedMap<K, V> {
9696
}
9797
}
9898

99+
/// Gets a mutable reference to the value in the entry, or insert a new one.
100+
#[inline]
101+
pub fn get_mut_or_insert_default(&mut self, key: K) -> &mut V
102+
where
103+
K: Eq,
104+
V: Default,
105+
{
106+
let index = match self.lookup_index_for(&key) {
107+
Ok(index) => index,
108+
Err(index) => {
109+
self.data.insert(index, (key, V::default()));
110+
index
111+
}
112+
};
113+
unsafe { &mut self.data.get_unchecked_mut(index).1 }
114+
}
115+
99116
#[inline]
100117
pub fn clear(&mut self) {
101118
self.data.clear();

compiler/rustc_errors/src/diagnostic.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,10 @@ impl Diagnostic {
364364
// The lint index inside the attribute is manually transferred here.
365365
let lint_index = expectation_id.get_lint_index();
366366
expectation_id.set_lint_index(None);
367-
let mut stable_id = *unstable_to_stable
367+
let mut stable_id = unstable_to_stable
368368
.get(&expectation_id)
369-
.expect("each unstable `LintExpectationId` must have a matching stable id");
369+
.expect("each unstable `LintExpectationId` must have a matching stable id")
370+
.normalize();
370371

371372
stable_id.set_lint_index(lint_index);
372373
*expectation_id = stable_id;

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ impl HandlerInner {
12111211

12121212
if let Some(expectation_id) = diagnostic.level.get_expectation_id() {
12131213
self.suppressed_expected_diag = true;
1214-
self.fulfilled_expectations.insert(expectation_id);
1214+
self.fulfilled_expectations.insert(expectation_id.normalize());
12151215
}
12161216

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

compiler/rustc_lint/src/context.rs

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

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

compiler/rustc_lint/src/early.rs

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

6364
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)