diff options
| author | bors <bors@rust-lang.org> | 2022-09-18 00:46:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-18 00:46:14 +0000 |
| commit | bc7b17cfe3bf08b618d1c7b64838053faeb1f590 (patch) | |
| tree | 2e843ccff581c0eaaf21b293912eeaca4c8a4775 | |
| parent | 5253b0a0a1f366fad0ebed57597fcf2703b9e893 (diff) | |
| parent | c9c6c507b785ea74a69fc716ac1512283bdb76e3 (diff) | |
| download | rust-bc7b17cfe3bf08b618d1c7b64838053faeb1f590.tar.gz rust-bc7b17cfe3bf08b618d1c7b64838053faeb1f590.zip | |
Auto merge of #101862 - cjgillot:lint-regression, r=oli-obk
Do not fetch HIR node when iterating to find lint. Addresses the regression in https://github.com/rust-lang/rust/pull/101620
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/lint.rs | 2 |
2 files changed, 13 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 30a23c342b3..ca5598f5ff1 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -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 @@ impl<'hir> Iterator for ParentHirIterator<'hir> { } 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 @@ impl<'hir> Map<'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,13 +632,20 @@ impl<'hir> Map<'hir> { /// 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] pub fn parent_owner_iter(self, current_id: HirId) -> ParentOwnerIterator<'hir> { ParentOwnerIterator { current_id, map: self } } diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 4cb5ef79177..bb9e1edf86c 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -126,7 +126,7 @@ impl ShallowLintLevelMap { 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); |
