Skip to content

Commit f234dc3

Browse files
committed
Move maybe_lint_level_root_bounded.
From `TyCtxt` to the MIR `Builder`. This will allow us to add a cache to `Builder` and use it from `maybe_lint_level_root_bounded`.
1 parent 3645810 commit f234dc3

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

compiler/rustc_middle/src/lint.rs

-20
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,6 @@ impl TyCtxt<'_> {
169169
pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintLevelSource) {
170170
self.shallow_lint_levels_on(id.owner).lint_level_id_at_node(self, LintId::of(lint), id)
171171
}
172-
173-
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
174-
/// It stops at `bound` and just returns it if reached.
175-
pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
176-
let hir = self.hir();
177-
loop {
178-
if id == bound {
179-
return bound;
180-
}
181-
182-
if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
183-
return id;
184-
}
185-
let next = hir.parent_id(id);
186-
if next == id {
187-
bug!("lint traversal reached the root of the crate");
188-
}
189-
id = next;
190-
}
191-
}
192172
}
193173

194174
/// This struct represents a lint expectation and holds all required information

compiler/rustc_mir_build/src/build/scope.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ use rustc_index::{IndexSlice, IndexVec};
9090
use rustc_middle::middle::region;
9191
use rustc_middle::mir::*;
9292
use rustc_middle::thir::{Expr, LintLevel};
93-
9493
use rustc_middle::ty::Ty;
94+
use rustc_session::lint::Level;
9595
use rustc_span::{Span, DUMMY_SP};
9696

9797
#[derive(Debug)]
@@ -773,8 +773,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
773773
// to avoid adding Hir dependencies on our parents.
774774
// We estimate the true lint roots here to avoid creating a lot of source scopes.
775775
(
776-
self.tcx.maybe_lint_level_root_bounded(current_id, self.hir_id),
777-
self.tcx.maybe_lint_level_root_bounded(parent_id, self.hir_id),
776+
self.maybe_lint_level_root_bounded(current_id, self.hir_id),
777+
self.maybe_lint_level_root_bounded(parent_id, self.hir_id),
778778
)
779779
};
780780

@@ -784,6 +784,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
784784
}
785785
}
786786

787+
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
788+
/// It stops at `bound` and just returns it if reached.
789+
fn maybe_lint_level_root_bounded(&self, mut id: HirId, bound: HirId) -> HirId {
790+
let hir = self.tcx.hir();
791+
loop {
792+
if id == bound {
793+
return bound;
794+
}
795+
796+
if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
797+
return id;
798+
}
799+
800+
let next = hir.parent_id(id);
801+
if next == id {
802+
bug!("lint traversal reached the root of the crate");
803+
}
804+
id = next;
805+
}
806+
}
807+
787808
/// Creates a new source scope, nested in the current one.
788809
pub(crate) fn new_source_scope(
789810
&mut self,

0 commit comments

Comments
 (0)