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:
parent
a933de8398
commit
5b5964f569
50 changed files with 162 additions and 176 deletions
|
@ -341,7 +341,7 @@ impl InferenceDiagnosticsData {
|
|||
|
||||
impl InferenceDiagnosticsParentData {
|
||||
fn for_def_id(tcx: TyCtxt<'_>, def_id: DefId) -> Option<InferenceDiagnosticsParentData> {
|
||||
let parent_def_id = tcx.parent(def_id)?;
|
||||
let parent_def_id = tcx.parent(def_id);
|
||||
|
||||
let parent_name =
|
||||
tcx.def_key(parent_def_id).disambiguated_data.data.get_opt_name()?.to_string();
|
||||
|
@ -854,10 +854,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
if let Some((DefKind::AssocFn, def_id)) =
|
||||
self.in_progress_typeck_results?.borrow().type_dependent_def(hir_id)
|
||||
{
|
||||
return self
|
||||
.tcx
|
||||
.parent(def_id)
|
||||
.filter(|&parent_def_id| self.tcx.is_trait(parent_def_id));
|
||||
let parent_def_id = self.tcx.parent(def_id);
|
||||
return self.tcx.is_trait(parent_def_id).then_some(parent_def_id);
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
@ -42,7 +42,7 @@ pub fn find_param_with_region<'tcx>(
|
|||
let (id, bound_region) = match *anon_region {
|
||||
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
||||
ty::ReEarlyBound(ebr) => {
|
||||
(tcx.parent(ebr.def_id).unwrap(), ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name))
|
||||
(tcx.parent(ebr.def_id), ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name))
|
||||
}
|
||||
_ => return None, // not a free region
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue