Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a1a3557

Browse files
committedSep 20, 2021
Make with_hir_id_owner responsible for registering the item.
1 parent c1bac92 commit a1a3557

File tree

3 files changed

+91
-140
lines changed

3 files changed

+91
-140
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
327327
let mut generic_args = vec![];
328328
for (idx, arg) in args.into_iter().enumerate() {
329329
if legacy_args_idx.contains(&idx) {
330-
let parent_def_id = self.current_hir_id_owner.0;
330+
let parent_def_id = self.current_hir_id_owner;
331331
let node_id = self.resolver.next_node_id();
332332

333333
// Add a definition for the in-band const def.

‎compiler/rustc_ast_lowering/src/item.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@ impl ItemLowerer<'_, '_, '_> {
4040

4141
impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
4242
fn visit_item(&mut self, item: &'a Item) {
43-
self.lctx.allocate_hir_id_counter(item.id);
4443
let hir_id = self.lctx.with_hir_id_owner(item.id, |lctx| {
45-
lctx.without_in_scope_lifetime_defs(|lctx| {
46-
let hir_item = lctx.lower_item(item);
47-
lctx.insert_item(hir_item)
48-
})
44+
let node = lctx.without_in_scope_lifetime_defs(|lctx| lctx.lower_item(item));
45+
hir::OwnerNode::Item(node)
4946
});
5047

5148
self.lctx.with_parent_item_lifetime_defs(hir_id, |this| {
@@ -72,26 +69,17 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
7269
}
7370

7471
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
75-
self.lctx.allocate_hir_id_counter(item.id);
7672
self.lctx.with_hir_id_owner(item.id, |lctx| match ctxt {
77-
AssocCtxt::Trait => {
78-
let hir_item = lctx.lower_trait_item(item);
79-
lctx.insert_trait_item(hir_item);
80-
}
81-
AssocCtxt::Impl => {
82-
let hir_item = lctx.lower_impl_item(item);
83-
lctx.insert_impl_item(hir_item);
84-
}
73+
AssocCtxt::Trait => hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)),
74+
AssocCtxt::Impl => hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)),
8575
});
8676

8777
visit::walk_assoc_item(self, item, ctxt);
8878
}
8979

