1
Fork 0

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`.
This commit is contained in:
Nicholas Nethercote 2023-07-11 22:07:28 +10:00
parent 36458109ae
commit f234dc3e1c
2 changed files with 24 additions and 23 deletions

View file

@ -169,26 +169,6 @@ impl TyCtxt<'_> {
pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintLevelSource) {
self.shallow_lint_levels_on(id.owner).lint_level_id_at_node(self, LintId::of(lint), id)
}
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
/// It stops at `bound` and just returns it if reached.
pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
let hir = self.hir();
loop {
if id == bound {
return bound;
}
if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
return id;
}
let next = hir.parent_id(id);
if next == id {
bug!("lint traversal reached the root of the crate");
}
id = next;
}
}
}
/// This struct represents a lint expectation and holds all required information