Skip to content

Commit 381bd2a

Browse files
committed
Revert "Auto merge of rust-lang#101862 - cjgillot:lint-regression, r=oli-obk"
This reverts commit bc7b17c, reversing changes made to 5253b0a.
1 parent 8ab71ab commit 381bd2a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct ParentHirIterator<'hir> {
6161
}
6262

6363
impl<'hir> Iterator for ParentHirIterator<'hir> {
64-
type Item = HirId;
64+
type Item = (HirId, Node<'hir>);
6565

6666
fn next(&mut self) -> Option<Self::Item> {
6767
if self.current_id == CRATE_HIR_ID {
@@ -77,7 +77,10 @@ impl<'hir> Iterator for ParentHirIterator<'hir> {
7777
}
7878

7979
self.current_id = parent_id;
80-
return Some(parent_id);
80+
if let Some(node) = self.map.find(parent_id) {
81+
return Some((parent_id, node));
82+
}
83+
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
8184
}
8285
}
8386
}
@@ -390,8 +393,8 @@ impl<'hir> Map<'hir> {
390393
}
391394

392395
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
393-
for (_, node) in self.parent_iter(hir_id) {
394-
if let Some(body) = associated_body(node) {
396+
for (parent, _) in self.parent_iter(hir_id) {
397+
if let Some(body) = self.find(parent).map(associated_body).flatten() {
395398
return self.body_owner_def_id(body);
396399
}
397400
}
@@ -632,17 +635,10 @@ impl<'hir> Map<'hir> {
632635
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
633636
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
634637
#[inline]
635-
pub fn parent_id_iter(self, current_id: HirId) -> impl Iterator<Item = HirId> + 'hir {
638+
pub fn parent_iter(self, current_id: HirId) -> ParentHirIterator<'hir> {
636639
ParentHirIterator { current_id, map: self }
637640
}
638641

639-
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
640-
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
641-
#[inline]
642-
pub fn parent_iter(self, current_id: HirId) -> impl Iterator<Item = (HirId, Node<'hir>)> {
643-
self.parent_id_iter(current_id).filter_map(move |id| Some((id, self.find(id)?)))
644-
}
645-
646642
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
647643
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
648644
#[inline]

compiler/rustc_middle/src/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl ShallowLintLevelMap {
126126
return (Some(level), src);
127127
}
128128

129-
for parent in tcx.hir().parent_id_iter(start) {
129+
for (parent, _) in tcx.hir().parent_iter(start) {
130130
let specs = tcx.shallow_lint_levels_on(parent);
131131
if let Some(&(level, src)) = specs.specs.get(&id) {
132132
return (Some(level), src);

0 commit comments

Comments
 (0)