Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/delegation/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
let &DelegationResolution { span, sig_id, .. } = resolution;

const PARENT_ID: hir::ItemLocalId = hir::ItemLocalId::ZERO;
let new_attrs = self.create_new_attrs(span, sig_id, self.attrs.get(&PARENT_ID));
let new_attrs = self.create_new_attrs(span, sig_id, self.curr_owner.attrs.get(&PARENT_ID));

if !new_attrs.is_empty() {
let new_attrs = match self.attrs.get(&PARENT_ID) {
let new_attrs = match self.curr_owner.attrs.get(&PARENT_ID) {
Some(existing_attrs) => self.arena.alloc_from_iter(
existing_attrs.iter().map(|a| a.clone()).chain(new_attrs.into_iter()),
),
None => self.arena.alloc_from_iter(new_attrs.into_iter()),
};

self.attrs.insert(PARENT_ID, new_attrs);
self.curr_owner.attrs.insert(PARENT_ID, new_attrs);
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/delegation/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
};

// Important: we don't use `self.next_id()` as we want to execute
// `lower_node_id` routine so param's id is added to `self.children`.
// `lower_node_id` routine so param's id is added to `self.curr_owner.children`.
let hir_id = self.lower_node_id(node_id);

Some(hir::GenericParam {
Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_ast_lowering/src/delegation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
let id = match source {
DelegationSource::Single => None,
DelegationSource::List(expn_id) => Some(expn_id),
DelegationSource::Glob => {
Some(self.tcx.expn_that_defined(self.owner.def_id).expect_local())
}
DelegationSource::Glob => Some(
self.tcx
.expn_that_defined(self.curr_owner.owner.def_id)
.expect_local(),
),
};

id.map(|id| (id, unused_target_expr))
Expand Down Expand Up @@ -335,7 +337,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let overwrites = self_resolver.overwrites;

// Target expr needs to lower `self` path.
self.ident_and_label_to_local_id.insert(pat_node_id, param_local_id);
self.curr_owner.ident_and_label_to_local_id.insert(pat_node_id, param_local_id);

let block = cfg_select! {
debug_assertions => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/delegation/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(super) mod resolver {

#[inline]
pub(crate) fn owner_id(&self) -> LocalDefId {
self.0.owner.def_id
self.0.curr_owner.owner.def_id
}

/// (from `tests\ui\delegation\target-expr-removal-defs-inside.rs`):
Expand All @@ -91,7 +91,7 @@ pub(super) mod resolver {
#[inline]
pub(crate) fn is_definition(&self, id: NodeId) -> bool {
self.0.resolver.owners.contains_key(&id)
|| self.0.owner.node_id_to_def_id.contains_key(&id)
|| self.0.curr_owner.owner.node_id_to_def_id.contains_key(&id)
}

#[inline]
Expand Down
17 changes: 9 additions & 8 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
// Merge attributes into the inner expression.
if !e.attrs.is_empty() {
let old_attrs = self.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
let old_attrs =
self.curr_owner.attrs.get(&ex.hir_id.local_id).copied().unwrap_or(&[]);
let new_attrs = self
.lower_attrs_vec(&e.attrs, e.span, ex.hir_id, Target::from_expr(e))
.into_iter()
Expand All @@ -181,7 +182,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if new_attrs.is_empty() {
return ex;
}
self.attrs.insert(ex.hir_id.local_id, new_attrs);
self.curr_owner.attrs.insert(ex.hir_id.local_id, new_attrs);
}
return ex;
}
Expand Down Expand Up @@ -884,15 +885,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// `inner_hir_id` in case the `async_fn_track_caller` feature is enabled.
pub(super) fn maybe_forward_track_caller(&mut self, outer_hir_id: HirId, inner_hir_id: HirId) {
if self.tcx.features().async_fn_track_caller()
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
&& let Some(attrs) = self.curr_owner.attrs.get(&outer_hir_id.local_id)
&& let Some(t) = attrs.iter().find(|a| {
matches!(
a,
rustc_attr_ir::Attribute::Parsed(rustc_attr_ir::AttributeKind::TrackCaller(_))
)
})
{
self.attrs.insert(inner_hir_id.local_id, std::slice::from_ref(t));
self.curr_owner.attrs.insert(inner_hir_id.local_id, std::slice::from_ref(t));
}
}

Expand Down Expand Up @@ -1505,16 +1506,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
dest_hir_id: hir::HirId,
) -> Option<Label> {
let label = opt_label?;
self.ident_and_label_to_local_id.insert(dest_id, dest_hir_id.local_id);
self.curr_owner.ident_and_label_to_local_id.insert(dest_id, dest_hir_id.local_id);
Some(Label { ident: self.lower_ident(label.ident) })
}

fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
let target_id = match destination {
Some((id, _)) => {
if let Some(loop_id) = self.owner.get_label_res(id) {
let local_id = self.ident_and_label_to_local_id[&loop_id];
let loop_hir_id = HirId { owner: self.current_hir_id_owner, local_id };
if let Some(loop_id) = self.curr_owner.owner.get_label_res(id) {
let local_id = self.curr_owner.ident_and_label_to_local_id[&loop_id];
let loop_hir_id = HirId { owner: self.curr_owner.owner_id, local_id };
Ok(loop_hir_id)
} else {
Err(hir::LoopIdError::UnresolvedLabel)
Expand Down
42 changes: 20 additions & 22 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ impl<'hir> ItemLowerer<'_, 'hir> {
let mut lctx = LoweringContext::new(self.tcx, self.resolver, owner);

let item = f(&mut lctx);
debug_assert_eq!(lctx.current_hir_id_owner, item.def_id());

let info = lctx.make_owner_info(item);

let info = lctx.curr_owner.into_owner_info(self.tcx, item);
hir::MaybeOwner::Owner(lctx.arena.alloc(info))
}

#[instrument(level = "debug", skip(self, c))]
pub(super) fn lower_crate(&mut self, c: &Crate) -> hir::MaybeOwner<'hir> {
self.with_lctx(CRATE_NODE_ID, |lctx| {
debug_assert_eq!(lctx.current_hir_id_owner, CRATE_OWNER_ID);
debug_assert_eq!(lctx.curr_owner.owner_id, CRATE_OWNER_ID);
let module = lctx.lower_mod(&c.items, &c.spans);
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
hir::OwnerNode::Crate(module)
Expand Down Expand Up @@ -206,7 +204,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
let owner_id = self.current_hir_id_owner;
let owner_id = self.curr_owner.owner_id;
let hir_id: HirId = owner_id.into();
let vis_span = self.lower_span(i.vis.span);

Expand Down Expand Up @@ -399,7 +397,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias {
parent: this.owner.def_id,
parent: this.curr_owner.owner.def_id,
in_assoc_ty: false,
},
},
Expand Down Expand Up @@ -547,7 +545,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ItemKind::MacroDef(ident, MacroDef { body, macro_rules, eii_declaration: _ }) => {
let ident = self.lower_ident(*ident);
let body = Box::new(self.lower_delim_args(body));
let def_id = self.owner.def_id;
let def_id = self.curr_owner.owner.def_id;
let def_kind = self.tcx.def_kind(def_id);
let DefKind::Macro(macro_kinds) = def_kind else {
unreachable!(
Expand Down Expand Up @@ -695,7 +693,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `ItemLocalId` and the new owner. (See `lower_node_id`)
let kind = this.lower_use_tree(use_tree, &prefix, id, vis_span, attrs);
if !attrs.is_empty() {
this.attrs.insert(hir::ItemLocalId::ZERO, attrs);
this.curr_owner.attrs.insert(hir::ItemLocalId::ZERO, attrs);
}

let item = hir::Item {
Expand Down Expand Up @@ -731,7 +729,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
let owner_id = self.current_hir_id_owner;
let owner_id = self.curr_owner.owner_id;
let hir_id: HirId = owner_id.into();
let attrs =
self.lower_attrs(hir_id, &i.attrs, i.span, Target::from_foreign_item_kind(&i.kind));
Expand Down Expand Up @@ -914,7 +912,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
let trait_item_def_id = self.current_hir_id_owner;
let trait_item_def_id = self.curr_owner.owner_id;
let hir_id: HirId = trait_item_def_id.into();
let attrs = self.lower_attrs(
hir_id,
Expand Down Expand Up @@ -1169,7 +1167,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
let owner_id = self.current_hir_id_owner;
let owner_id = self.curr_owner.owner_id;
let hir_id: HirId = owner_id.into();
let parent_id = self.tcx.local_parent(owner_id.def_id);
let is_in_trait_impl =
Expand Down Expand Up @@ -1258,7 +1256,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::TyAlias {
parent: this.owner.def_id,
parent: this.curr_owner.owner.def_id,
in_assoc_ty: true,
},
},
Expand Down Expand Up @@ -1336,8 +1334,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::BodyId {
let body = hir::Body { params, value: self.arena.alloc(value) };
let id = body.id();
assert_eq!(id.hir_id.owner, self.current_hir_id_owner);
self.bodies.push((id.hir_id.local_id, self.arena.alloc(body)));
assert_eq!(id.hir_id.owner, self.curr_owner.owner_id);
self.curr_owner.bodies.push((id.hir_id.local_id, self.arena.alloc(body)));
id
}

Expand Down Expand Up @@ -1545,7 +1543,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
//
// If this is the simple case, this parameter will end up being the same as the
// original parameter, but with a different pattern id.
let stmt_attrs = self.attrs.get(&parameter.hir_id.local_id).copied();
let stmt_attrs = self.curr_owner.attrs.get(&parameter.hir_id.local_id).copied();
let (new_parameter_pat, new_parameter_id) = self.pat_ident(desugared_span, ident);
let new_parameter = hir::Param {
hir_id: parameter.hir_id,
Expand Down Expand Up @@ -1883,8 +1881,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
itctx: ImplTraitContext,
f: impl FnOnce(&mut Self) -> T,
) -> (&'hir hir::Generics<'hir>, T) {
assert!(self.impl_trait_defs.is_empty());
assert!(self.impl_trait_bounds.is_empty());
assert!(self.curr_owner.impl_trait_defs.is_empty());
assert!(self.curr_owner.impl_trait_bounds.is_empty());

let mut predicates: SmallVec<[hir::WherePredicate<'hir>; 4]> = SmallVec::new();
// We need to make sure that generic params don't have multiple relaxed bounds for the same trait
Expand Down Expand Up @@ -1914,7 +1912,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
.collect();

// Introduce extra lifetimes if late resolution tells us to.
let extra_lifetimes = self.owner.extra_lifetime_params(self.owner.id);
let extra_lifetimes = self.curr_owner.owner.extra_lifetime_params(self.curr_owner.owner.id);
params.extend(extra_lifetimes.into_iter().map(|&(ident, node_id, kind)| {
self.lifetime_res_to_generic_param(
ident,
Expand All @@ -1929,10 +1927,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
let span = self.lower_span(generics.span);
let res = f(self);

let impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
let impl_trait_defs = std::mem::take(&mut self.curr_owner.impl_trait_defs);
params.extend(impl_trait_defs.into_iter());

let impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
let impl_trait_bounds = std::mem::take(&mut self.curr_owner.impl_trait_bounds);
predicates.extend(impl_trait_bounds.into_iter());

let lowered_generics = self.arena.alloc(hir::Generics {
Expand All @@ -1951,7 +1949,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir_id: HirId,
define_opaque: &Option<ThinVec<(NodeId, Path)>>,
) {
assert_eq!(self.define_opaque, None);
assert_eq!(self.curr_owner.define_opaque, None);
assert!(hir_id.is_owner());
let Some(define_opaque) = define_opaque.as_ref() else {
return;
Expand All @@ -1972,7 +1970,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some((self.lower_span(path.span), did))
});
let define_opaque = self.arena.alloc_from_iter(define_opaque);
self.define_opaque = Some(define_opaque);
self.curr_owner.define_opaque = Some(define_opaque);
}

pub(super) fn lower_generic_bound_predicate(
Expand Down
Loading
Loading