Skip to content

Commit 6006472

Browse files
committed
Return a LocalDefId in get_parent_item.
1 parent 5a123c2 commit 6006472

File tree

51 files changed

+151
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+151
-140
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
896896
if look_at_return && hir.get_return_block(closure_id).is_some() {
897897
// ...otherwise we are probably in the tail expression of the function, point at the
898898
// return type.
899-
match hir.get(hir.get_parent_item(fn_call_id)) {
899+
match hir.get_by_def_id(hir.get_parent_item(fn_call_id)) {
900900
hir::Node::Item(hir::Item { ident, kind: hir::ItemKind::Fn(sig, ..), .. })
901901
| hir::Node::TraitItem(hir::TraitItem {
902902
ident,

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
704704
hir::AsyncGeneratorKind::Block => " of async block",
705705
hir::AsyncGeneratorKind::Closure => " of async closure",
706706
hir::AsyncGeneratorKind::Fn => {
707-
let parent_item = hir.get(hir.get_parent_item(mir_hir_id));
707+
let parent_item = hir.get_by_def_id(hir.get_parent_item(mir_hir_id));
708708
let output = &parent_item
709709
.fn_decl()
710710
.expect("generator lowered from async fn should be in fn")

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,9 +2212,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22122212
if let Some(Node::Item(Item {
22132213
kind: ItemKind::Trait(..) | ItemKind::Impl { .. },
22142214
..
2215-
})) = hir.find(parent_id)
2215+
})) = hir.find_by_def_id(parent_id)
22162216
{
2217-
Some(self.tcx.generics_of(hir.local_def_id(parent_id).to_def_id()))
2217+
Some(self.tcx.generics_of(parent_id))
22182218
} else {
22192219
None
22202220
},

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
187187
| ObligationCauseCode::BlockTailExpression(hir_id) = cause.code()
188188
{
189189
let parent_id = tcx.hir().get_parent_item(*hir_id);
190+
let parent_id = tcx.hir().local_def_id_to_hir_id(parent_id);
190191
if let Some(fn_decl) = tcx.hir().fn_decl_by_hir_id(parent_id) {
191192
let mut span: MultiSpan = fn_decl.output.span().into();
192193
let mut add_label = true;
@@ -425,7 +426,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
425426
let tcx = self.tcx();
426427
match tcx.hir().get_if_local(def_id) {
427428
Some(Node::ImplItem(impl_item)) => {
428-
match tcx.hir().find(tcx.hir().get_parent_item(impl_item.hir_id())) {
429+
match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id())) {
429430
Some(Node::Item(Item {
430431
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
431432
..
@@ -434,13 +435,13 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
434435
}
435436
}
436437
Some(Node::TraitItem(trait_item)) => {
437-
let parent_id = tcx.hir().get_parent_item(trait_item.hir_id());
438-
match tcx.hir().find(parent_id) {
438+
let trait_did = tcx.hir().get_parent_item(trait_item.hir_id());
439+
match tcx.hir().find_by_def_id(trait_did) {
439440
Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
440441
// The method being called is defined in the `trait`, but the `'static`
441442
// obligation comes from the `impl`. Find that `impl` so that we can point
442443
// at it in the suggestion.
443-
let trait_did = tcx.hir().local_def_id(parent_id).to_def_id();
444+
let trait_did = trait_did.to_def_id();
444445
match tcx
445446
.hir()
446447
.trait_impls(trait_did)

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ fn may_define_opaque_type(tcx: TyCtxt<'_>, def_id: LocalDefId, opaque_hir_id: hi
635635
let scope = tcx.hir().get_defining_scope(opaque_hir_id);
636636
// We walk up the node tree until we hit the root or the scope of the opaque type.
637637
while hir_id != scope && hir_id != hir::CRATE_HIR_ID {
638-
hir_id = tcx.hir().get_parent_item(hir_id);
638+
hir_id = tcx.hir().local_def_id_to_hir_id(tcx.hir().get_parent_item(hir_id));
639639
}
640640
// Syntactically, we are allowed to define the concrete type if:
641641
let res = hir_id == scope;

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
656656

657657
// If the method is an impl for an item with docs_hidden, don't doc.
658658
if method_context(cx, impl_item.hir_id()) == MethodLateContext::PlainImpl {
659-
let parent = cx.tcx.hir().get_parent_did(impl_item.hir_id());
659+
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id());
660660
let impl_ty = cx.tcx.type_of(parent);
661661
let outerdef = match impl_ty.kind() {
662662
ty::Adt(def, _) => Some(def.did),

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ pub struct ParentOwnerIterator<'hir> {
117117
}
118118

119119
impl<'hir> Iterator for ParentOwnerIterator<'hir> {
120-
type Item = (HirId, OwnerNode<'hir>);
120+
type Item = (LocalDefId, OwnerNode<'hir>);
121121

122122
fn next(&mut self) -> Option<Self::Item> {
123123
if self.current_id.local_id.index() != 0 {
124124
self.current_id.local_id = ItemLocalId::new(0);
125125
if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
126-
return Some((self.current_id, node.node));
126+
return Some((self.current_id.owner, node.node));
127127
}
128128
}
129129
if self.current_id == CRATE_HIR_ID {
@@ -141,7 +141,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
141141

142142
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
143143
if let Some(node) = self.map.tcx.hir_owner(self.current_id.owner) {
144-
return Some((self.current_id, node.node));
144+
return Some((self.current_id.owner, node.node));
145145
}
146146
}
147147
}
@@ -340,11 +340,23 @@ impl<'hir> Map<'hir> {
340340
}
341341
}
342342

343+
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
344+
#[inline]
345+
pub fn find_by_def_id(&self, id: LocalDefId) -> Option<Node<'hir>> {
346+
self.find(self.local_def_id_to_hir_id(id))
347+
}
348+
343349
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
344350
pub fn get(&self, id: HirId) -> Node<'hir> {
345351
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
346352
}
347353

354+
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
355+
#[inline]
356+
pub fn get_by_def_id(&self, id: LocalDefId) -> Node<'hir> {
357+
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
358+
}
359+
348360
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
349361
id.as_local().and_then(|id| self.find(self.local_def_id_to_hir_id(id)))
350362
}
@@ -780,23 +792,23 @@ impl<'hir> Map<'hir> {
780792
/// parent item is in this map. The "parent item" is the closest parent node
781793
/// in the HIR which is recorded by the map and is an item, either an item
782794
/// in a module, trait, or impl.
783-
pub fn get_parent_item(&self, hir_id: HirId) -> HirId {
784-
if let Some((hir_id, _node)) = self.parent_owner_iter(hir_id).next() {
785-
hir_id
795+
pub fn get_parent_item(&self, hir_id: HirId) -> LocalDefId {
796+
if let Some((def_id, _node)) = self.parent_owner_iter(hir_id).next() {
797+
def_id
786798
} else {
787-
CRATE_HIR_ID
799+
CRATE_DEF_ID
788800
}
789801
}
790802

791803
/// Returns the `HirId` of `id`'s nearest module parent, or `id` itself if no
792804
/// module parent is in this map.
793-
pub(super) fn get_module_parent_node(&self, hir_id: HirId) -> HirId {
794-
for (hir_id, node) in self.parent_owner_iter(hir_id) {
805+
pub(super) fn get_module_parent_node(&self, hir_id: HirId) -> LocalDefId {
806+
for (def_id, node) in self.parent_owner_iter(hir_id) {
795807
if let OwnerNode::Item(&Item { kind: ItemKind::Mod(_), .. }) = node {
796-
return hir_id;
808+
return def_id;
797809
}
798810
}
799-
CRATE_HIR_ID
811+
CRATE_DEF_ID
800812
}
801813

802814
/// When on an if expression, a match arm tail expression or a match arm, give back
@@ -859,19 +871,18 @@ impl<'hir> Map<'hir> {
859871
}
860872
}
861873

862-
pub fn get_parent_did(&self, id: HirId) -> LocalDefId {
863-
self.local_def_id(self.get_parent_item(id))
864-
}
865-
866874
pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi {
867875
let parent = self.get_parent_item(hir_id);
868-
if let Some(node) = self.tcx.hir_owner(self.local_def_id(parent)) {
876+
if let Some(node) = self.tcx.hir_owner(parent) {
869877
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = node.node
870878
{
871879
return *abi;
872880
}
873881
}
874-
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
882+
bug!(
883+
"expected foreign mod or inlined parent, found {}",
884+
self.node_to_string(HirId::make_owner(parent))
885+
)
875886
}
876887

877888
pub fn expect_item(&self, id: LocalDefId) -> &'hir Item<'hir> {
@@ -929,7 +940,7 @@ impl<'hir> Map<'hir> {
929940
Node::Lifetime(lt) => lt.name.ident().name,
930941
Node::GenericParam(param) => param.name.ident().name,
931942
Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name,
932-
Node::Ctor(..) => self.name(self.get_parent_item(id)),
943+
Node::Ctor(..) => self.name(HirId::make_owner(self.get_parent_item(id))),
933944
_ => return None,
934945
})
935946
}

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> TyCtxt<'tcx> {
5858
pub fn provide(providers: &mut Providers) {
5959
providers.parent_module_from_def_id = |tcx, id| {
6060
let hir = tcx.hir();
61-
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
61+
hir.get_module_parent_node(hir.local_def_id_to_hir_id(id))
6262
};
6363
providers.hir_crate = |tcx, ()| tcx.untracked_crate;
6464
providers.crate_hash = map::crate_hash;

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'tcx> TyCtxt<'tcx> {
348348
// Deprecated attributes apply in-crate and cross-crate.
349349
if let Some(id) = id {
350350
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
351-
let parent_def_id = self.hir().local_def_id(self.hir().get_parent_item(id));
351+
let parent_def_id = self.hir().get_parent_item(id);
352352
let skip = self
353353
.lookup_deprecation_entry(parent_def_id.to_def_id())
354354
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));

compiler/rustc_middle/src/ty/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ fn foo(&self) -> Self::T { String::new() }
869869
// When `body_owner` is an `impl` or `trait` item, look in its associated types for
870870
// `expected` and point at it.
871871
let parent_id = self.hir().get_parent_item(hir_id);
872-
let item = self.hir().find(parent_id);
872+
let item = self.hir().find_by_def_id(parent_id);
873873
debug!("expected_projection parent item {:?}", item);
874874
match item {
875875
Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Trait(.., items), .. })) => {

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
1313
use rustc_errors::{pluralize, struct_span_err, Applicability};
1414
use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
1515
use rustc_hir as hir;
16-
use rustc_hir::def_id::LocalDefId;
16+
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
1717
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1818
use rustc_hir::{self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID};
1919
use rustc_hir::{MethodKind, Target};
@@ -32,7 +32,7 @@ pub(crate) fn target_from_impl_item<'tcx>(
3232
match impl_item.kind {
3333
hir::ImplItemKind::Const(..) => Target::AssocConst,
3434
hir::ImplItemKind::Fn(..) => {
35-
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id()).expect_owner();
35+
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id());
3636
let containing_item = tcx.hir().expect_item(parent_hir_id);
3737
let containing_impl_is_for_trait = match &containing_item.kind {
3838
hir::ItemKind::Impl(impl_) => impl_.of_trait.is_some(),
@@ -582,7 +582,7 @@ impl CheckAttrVisitor<'_> {
582582
Target::Impl => Some("implementation block"),
583583
Target::ForeignMod => Some("extern block"),
584584
Target::AssocTy => {
585-
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id).expect_owner();
585+
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
586586
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
587587
if Target::from_item(containing_item) == Target::Impl {
588588
Some("type alias in implementation block")
@@ -591,7 +591,7 @@ impl CheckAttrVisitor<'_> {
591591
}
592592
}
593593
Target::AssocConst => {
594-
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id).expect_owner();
594+
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
595595
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
596596
// We can't link to trait impl's consts.
597597
let err = "associated constant in trait implementation block";
@@ -832,7 +832,7 @@ impl CheckAttrVisitor<'_> {
832832
let mut err = lint.build(
833833
"this attribute can only be applied at the crate level",
834834
);
835-
if attr.style == AttrStyle::Outer && self.tcx.hir().get_parent_item(hir_id) == CRATE_HIR_ID {
835+
if attr.style == AttrStyle::Outer && self.tcx.hir().get_parent_item(hir_id) == CRATE_DEF_ID {
836836
if let Ok(mut src) =
837837
self.tcx.sess.source_map().span_to_snippet(attr.span)
838838
{

compiler/rustc_passes/src/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'tcx> ReachableContext<'tcx> {
169169
if generics.requires_monomorphization(self.tcx) || attrs.requests_inline() {
170170
true
171171
} else {
172-
let impl_did = self.tcx.hir().get_parent_did(hir_id);
172+
let impl_did = self.tcx.hir().get_parent_item(hir_id);
173173
// Check the impl. If the generics on the self
174174
// type of the impl require inlining, this method
175175
// does too.

compiler/rustc_passes/src/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
629629
}
630630

631631
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
632-
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id()));
632+
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
633633
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
634634
self.check_missing_stability(ii.def_id, ii.span);
635635
}

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ fn visibility(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Visibility {
20242024
// Visibilities of trait impl items are inherited from their traits
20252025
// and are not filled in resolve.
20262026
Node::ImplItem(impl_item) => {
2027-
match tcx.hir().get(tcx.hir().get_parent_item(hir_id)) {
2027+
match tcx.hir().get_by_def_id(tcx.hir().get_parent_item(hir_id)) {
20282028
Node::Item(hir::Item {
20292029
kind: hir::ItemKind::Impl(hir::Impl { of_trait: Some(tr), .. }),
20302030
..

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
11371137
self.missing_named_lifetime_spots.push((&trait_item.generics).into());
11381138
let tcx = self.tcx;
11391139
self.visit_early_late(
1140-
Some(tcx.hir().get_parent_did(trait_item.hir_id())),
1140+
Some(tcx.hir().get_parent_item(trait_item.hir_id())),
11411141
trait_item.hir_id(),
11421142
&sig.decl,
11431143
&trait_item.generics,
@@ -1206,7 +1206,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
12061206
self.missing_named_lifetime_spots.push((&impl_item.generics).into());
12071207
let tcx = self.tcx;
12081208
self.visit_early_late(
1209-
Some(tcx.hir().get_parent_did(impl_item.hir_id())),
1209+
Some(tcx.hir().get_parent_item(impl_item.hir_id())),
12101210
impl_item.hir_id(),
12111211
&sig.decl,
12121212
&impl_item.generics,
@@ -1950,7 +1950,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19501950
};
19511951
if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) {
19521952
if let Some(parent) =
1953-
self.tcx.hir().find(self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
1953+
self.tcx.hir().find_by_def_id(self.tcx.hir().get_parent_item(hir_lifetime.hir_id))
19541954
{
19551955
match parent {
19561956
Node::Item(item) => {
@@ -2761,7 +2761,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27612761

27622762
Node::TraitItem(&hir::TraitItem { kind: hir::TraitItemKind::Fn(_, ref m), .. }) => {
27632763
if let hir::ItemKind::Trait(.., ref trait_items) =
2764-
self.tcx.hir().expect_item(self.tcx.hir().get_parent_did(parent)).kind
2764+
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
27652765
{
27662766
assoc_item_kind =
27672767
trait_items.iter().find(|ti| ti.id.hir_id() == parent).map(|ti| ti.kind);
@@ -2774,7 +2774,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27742774

27752775
Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body), .. }) => {
27762776
if let hir::ItemKind::Impl(hir::Impl { ref self_ty, ref items, .. }) =
2777-
self.tcx.hir().expect_item(self.tcx.hir().get_parent_did(parent)).kind
2777+
self.tcx.hir().expect_item(self.tcx.hir().get_parent_item(parent)).kind
27782778
{
27792779
impl_self = Some(self_ty);
27802780
assoc_item_kind =

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
481481
_ => {}
482482
}
483483

484-
hir_id = self.tcx.hir().get_parent_item(hir_id);
484+
hir_id = self.tcx.hir().local_def_id_to_hir_id(self.tcx.hir().get_parent_item(hir_id));
485485
}
486486
}
487487

@@ -2301,7 +2301,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
23012301
{
23022302
let in_progress_typeck_results =
23032303
self.in_progress_typeck_results.map(|t| t.borrow());
2304-
let parent_id = hir.local_def_id(hir.get_parent_item(arg_hir_id));
2304+
let parent_id = hir.get_parent_item(arg_hir_id);
23052305
let typeck_results: &TypeckResults<'tcx> = match &in_progress_typeck_results {
23062306
Some(t) if t.hir_owner == parent_id => t,
23072307
_ => self.tcx.typeck(parent_id),

compiler/rustc_ty_utils/src/assoc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
5252

5353
fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItem {
5454
let id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
55-
let parent_id = tcx.hir().get_parent_item(id);
56-
let parent_def_id = tcx.hir().local_def_id(parent_id);
55+
let parent_def_id = tcx.hir().get_parent_item(id);
5756
let parent_item = tcx.hir().expect_item(parent_def_id);
5857
match parent_item.kind {
5958
hir::ItemKind::Impl(ref impl_) => {

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19141914
.and_then(|def_id| {
19151915
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
19161916
})
1917-
.map(|hir_id| tcx.hir().get_parent_did(hir_id).to_def_id());
1917+
.map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id());
19181918

19191919
debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id);
19201920

0 commit comments

Comments
 (0)