Simplify loop and remove old debugging code

Co-authored-by: Joshua Nelson <jyn514@gmail.com>
This commit is contained in:
Camelid 2020-12-25 16:35:28 -08:00
parent 4b1b277cf9
commit eaf851288e

View file

@ -636,21 +636,12 @@ crate fn find_closest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<De
let mut current = def_id;
// The immediate parent might not always be a module.
// Find the first parent which is.
loop {
if let Some(parent) = tcx.parent(current) {
if tcx.def_kind(parent) == DefKind::Mod {
break Some(parent);
}
current = parent;
} else {
debug!(
"{:?} has no parent (kind={:?}, original was {:?})",
current,
tcx.def_kind(current),
def_id
);
break None;
while let Some(parent) = tcx.parent(current) {
if tcx.def_kind(parent) == DefKind::Mod {
return Some(parent);
}
current = parent;
}
None
}
}