Do not fetch HIR node when iterating to find lint.
This commit is contained in:
parent
2cb9a65684
commit
c9c6c507b7
@ -61,7 +61,7 @@ pub struct ParentHirIterator<'hir> {
|
||||
}
|
||||
|
||||
impl<'hir> Iterator for ParentHirIterator<'hir> {
|
||||
type Item = (HirId, Node<'hir>);
|
||||
type Item = HirId;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.current_id == CRATE_HIR_ID {
|
||||
@ -77,10 +77,7 @@ fn next(&mut self) -> Option<Self::Item> {
|
||||
}
|
||||
|
||||
self.current_id = parent_id;
|
||||
if let Some(node) = self.map.find(parent_id) {
|
||||
return Some((parent_id, node));
|
||||
}
|
||||
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
|
||||
return Some(parent_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,8 +390,8 @@ pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
|
||||
}
|
||||
|
||||
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
|
||||
for (parent, _) in self.parent_iter(hir_id) {
|
||||
if let Some(body) = self.find(parent).map(associated_body).flatten() {
|
||||
for (_, node) in self.parent_iter(hir_id) {
|
||||
if let Some(body) = associated_body(node) {
|
||||
return self.body_owner_def_id(body);
|
||||
}
|
||||
}
|
||||
@ -635,10 +632,17 @@ pub fn par_for_each_module(self, f: impl Fn(LocalDefId) + Sync + Send) {
|
||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
|
||||
#[inline]
|
||||
pub fn parent_iter(self, current_id: HirId) -> ParentHirIterator<'hir> {
|
||||
pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'hir {
|
||||
ParentHirIterator { current_id, map: self }
|
||||
}
|
||||
|
||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
|
||||
#[inline]
|
||||
pub fn parent_iter(self, current_id: HirId) -> impl Iterator<Item = (HirId, Node<'hir>)> {
|
||||
self.parent_id_iter(current_id).filter_map(move |id| Some((id, self.find(id)?)))
|
||||
}
|
||||
|
||||
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
|
||||
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
|
||||
#[inline]
|
||||
|
@ -126,7 +126,7 @@ fn probe_for_lint_level(
|
||||
return (Some(level), src);
|
||||
}
|
||||
|
||||
for (parent, _) in tcx.hir().parent_iter(start) {
|
||||
for parent in tcx.hir().parent_id_iter(start) {
|
||||
let specs = tcx.shallow_lint_levels_on(parent);
|
||||
if let Some(&(level, src)) = specs.specs.get(&id) {
|
||||
return (Some(level), src);
|
||||
|
Loading…
Reference in New Issue
Block a user