rustc: Panic by default in DefIdTree::parent

Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
This commit is contained in:
Vadim Petrochenkov 2022-04-25 22:08:45 +03:00
parent a933de8398
commit 5b5964f569
50 changed files with 162 additions and 176 deletions

View file

@ -1109,7 +1109,8 @@ impl<'a> AsMut<Resolver<'a>> for Resolver<'a> {
}
impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
fn parent(self, id: DefId) -> Option<DefId> {
#[inline]
fn opt_parent(self, id: DefId) -> Option<DefId> {
match id.as_local() {
Some(id) => self.definitions.def_key(id).parent,
None => self.cstore().def_key(id).parent,