Skip to content

Commit

Permalink
Auto merge of rust-lang#102236 - cjgillot:compute_lint_levels_by_def,…
Browse files Browse the repository at this point in the history
… r=oli-obk

Compute lint levels by definition

Second attempt to rust-lang#101620.

I think that I have removed the perf regression.
  • Loading branch information
bors committed Oct 1, 2022
2 parents 56a35bc + fec53fd commit 57f097e
Show file tree
Hide file tree
Showing 17 changed files with 791 additions and 499 deletions.
17 changes: 17 additions & 0 deletions compiler/rustc_data_structures/src/sorted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ impl<K: Ord, V> SortedMap<K, V> {
}
}

/// Gets a mutable reference to the value in the entry, or insert a new one.
#[inline]
pub fn get_mut_or_insert_default(&mut self, key: K) -> &mut V
where
K: Eq,
V: Default,
{
let index = match self.lookup_index_for(&key) {
Ok(index) => index,
Err(index) => {
self.data.insert(index, (key, V::default()));
index
}
};
unsafe { &mut self.data.get_unchecked_mut(index).1 }
}

#[inline]
pub fn clear(&mut self) {
self.data.clear();
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,10 @@ impl Diagnostic {
// The lint index inside the attribute is manually transferred here.
let lint_index = expectation_id.get_lint_index();
expectation_id.set_lint_index(None);
let mut stable_id = *unstable_to_stable
let mut stable_id = unstable_to_stable
.get(&expectation_id)
.expect("each unstable `LintExpectationId` must have a matching stable id");
.expect("each unstable `LintExpectationId` must have a matching stable id")
.normalize();

stable_id.set_lint_index(lint_index);
*expectation_id = stable_id;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ impl HandlerInner {

if let Some(expectation_id) = diagnostic.level.get_expectation_id() {
self.suppressed_expected_diag = true;
self.fulfilled_expectations.insert(expectation_id);
self.fulfilled_expectations.insert(expectation_id.normalize());
}

if matches!(diagnostic.level, Warning(_))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ pub struct LateContext<'tcx> {

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

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
F: FnOnce(&mut Self),
{
let is_crate_node = id == ast::CRATE_NODE_ID;
debug!(?id);
let push = self.context.builder.push(attrs, is_crate_node, None);

self.check_id(id);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
return;
}

let lint_expectations = tcx.lint_expectations(());
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
let lint_expectations = &tcx.lint_levels(()).lint_expectations;

tracing::debug!(?lint_expectations, ?fulfilled_expectations);

for (id, expectation) in lint_expectations {
// This check will always be true, since `lint_expectations` only
Expand Down
Loading

0 comments on commit 57f097e

Please sign in to comment.