9080
fn visit_foreign_item(&mut self, item: &'a ForeignItem) {
91-
self.lctx.allocate_hir_id_counter(item.id);
9281
self.lctx.with_hir_id_owner(item.id, |lctx| {
93-
let hir_item = lctx.lower_foreign_item(item);
94-
lctx.insert_foreign_item(hir_item);
82+
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
9583
});
9684

9785
visit::walk_foreign_item(self, item);
@@ -106,12 +94,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
10694
// only used when lowering a child item of a trait or impl.
10795
fn with_parent_item_lifetime_defs<T>(
10896
&mut self,
109-
parent_hir_id: hir::ItemId,
97+
parent_hir_id: LocalDefId,
11098
f: impl FnOnce(&mut Self) -> T,
11199
) -> T {
112100
let old_len = self.in_scope_lifetimes.len();
113101

114-
let parent_generics = match self.owners[parent_hir_id.def_id].unwrap().expect_item().kind {
102+
let parent_generics = match self.owners[parent_hir_id].unwrap().expect_item().kind {
115103
hir::ItemKind::Impl(hir::Impl { ref generics, .. })
116104
| hir::ItemKind::Trait(_, _, ref generics, ..) => generics.params,
117105
_ => &[],
@@ -186,19 +174,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
186174
}
187175
}
188176

189-
pub fn lower_item(&mut self, i: &Item) -> hir::Item<'hir> {
177+
fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
190178
let mut ident = i.ident;
191179
let mut vis = self.lower_visibility(&i.vis);
192180
let hir_id = self.lower_node_id(i.id);
193181
let attrs = self.lower_attrs(hir_id, &i.attrs);
194182
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
195-
hir::Item {
183+
let item = hir::Item {
196184
def_id: hir_id.expect_owner(),
197185
ident: self.lower_ident(ident),
198186
kind,
199187
vis,
200188
span: self.lower_span(i.span),
201-
}
189+
};
190+
self.arena.alloc(item)
202191
}
203192

204193
fn lower_item_kind(
@@ -480,10 +469,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
480469
// Essentially a single `use` which imports two names is desugared into
481470
// two imports.
482471
for new_node_id in [id1, id2] {
483-
// Associate an HirId to both ids even if there is no resolution.
484-
let new_id = self.allocate_hir_id_counter(new_node_id);
485-
486-
let res = if let Some(res) = resolutions.next() { res } else { continue };
472+
let new_id = self.resolver.local_def_id(new_node_id);
473+
let res = if let Some(res) = resolutions.next() {
474+
res
475+
} else {
476+
// Associate an HirId to both ids even if there is no resolution.
477+
self.node_id_to_hir_id.ensure_contains_elem(new_node_id, || None);
478+
debug_assert!(self.node_id_to_hir_id[new_node_id].is_none());
479+
self.node_id_to_hir_id[new_node_id] = Some(hir::HirId::make_owner(new_id));
480+
continue;
481+
};
487482
let ident = *ident;
488483
let mut path = path.clone();
489484
for seg in &mut path.segments {
@@ -500,13 +495,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
500495
this.attrs.insert(hir::HirId::make_owner(new_id), attrs);
501496
}
502497

503-
this.insert_item(hir::Item {
498+
let item = hir::Item {
504499
def_id: new_id,
505500
ident: this.lower_ident(ident),
506501
kind,
507502
vis,
508503
span: this.lower_span(span),
509-
});
504+
};
505+
hir::OwnerNode::Item(this.arena.alloc(item))
510506
});
511507
}
512508

@@ -550,7 +546,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
550546

551547
// Add all the nested `PathListItem`s to the HIR.
552548
for &(ref use_tree, id) in trees {
553-
let new_hir_id = self.allocate_hir_id_counter(id);
549+
let new_hir_id = self.resolver.local_def_id(id);
554550

555551
let mut prefix = prefix.clone();
556552

@@ -574,13 +570,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
574570
this.attrs.insert(hir::HirId::make_owner(new_hir_id), attrs);
575571
}
576572

577-
this.insert_item(hir::Item {
573+
let item = hir::Item {
578574
def_id: new_hir_id,
579575
ident: this.lower_ident(ident),
580576
kind,
581577
vis,
582578
span: this.lower_span(use_tree.span),
583-
});
579+
};
580+
hir::OwnerNode::Item(this.arena.alloc(item))
584581
});
585582
}
586583

@@ -647,11 +644,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
647644
respan(self.lower_span(vis.span), vis_kind)
648645
}
649646

650-
fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
647+
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
651648
let hir_id = self.lower_node_id(i.id);
652649
let def_id = hir_id.expect_owner();
653650
self.lower_attrs(hir_id, &i.attrs);
654-
hir::ForeignItem {
651+
let item = hir::ForeignItem {
655652
def_id,
656653
ident: self.lower_ident(i.ident),
657654
kind: match i.kind {
@@ -681,12 +678,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
681678
},
682679
vis: self.lower_visibility(&i.vis),
683680
span: self.lower_span(i.span),
684-
}
681+
};
682+
self.arena.alloc(item)
685683
}
686684

687685
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef {
688686
hir::ForeignItemRef {
689-
id: hir::ForeignItemId { def_id: self.allocate_hir_id_counter(i.id) },
687+
id: hir::ForeignItemId { def_id: self.resolver.local_def_id(i.id) },
690688
ident: self.lower_ident(i.ident),
691689
span: self.lower_span(i.span),
692690
}
@@ -761,7 +759,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
761759
}
762760
}
763761

764-
fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
762+
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
765763
let hir_id = self.lower_node_id(i.id);
766764
let trait_item_def_id = hir_id.expect_owner();
767765

@@ -804,13 +802,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
804802
};
805803

806804
self.lower_attrs(hir_id, &i.attrs);
807-
hir::TraitItem {
805+
let item = hir::TraitItem {
808806
def_id: trait_item_def_id,
809807
ident: self.lower_ident(i.ident),
810808
generics,
811809
kind,
812810
span: self.lower_span(i.span),
813-
}
811+
};
812+
self.arena.alloc(item)
814813
}
815814

816815
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
@@ -840,7 +839,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
840839
self.expr(span, hir::ExprKind::Err, AttrVec::new())
841840
}
842841

843-
fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
842+
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
844843
let impl_item_def_id = self.resolver.local_def_id(i.id);
845844

846845
let (generics, kind) = match &i.kind {
@@ -894,23 +893,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
894893
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
895894
let hir_id = self.lower_node_id(i.id);
896895
self.lower_attrs(hir_id, &i.attrs);
897-
hir::ImplItem {
896+
let item = hir::ImplItem {
898897
def_id: hir_id.expect_owner(),
899898
ident: self.lower_ident(i.ident),
900899
generics,
901900
vis: self.lower_visibility(&i.vis),
902901
defaultness,
903902
kind,
904903
span: self.lower_span(i.span),
905-
}
904+
};
905+
self.arena.alloc(item)
906906
}
907907

908908
fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef {
909909
// Since `default impl` is not yet implemented, this is always true in impls.
910910
let has_value = true;
911911
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
912912
hir::ImplItemRef {
913-
id: hir::ImplItemId { def_id: self.allocate_hir_id_counter(i.id) },
913+
id: hir::ImplItemId { def_id: self.resolver.local_def_id(i.id) },
914914
ident: self.lower_ident(i.ident),
915915
span: self.lower_span(i.span),
916916
defaultness,

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 48 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ struct LoweringContext<'a, 'hir: 'a> {
148148
/// vector.
149149
in_scope_lifetimes: Vec<ParamName>,
150150

151-
current_hir_id_owner: (LocalDefId, u32),
152-
item_local_id_counters: IndexVec<LocalDefId, u32>,
151+
current_hir_id_owner: LocalDefId,
152+
item_local_id_counter: hir::ItemLocalId,
153153
node_id_to_hir_id: IndexVec<NodeId, Option<hir::HirId>>,
154154

155155
allow_try_trait: Option<Lrc<[Symbol]>>,
@@ -328,8 +328,8 @@ pub fn lower_crate<'a, 'hir>(
328328
is_in_trait_impl: false,
329329
is_in_dyn_type: false,
330330
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
331-
current_hir_id_owner: (CRATE_DEF_ID, 0),
332-
item_local_id_counters: Default::default(),
331+
current_hir_id_owner: CRATE_DEF_ID,
332+
item_local_id_counter: hir::ItemLocalId::new(0),
333333
node_id_to_hir_id: IndexVec::new(),
334334
generator_kind: None,
335335
task_context: None,
@@ -410,15 +410,15 @@ enum AnonymousLifetimeMode {
410410

411411
impl<'a, 'hir> LoweringContext<'a, 'hir> {
412412
fn lower_crate(mut self, c: &Crate) -> &'hir hir::Crate<'hir> {
413-
self.lower_node_id(CRATE_NODE_ID);
414-
debug_assert!(self.node_id_to_hir_id[CRATE_NODE_ID] == Some(hir::CRATE_HIR_ID));
413+
debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID);
415414

416415
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
417416

418-
let module = self.arena.alloc(self.lower_mod(&c.items, c.span));
419-
self.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
420-
self.owners.ensure_contains_elem(CRATE_DEF_ID, || None);
421-
self.owners[CRATE_DEF_ID] = Some(hir::OwnerNode::Crate(module));
417+
self.with_hir_id_owner(CRATE_NODE_ID, |lctx| {
418+
let module = lctx.lower_mod(&c.items, c.span);
419+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
420+
hir::OwnerNode::Crate(lctx.arena.alloc(module))
421+
});
422422

423423
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
424424
for (k, v) in self.resolver.take_trait_map().into_iter() {
@@ -454,83 +454,40 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
454454
self.arena.alloc(krate)
455455
}
456456

457-
fn insert_item(&mut self, item: hir::Item<'hir>) -> hir::ItemId {
458-
let id = item.item_id();
459-
let item = self.arena.alloc(item);
460-
self.owners.ensure_contains_elem(id.def_id, || None);
461-
self.owners[id.def_id] = Some(hir::OwnerNode::Item(item));
462-
id
463-
}
464-
465-
fn insert_foreign_item(&mut self, item: hir::ForeignItem<'hir>) -> hir::ForeignItemId {
466-
let id = item.foreign_item_id();
467-
let item = self.arena.alloc(item);
468-
self.owners.ensure_contains_elem(id.def_id, || None);
469-
self.owners[id.def_id] = Some(hir::OwnerNode::ForeignItem(item));
470-
id
471-
}
472-
473-
fn insert_impl_item(&mut self, item: hir::ImplItem<'hir>) -> hir::ImplItemId {
474-
let id = item.impl_item_id();
475-
let item = self.arena.alloc(item);
476-
self.owners.ensure_contains_elem(id.def_id, || None);
477-
self.owners[id.def_id] = Some(hir::OwnerNode::ImplItem(item));
478-
id
479-
}
480-
481-
fn insert_trait_item(&mut self, item: hir::TraitItem<'hir>) -> hir::TraitItemId {
482-
let id = item.trait_item_id();
483-
let item = self.arena.alloc(item);
484-
self.owners.ensure_contains_elem(id.def_id, || None);
485-
self.owners[id.def_id] = Some(hir::OwnerNode::TraitItem(item));
486-
id
487-
}
488-
489457
fn create_stable_hashing_context(&self) -> LoweringHasher<'_> {
490458
LoweringHasher {
491459
source_map: CachingSourceMapView::new(self.sess.source_map()),
492460
resolver: self.resolver,
493461
}
494462
}
495463

496-
fn allocate_hir_id_counter(&mut self, owner: NodeId) -> LocalDefId {
497-
// Set up the counter if needed.
464+
fn with_hir_id_owner(
465+
&mut self,
466+
owner: NodeId,
467+
f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>,
468+
) -> LocalDefId {
498469
let def_id = self.resolver.local_def_id(owner);
499470

500471
// Always allocate the first `HirId` for the owner itself.
501472
self.node_id_to_hir_id.ensure_contains_elem(owner, || None);
502473
if let Some(_lowered) = self.node_id_to_hir_id[owner] {
503-
debug_assert_eq!(_lowered.owner, def_id);
504-
debug_assert_eq!(_lowered.local_id.as_u32(), 0);
505-
} else {
506-
self.item_local_id_counters.ensure_contains_elem(def_id, || 0);
507-
let local_id_counter = &mut self.item_local_id_counters[def_id];
508-
let local_id = *local_id_counter;
474+
panic!("with_hir_id_owner must not be called multiple times on owner {:?}", def_id);
475+
}
476+
self.node_id_to_hir_id[owner] = Some(hir::HirId::make_owner(def_id));
509477

510-
// We want to be sure not to modify the counter in the map while it
511-
// is also on the stack. Otherwise we'll get lost updates when writing
512-
// back from the stack to the map.
513-
debug_assert_eq!(local_id, 0);
478+
let current_owner = std::mem::replace(&mut self.current_hir_id_owner, def_id);
479+
let current_local_counter =
480+
std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
514481

515-
*local_id_counter += 1;
516-
self.node_id_to_hir_id[owner] = Some(hir::HirId::make_owner(def_id));
517-
}
518-
def_id
519-
}
482+
let item = f(self);
520483

521-
fn with_hir_id_owner<T>(&mut self, owner: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
522-
let def_id = self.resolver.local_def_id(owner);
523-
let counter = self.item_local_id_counters[def_id];
524-
let old_owner = std::mem::replace(&mut self.current_hir_id_owner, (def_id, counter));
525-
let ret = f(self);
526-
let (new_def_id, new_counter) =
527-
std::mem::replace(&mut self.current_hir_id_owner, old_owner);
484+
self.current_hir_id_owner = current_owner;
485+
self.item_local_id_counter = current_local_counter;
528486

529-
debug_assert!(def_id == new_def_id);
530-
debug_assert!(new_counter >= counter);
487+
self.owners.ensure_contains_elem(def_id, || None);
488+
self.owners[def_id] = Some(item);
531489

532-
self.item_local_id_counters[def_id] = new_counter;
533-
ret
490+
def_id
534491
}
535492

536493
/// This method allocates a new `HirId` for the given `NodeId` and stores it in
@@ -547,10 +504,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
547504
existing_hir_id
548505
} else {
549506
// Generate a new `HirId`.
550-
let &mut (owner, ref mut local_id_counter) = &mut self.current_hir_id_owner;
551-
let local_id = *local_id_counter;
552-
*local_id_counter += 1;
553-
let hir_id = hir::HirId { owner, local_id: hir::ItemLocalId::from_u32(local_id) };
507+
let owner = self.current_hir_id_owner;
508+
let local_id = self.item_local_id_counter;
509+
self.item_local_id_counter.increment_by(1);
510+
let hir_id = hir::HirId { owner, local_id };
554511
self.node_id_to_hir_id[ast_node_id] = Some(hir_id);
555512
hir_id
556513
}
@@ -626,7 +583,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
626583
/// Mark a span as relative to the current owning item.
627584
fn lower_span(&self, span: Span) -> Span {
628585
if self.sess.opts.debugging_opts.incremental_relative_spans {
629-
span.with_parent(Some(self.current_hir_id_owner.0))
586+
span.with_parent(Some(self.current_hir_id_owner))
630587
} else {
631588
// Do not make spans relative when not using incremental compilation.
632589
span
@@ -799,7 +756,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
799756
// wouldn't have been added yet.
800757
let generics = this.lower_generics_mut(
801758
generics,
802-
ImplTraitContext::Universal(&mut params, this.current_hir_id_owner.0),
759+
ImplTraitContext::Universal(&mut params, this.current_hir_id_owner),
803760
);
804761
let res = f(this, &mut params);
805762
(params, (generics, res))
@@ -1005,7 +962,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1005962
}
1006963
AssocTyConstraintKind::Bound { ref bounds } => {
1007964
let mut capturable_lifetimes;
1008-
let mut parent_def_id = self.current_hir_id_owner.0;
965+
let mut parent_def_id = self.current_hir_id_owner;
1009966
// Piggy-back on the `impl Trait` context to figure out the correct behavior.
1010967
let (desugar_to_impl_trait, itctx) = match itctx {
1011968
// We are in the return position:
@@ -1133,7 +1090,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11331090

11341091
// Construct an AnonConst where the expr is the "ty"'s path.
11351092

1136-
let parent_def_id = self.current_hir_id_owner.0;
1093+
let parent_def_id = self.current_hir_id_owner;
11371094
let node_id = self.resolver.next_node_id();
11381095

11391096
// Add a definition for the in-band const def.
@@ -1399,12 +1356,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13991356
// frequently opened issues show.
14001357
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
14011358

1402-
let opaque_ty_def_id = self.allocate_hir_id_counter(opaque_ty_node_id);
1359+
let opaque_ty_def_id = self.resolver.local_def_id(opaque_ty_node_id);
14031360

1404-
let collected_lifetimes = self.with_hir_id_owner(opaque_ty_node_id, move |lctx| {
1361+
let mut collected_lifetimes = Vec::new();
1362+
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
14051363
let hir_bounds = lower_bounds(lctx);
14061364

1407-
let collected_lifetimes = lifetimes_from_impl_trait_bounds(
1365+
collected_lifetimes = lifetimes_from_impl_trait_bounds(
14081366
opaque_ty_node_id,
14091367
&hir_bounds,
14101368
capturable_lifetimes,
@@ -1457,9 +1415,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14571415
};
14581416

14591417
trace!("lower_opaque_impl_trait: {:#?}", opaque_ty_def_id);
1460-
lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span);
1461-
1462-
collected_lifetimes
1418+
lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span)
14631419
});
14641420

14651421
let lifetimes =
@@ -1481,7 +1437,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14811437
opaque_ty_item: hir::OpaqueTy<'hir>,
14821438
span: Span,
14831439
opaque_ty_span: Span,
1484-
) {
1440+
) -> hir::OwnerNode<'hir> {
14851441
let opaque_ty_item_kind = hir::ItemKind::OpaqueTy(opaque_ty_item);
14861442
// Generate an `type Foo = impl Trait;` declaration.
14871443
trace!("registering opaque type with id {:#?}", opaque_ty_id);
@@ -1492,11 +1448,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14921448
vis: respan(self.lower_span(span.shrink_to_lo()), hir::VisibilityKind::Inherited),
14931449
span: self.lower_span(opaque_ty_span),
14941450
};
1495-
1496-
// Insert the item into the global item list. This usually happens
1497-
// automatically for all AST items. But this opaque type item
1498-
// does not actually exist in the AST.
1499-
self.insert_item(opaque_ty_item);
1451+
hir::OwnerNode::Item(self.arena.alloc(opaque_ty_item))
15001452
}
15011453

15021454
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
@@ -1565,7 +1517,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15651517
if let Some((_, ibty)) = &mut in_band_ty_params {
15661518
this.lower_ty_direct(
15671519
&param.ty,
1568-
ImplTraitContext::Universal(ibty, this.current_hir_id_owner.0),
1520+
ImplTraitContext::Universal(ibty, this.current_hir_id_owner),
15691521
)
15701522
} else {
15711523
this.lower_ty_direct(&param.ty, ImplTraitContext::disallowed())
@@ -1656,7 +1608,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16561608

16571609
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::Async, span, None);
16581610

1659-
let opaque_ty_def_id = self.allocate_hir_id_counter(opaque_ty_node_id);
1611+
let opaque_ty_def_id = self.resolver.local_def_id(opaque_ty_node_id);
16601612

16611613
// When we create the opaque type for this async fn, it is going to have
16621614
// to capture all the lifetimes involved in the signature (including in the
@@ -1706,7 +1658,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17061658
// grow.
17071659
let input_lifetimes_count = self.in_scope_lifetimes.len() + self.lifetimes_to_define.len();
17081660

1709-
let lifetime_params = self.with_hir_id_owner(opaque_ty_node_id, |this| {
1661+
let mut lifetime_params = Vec::new();
1662+
self.with_hir_id_owner(opaque_ty_node_id, |this| {
17101663
// We have to be careful to get elision right here. The
17111664
// idea is that we create a lifetime parameter for each
17121665
// lifetime in the return type. So, given a return type
@@ -1728,7 +1681,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17281681
//
17291682
// Note: this must be done after lowering the output type,
17301683
// as the output type may introduce new in-band lifetimes.
1731-
let lifetime_params: Vec<(Span, ParamName)> = this
1684+
lifetime_params = this
17321685
.in_scope_lifetimes
17331686
.iter()
17341687
.cloned()
@@ -1757,9 +1710,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17571710
};
17581711

17591712
trace!("exist ty from async fn def id: {:#?}", opaque_ty_def_id);
1760-
this.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span);
1761-
1762-
lifetime_params
1713+
this.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span)
17631714
});
17641715

17651716
// As documented above on the variable

0 commit comments

Comments
 (0)
Please sign in to comment.