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:
@@ -690,7 +690,7 @@ impl<'tcx> SaveContext<'tcx> {
|
||||
// This is a reference to a tuple struct or an enum variant where the def_id points
|
||||
// to an invisible constructor function. That is not a very useful
|
||||
// def, so adjust to point to the tuple struct or enum variant itself.
|
||||
let parent_def_id = self.tcx.parent(def_id).unwrap();
|
||||
let parent_def_id = self.tcx.parent(def_id);
|
||||
Some(Ref { kind: RefKind::Type, span, ref_id: id_from_def_id(parent_def_id) })
|
||||
}
|
||||
Res::Def(HirDefKind::Static(_) | HirDefKind::Const | HirDefKind::AssocConst, _) => {
|
||||
|
||||
Reference in New Issue
Block a user