From 5b5964f569ca07ba54710cb440aacaa1cf1e5c1a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 25 Apr 2022 22:08:45 +0300 Subject: 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`. --- compiler/rustc_lint/src/types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_lint/src') diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 437104d1aaf..dfce30171ff 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1471,7 +1471,7 @@ impl InvalidAtomicOrdering { && let Some(adt) = cx.tcx.type_of(impl_did).ty_adt_def() // skip extension traits, only lint functions from the standard library && cx.tcx.trait_id_of_impl(impl_did).is_none() - && let Some(parent) = cx.tcx.parent(adt.did()) + && let parent = cx.tcx.parent(adt.did()) && cx.tcx.is_diagnostic_item(sym::atomic_mod, parent) && ATOMIC_TYPES.contains(&cx.tcx.item_name(adt.did())) { @@ -1486,9 +1486,9 @@ impl InvalidAtomicOrdering { orderings.iter().any(|ordering| { tcx.item_name(did) == *ordering && { let parent = tcx.parent(did); - parent == atomic_ordering + Some(parent) == atomic_ordering // needed in case this is a ctor, not a variant - || parent.map_or(false, |parent| tcx.parent(parent) == atomic_ordering) + || tcx.opt_parent(parent) == atomic_ordering } }) } -- cgit 1.4.1-3-g733a5