Fix bugs; fix and add tests
This commit is contained in:
parent
d3f4c48b49
commit
50c1c27fa6
8 changed files with 110 additions and 87 deletions
|
@ -15,7 +15,7 @@ use rustc_hir::def::{DefKind, Res};
|
|||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_middle::mir::interpret::ConstValue;
|
||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||
use rustc_middle::ty::{self, DefIdTree, Ty};
|
||||
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use std::mem;
|
||||
|
||||
|
@ -624,3 +624,25 @@ where
|
|||
*cx.impl_trait_bounds.borrow_mut() = old_bounds;
|
||||
r
|
||||
}
|
||||
|
||||
crate fn find_closest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue