mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Create LoweringContext::lower_assoc_item
.
By moving most of `ItemLowerer::lower_assoc_item` into it. This is similar to `LoweringContext::lower_foreign_item`.
This commit is contained in:
parent
b12851ce5d
commit
ed2868eb9d
@ -136,39 +136,9 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
|
|||||||
|
|
||||||
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
|
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
|
||||||
let def_id = self.resolver.node_id_to_def_id[&item.id];
|
let def_id = self.resolver.node_id_to_def_id[&item.id];
|
||||||
|
|
||||||
let parent_id = self.tcx.local_parent(def_id);
|
let parent_id = self.tcx.local_parent(def_id);
|
||||||
let parent_hir = self.lower_node(parent_id).unwrap();
|
let parent_hir = self.lower_node(parent_id).unwrap();
|
||||||
self.with_lctx(item.id, |lctx| {
|
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt, parent_hir))
|
||||||
// Evaluate with the lifetimes in `params` in-scope.
|
|
||||||
// This is used to track which lifetimes have already been defined,
|
|
||||||
// and which need to be replicated when lowering an async fn.
|
|
||||||
|
|
||||||
match parent_hir.node().expect_item().kind {
|
|
||||||
hir::ItemKind::Impl(impl_) => {
|
|
||||||
lctx.is_in_trait_impl = impl_.of_trait.is_some();
|
|
||||||
}
|
|
||||||
hir::ItemKind::Trait(_, _, generics, _, _) if lctx.tcx.features().effects => {
|
|
||||||
lctx.host_param_id = generics
|
|
||||||
.params
|
|
||||||
.iter()
|
|
||||||
.find(|param| {
|
|
||||||
parent_hir
|
|
||||||
.attrs
|
|
||||||
.get(param.hir_id.local_id)
|
|
||||||
.iter()
|
|
||||||
.any(|attr| attr.has_name(sym::rustc_host))
|
|
||||||
})
|
|
||||||
.map(|param| param.def_id);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
match ctxt {
|
|
||||||
AssocCtxt::Trait => hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)),
|
|
||||||
AssocCtxt::Impl => hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_foreign_item(&mut self, item: &ForeignItem) {
|
fn lower_foreign_item(&mut self, item: &ForeignItem) {
|
||||||
@ -609,6 +579,42 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn lower_assoc_item(
|
||||||
|
&mut self,
|
||||||
|
item: &AssocItem,
|
||||||
|
ctxt: AssocCtxt,
|
||||||
|
parent_hir: &'hir hir::OwnerInfo<'hir>,
|
||||||
|
) -> hir::OwnerNode<'hir> {
|
||||||
|
// Evaluate with the lifetimes in `params` in-scope.
|
||||||
|
// This is used to track which lifetimes have already been defined,
|
||||||
|
// and which need to be replicated when lowering an async fn.
|
||||||
|
|
||||||
|
match parent_hir.node().expect_item().kind {
|
||||||
|
hir::ItemKind::Impl(impl_) => {
|
||||||
|
self.is_in_trait_impl = impl_.of_trait.is_some();
|
||||||
|
}
|
||||||
|
hir::ItemKind::Trait(_, _, generics, _, _) if self.tcx.features().effects => {
|
||||||
|
self.host_param_id = generics
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.find(|param| {
|
||||||
|
parent_hir
|
||||||
|
.attrs
|
||||||
|
.get(param.hir_id.local_id)
|
||||||
|
.iter()
|
||||||
|
.any(|attr| attr.has_name(sym::rustc_host))
|
||||||
|
})
|
||||||
|
.map(|param| param.def_id);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
match ctxt {
|
||||||
|
AssocCtxt::Trait => hir::OwnerNode::TraitItem(self.lower_trait_item(item)),
|
||||||
|
AssocCtxt::Impl => hir::OwnerNode::ImplItem(self.lower_impl_item(item)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
|
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
|
||||||
let hir_id = self.lower_node_id(i.id);
|
let hir_id = self.lower_node_id(i.id);
|
||||||
let owner_id = hir_id.expect_owner();
|
let owner_id = hir_id.expect_owner();
|
||||||
|
Loading…
Reference in New Issue
Block a user