summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast_lowering/src/item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ast_lowering/src/item.rs')
-rw-r--r--compiler/rustc_ast_lowering/src/item.rs343
1 files changed, 131 insertions, 212 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index 76316a574..d73d6d391 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -6,7 +6,6 @@ use super::{FnDeclKind, LoweringContext, ParamMode};
use rustc_ast::ptr::P;
use rustc_ast::visit::AssocCtxt;
use rustc_ast::*;
-use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
@@ -20,8 +19,7 @@ use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{Span, Symbol};
use rustc_target::spec::abi;
use smallvec::{smallvec, SmallVec};
-
-use std::iter;
+use thin_vec::ThinVec;
pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>,
@@ -67,7 +65,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
// HirId handling.
bodies: Vec::new(),
attrs: SortedMap::default(),
- children: FxHashMap::default(),
+ children: Vec::default(),
current_hir_id_owner: hir::CRATE_OWNER_ID,
item_local_id_counter: hir::ItemLocalId::new(0),
node_id_to_local_id: Default::default(),
@@ -86,7 +84,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
- allow_gen_future: Some([sym::gen_future][..].into()),
+ allow_gen_future: Some([sym::gen_future, sym::closure_track_caller][..].into()),
allow_into_future: Some([sym::into_future][..].into()),
generics_def_id_map: Default::default(),
};
@@ -143,7 +141,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
// 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(hir::Impl { ref of_trait, .. }) => {
+ hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => {
lctx.is_in_trait_impl = of_trait.is_some();
}
_ => {}
@@ -179,37 +177,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_item_ref(&mut self, i: &Item) -> SmallVec<[hir::ItemId; 1]> {
let mut node_ids =
smallvec![hir::ItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }];
- if let ItemKind::Use(ref use_tree) = &i.kind {
- self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids);
+ if let ItemKind::Use(use_tree) = &i.kind {
+ self.lower_item_id_use_tree(use_tree, &mut node_ids);
}
node_ids
}
- fn lower_item_id_use_tree(
- &mut self,
- tree: &UseTree,
- base_id: NodeId,
- vec: &mut SmallVec<[hir::ItemId; 1]>,
- ) {
- match tree.kind {
- UseTreeKind::Nested(ref nested_vec) => {
+ fn lower_item_id_use_tree(&mut self, tree: &UseTree, vec: &mut SmallVec<[hir::ItemId; 1]>) {
+ match &tree.kind {
+ UseTreeKind::Nested(nested_vec) => {
for &(ref nested, id) in nested_vec {
vec.push(hir::ItemId {
owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
});
- self.lower_item_id_use_tree(nested, id, vec);
- }
- }
- UseTreeKind::Glob => {}
- UseTreeKind::Simple(_, id1, id2) => {
- for (_, &id) in
- iter::zip(self.expect_full_res_from_use(base_id).skip(1), &[id1, id2])
- {
- vec.push(hir::ItemId {
- owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
- });
+ self.lower_item_id_use_tree(nested, vec);
}
}
+ UseTreeKind::Simple(..) | UseTreeKind::Glob => {}
}
}
@@ -239,26 +223,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
vis_span: Span,
i: &ItemKind,
) -> hir::ItemKind<'hir> {
- match *i {
- ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
- ItemKind::Use(ref use_tree) => {
+ match i {
+ ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(*orig_name),
+ ItemKind::Use(use_tree) => {
// Start with an empty prefix.
- let prefix = Path { segments: vec![], span: use_tree.span, tokens: None };
+ let prefix = Path { segments: ThinVec::new(), span: use_tree.span, tokens: None };
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
}
- ItemKind::Static(ref t, m, ref e) => {
+ ItemKind::Static(t, m, e) => {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
- hir::ItemKind::Static(ty, m, body_id)
+ hir::ItemKind::Static(ty, *m, body_id)
}
- ItemKind::Const(_, ref t, ref e) => {
+ ItemKind::Const(_, t, e) => {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
hir::ItemKind::Const(ty, body_id)
}
ItemKind::Fn(box Fn {
- sig: FnSig { ref decl, header, span: fn_sig_span },
- ref generics,
- ref body,
+ sig: FnSig { decl, header, span: fn_sig_span },
+ generics,
+ body,
..
}) => {
self.with_new_scopes(|this| {
@@ -269,43 +253,41 @@ impl<'hir> LoweringContext<'_, 'hir> {
// only cares about the input argument patterns in the function
// declaration (decl), not the return types.
let asyncness = header.asyncness;
- let body_id =
- this.lower_maybe_async_body(span, &decl, asyncness, body.as_deref());
+ let body_id = this.lower_maybe_async_body(
+ span,
+ hir_id,
+ &decl,
+ asyncness,
+ body.as_deref(),
+ );
let mut itctx = ImplTraitContext::Universal;
let (generics, decl) = this.lower_generics(generics, id, &mut itctx, |this| {
let ret_id = asyncness.opt_return_id();
- this.lower_fn_decl(&decl, Some(id), fn_sig_span, FnDeclKind::Fn, ret_id)
+ this.lower_fn_decl(&decl, id, *fn_sig_span, FnDeclKind::Fn, ret_id)
});
let sig = hir::FnSig {
decl,
- header: this.lower_fn_header(header),
- span: this.lower_span(fn_sig_span),
+ header: this.lower_fn_header(*header),
+ span: this.lower_span(*fn_sig_span),
};
hir::ItemKind::Fn(sig, generics, body_id)
})
}
- ItemKind::Mod(_, ref mod_kind) => match mod_kind {
+ ItemKind::Mod(_, mod_kind) => match mod_kind {
ModKind::Loaded(items, _, spans) => {
hir::ItemKind::Mod(self.lower_mod(items, spans))
}
ModKind::Unloaded => panic!("`mod` items should have been loaded by now"),
},
- ItemKind::ForeignMod(ref fm) => hir::ItemKind::ForeignMod {
+ ItemKind::ForeignMod(fm) => hir::ItemKind::ForeignMod {
abi: fm.abi.map_or(abi::Abi::FALLBACK, |abi| self.lower_abi(abi)),
items: self
.arena
.alloc_from_iter(fm.items.iter().map(|x| self.lower_foreign_item_ref(x))),
},
- ItemKind::GlobalAsm(ref asm) => {
- hir::ItemKind::GlobalAsm(self.lower_inline_asm(span, asm))
- }
- ItemKind::TyAlias(box TyAlias {
- ref generics,
- where_clauses,
- ty: Some(ref ty),
- ..
- }) => {
+ ItemKind::GlobalAsm(asm) => hir::ItemKind::GlobalAsm(self.lower_inline_asm(span, asm)),
+ ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: Some(ty), .. }) => {
// We lower
//
// type Foo = impl Trait
@@ -315,7 +297,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// type Foo = Foo1
// opaque type Foo1: Trait
let mut generics = generics.clone();
- add_ty_alias_where_clause(&mut generics, where_clauses, true);
+ add_ty_alias_where_clause(&mut generics, *where_clauses, true);
let (generics, ty) = self.lower_generics(
&generics,
id,
@@ -324,9 +306,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::TyAlias(ty, generics)
}
- ItemKind::TyAlias(box TyAlias {
- ref generics, ref where_clauses, ty: None, ..
- }) => {
+ ItemKind::TyAlias(box TyAlias { generics, where_clauses, ty: None, .. }) => {
let mut generics = generics.clone();
add_ty_alias_where_clause(&mut generics, *where_clauses, true);
let (generics, ty) = self.lower_generics(
@@ -337,7 +317,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::TyAlias(ty, generics)
}
- ItemKind::Enum(ref enum_definition, ref generics) => {
+ ItemKind::Enum(enum_definition, generics) => {
let (generics, variants) = self.lower_generics(
generics,
id,
@@ -350,7 +330,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::Enum(hir::EnumDef { variants }, generics)
}
- ItemKind::Struct(ref struct_def, ref generics) => {
+ ItemKind::Struct(struct_def, generics) => {
let (generics, struct_def) = self.lower_generics(
generics,
id,
@@ -359,7 +339,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::Struct(struct_def, generics)
}
- ItemKind::Union(ref vdata, ref generics) => {
+ ItemKind::Union(vdata, generics) => {
let (generics, vdata) = self.lower_generics(
generics,
id,
@@ -373,10 +353,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
polarity,
defaultness,
constness,
- generics: ref ast_generics,
- of_trait: ref trait_ref,
- self_ty: ref ty,
- items: ref impl_items,
+ generics: ast_generics,
+ of_trait: trait_ref,
+ self_ty: ty,
+ items: impl_items,
}) => {
// Lower the "impl header" first. This ordering is important
// for in-band lifetimes! Consider `'a` here:
@@ -414,30 +394,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
// to not cause an assertion failure inside the `lower_defaultness` function.
let has_val = true;
- let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val);
+ let (defaultness, defaultness_span) = self.lower_defaultness(*defaultness, has_val);
let polarity = match polarity {
ImplPolarity::Positive => ImplPolarity::Positive,
- ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(s)),
+ ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(*s)),
};
hir::ItemKind::Impl(self.arena.alloc(hir::Impl {
- unsafety: self.lower_unsafety(unsafety),
+ unsafety: self.lower_unsafety(*unsafety),
polarity,
defaultness,
defaultness_span,
- constness: self.lower_constness(constness),
+ constness: self.lower_constness(*constness),
generics,
of_trait: trait_ref,
self_ty: lowered_ty,
items: new_impl_items,
}))
}
- ItemKind::Trait(box Trait {
- is_auto,
- unsafety,
- ref generics,
- ref bounds,
- ref items,
- }) => {
+ ItemKind::Trait(box Trait { is_auto, unsafety, generics, bounds, items }) => {
let (generics, (unsafety, items, bounds)) = self.lower_generics(
generics,
id,
@@ -450,13 +424,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let items = this.arena.alloc_from_iter(
items.iter().map(|item| this.lower_trait_item_ref(item)),
);
- let unsafety = this.lower_unsafety(unsafety);
+ let unsafety = this.lower_unsafety(*unsafety);
(unsafety, items, bounds)
},
);
- hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, items)
+ hir::ItemKind::Trait(*is_auto, unsafety, generics, bounds, items)
}
- ItemKind::TraitAlias(ref generics, ref bounds) => {
+ ItemKind::TraitAlias(generics, bounds) => {
let (generics, bounds) = self.lower_generics(
generics,
id,
@@ -470,10 +444,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
hir::ItemKind::TraitAlias(generics, bounds)
}
- ItemKind::MacroDef(MacroDef { ref body, macro_rules }) => {
- let body = P(self.lower_mac_args(body));
+ ItemKind::MacroDef(MacroDef { body, macro_rules }) => {
+ let body = P(self.lower_delim_args(body));
let macro_kind = self.resolver.decl_macro_kind(self.local_def_id(id));
- hir::ItemKind::Macro(ast::MacroDef { body, macro_rules }, macro_kind)
+ hir::ItemKind::Macro(ast::MacroDef { body, macro_rules: *macro_rules }, macro_kind)
}
ItemKind::MacCall(..) => {
panic!("`TyMac` should have been expanded by now")
@@ -505,7 +479,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect();
match tree.kind {
- UseTreeKind::Simple(rename, id1, id2) => {
+ UseTreeKind::Simple(rename) => {
*ident = tree.ident();
// First, apply the prefix to the path.
@@ -521,66 +495,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
- let mut resolutions = self.expect_full_res_from_use(id).fuse();
- // We want to return *something* from this function, so hold onto the first item
- // for later.
- let ret_res = self.lower_res(resolutions.next().unwrap_or(Res::Err));
-
- // Here, we are looping over namespaces, if they exist for the definition
- // being imported. We only handle type and value namespaces because we
- // won't be dealing with macros in the rest of the compiler.
- // Essentially a single `use` which imports two names is desugared into
- // two imports.
- for new_node_id in [id1, id2] {
- let new_id = self.local_def_id(new_node_id);
- let Some(res) = resolutions.next() else {
- // Associate an HirId to both ids even if there is no resolution.
- let _old = self.children.insert(
- new_id,
- hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id)),
- );
- debug_assert!(_old.is_none());
- continue;
- };
- let ident = *ident;
- let mut path = path.clone();
- for seg in &mut path.segments {
- // Give the cloned segment the same resolution information
- // as the old one (this is needed for stability checking).
- let new_id = self.next_node_id();
- self.resolver.clone_res(seg.id, new_id);
- seg.id = new_id;
- }
- let span = path.span;
-
- self.with_hir_id_owner(new_node_id, |this| {
- let res = this.lower_res(res);
- let path = this.lower_path_extra(res, &path, ParamMode::Explicit);
- let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
- if let Some(attrs) = attrs {
- this.attrs.insert(hir::ItemLocalId::new(0), attrs);
- }
-
- let item = hir::Item {
- owner_id: hir::OwnerId { def_id: new_id },
- ident: this.lower_ident(ident),
- kind,
- vis_span,
- span: this.lower_span(span),
- };
- hir::OwnerNode::Item(this.arena.alloc(item))
- });
- }
-
- let path = self.lower_path_extra(ret_res, &path, ParamMode::Explicit);
+ let res =
+ self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
+ let path = self.lower_use_path(res, &path, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::Single)
}
UseTreeKind::Glob => {
- let path = self.lower_path(
- id,
- &Path { segments, span: path.span, tokens: None },
- ParamMode::Explicit,
- );
+ let res = self.expect_full_res(id);
+ let res = smallvec![self.lower_res(res)];
+ let path = Path { segments, span: path.span, tokens: None };
+ let path = self.lower_use_path(res, &path, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::Glob)
}
UseTreeKind::Nested(ref trees) => {
@@ -650,9 +574,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
});
}
- let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
- let res = self.lower_res(res);
- let path = self.lower_path_extra(res, &prefix, ParamMode::Explicit);
+ let res =
+ self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
+ let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::ListStem)
}
}
@@ -665,8 +589,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let item = hir::ForeignItem {
owner_id,
ident: self.lower_ident(i.ident),
- kind: match i.kind {
- ForeignItemKind::Fn(box Fn { ref sig, ref generics, .. }) => {
+ kind: match &i.kind {
+ ForeignItemKind::Fn(box Fn { sig, generics, .. }) => {
let fdec = &sig.decl;
let mut itctx = ImplTraitContext::Universal;
let (generics, (fn_dec, fn_args)) =
@@ -675,7 +599,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Disallow `impl Trait` in foreign items.
this.lower_fn_decl(
fdec,
- None,
+ i.id,
sig.span,
FnDeclKind::ExternFn,
None,
@@ -686,10 +610,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
}
- ForeignItemKind::Static(ref t, m, _) => {
+ ForeignItemKind::Static(t, m, _) => {
let ty =
self.lower_ty(t, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
- hir::ForeignItemKind::Static(ty, m)
+ hir::ForeignItemKind::Static(ty, *m)
}
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
@@ -709,11 +633,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
- let id = self.lower_node_id(v.id);
- self.lower_attrs(id, &v.attrs);
+ let hir_id = self.lower_node_id(v.id);
+ self.lower_attrs(hir_id, &v.attrs);
hir::Variant {
- id,
- data: self.lower_variant_data(id, &v.data),
+ hir_id,
+ def_id: self.local_def_id(v.id),
+ data: self.lower_variant_data(hir_id, &v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
ident: self.lower_ident(v.ident),
span: self.lower_span(v.span),
@@ -725,32 +650,33 @@ impl<'hir> LoweringContext<'_, 'hir> {
parent_id: hir::HirId,
vdata: &VariantData,
) -> hir::VariantData<'hir> {
- match *vdata {
- VariantData::Struct(ref fields, recovered) => hir::VariantData::Struct(
+ match vdata {
+ VariantData::Struct(fields, recovered) => hir::VariantData::Struct(
self.arena
.alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))),
- recovered,
+ *recovered,
),
- VariantData::Tuple(ref fields, id) => {
- let ctor_id = self.lower_node_id(id);
+ VariantData::Tuple(fields, id) => {
+ let ctor_id = self.lower_node_id(*id);
self.alias_attrs(ctor_id, parent_id);
hir::VariantData::Tuple(
self.arena.alloc_from_iter(
fields.iter().enumerate().map(|f| self.lower_field_def(f)),
),
ctor_id,
+ self.local_def_id(*id),
)
}
VariantData::Unit(id) => {
- let ctor_id = self.lower_node_id(id);
+ let ctor_id = self.lower_node_id(*id);
self.alias_attrs(ctor_id, parent_id);
- hir::VariantData::Unit(ctor_id)
+ hir::VariantData::Unit(ctor_id, self.local_def_id(*id))
}
}
}
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
- let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
+ let ty = if let TyKind::Path(qself, path) = &f.ty.kind {
let t = self.lower_path_ty(
&f.ty,
qself,
@@ -767,6 +693,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::FieldDef {
span: self.lower_span(f.span),
hir_id,
+ def_id: self.local_def_id(f.id),
ident: match f.ident {
Some(ident) => self.lower_ident(ident),
// FIXME(jseyfried): positional field hygiene.
@@ -779,15 +706,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
let hir_id = self.lower_node_id(i.id);
+ self.lower_attrs(hir_id, &i.attrs);
let trait_item_def_id = hir_id.expect_owner();
- let (generics, kind, has_default) = match i.kind {
- AssocItemKind::Const(_, ref ty, ref default) => {
+ let (generics, kind, has_default) = match &i.kind {
+ AssocItemKind::Const(_, ty, default) => {
let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type));
let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
(hir::Generics::empty(), hir::TraitItemKind::Const(ty, body), body.is_some())
}
- AssocItemKind::Fn(box Fn { ref sig, ref generics, body: None, .. }) => {
+ AssocItemKind::Fn(box Fn { sig, generics, body: None, .. }) => {
let asyncness = sig.header.asyncness;
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) = self.lower_method_sig(
@@ -799,10 +727,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)), false)
}
- AssocItemKind::Fn(box Fn { ref sig, ref generics, body: Some(ref body), .. }) => {
+ AssocItemKind::Fn(box Fn { sig, generics, body: Some(body), .. }) => {
let asyncness = sig.header.asyncness;
let body_id =
- self.lower_maybe_async_body(i.span, &sig.decl, asyncness, Some(&body));
+ self.lower_maybe_async_body(i.span, hir_id, &sig.decl, asyncness, Some(&body));
let (generics, sig) = self.lower_method_sig(
generics,
sig,
@@ -812,15 +740,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)), true)
}
- AssocItemKind::Type(box TyAlias {
- ref generics,
- where_clauses,
- ref bounds,
- ref ty,
- ..
- }) => {
+ AssocItemKind::Type(box TyAlias { generics, where_clauses, bounds, ty, .. }) => {
let mut generics = generics.clone();
- add_ty_alias_where_clause(&mut generics, where_clauses, false);
+ add_ty_alias_where_clause(&mut generics, *where_clauses, false);
let (generics, kind) = self.lower_generics(
&generics,
i.id,
@@ -843,7 +765,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
AssocItemKind::MacCall(..) => panic!("macro item shouldn't exist at this point"),
};
- self.lower_attrs(hir_id, &i.attrs);
let item = hir::TraitItem {
owner_id: trait_item_def_id,
ident: self.lower_ident(i.ident),
@@ -875,13 +796,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// Construct `ExprKind::Err` for the given `span`.
pub(crate) fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> {
- self.expr(span, hir::ExprKind::Err, AttrVec::new())
+ self.expr(span, hir::ExprKind::Err)
}
fn lower_impl_item(&mut self, i: &AssocItem) -> &'hir hir::ImplItem<'hir> {
// Since `default impl` is not yet implemented, this is always true in impls.
let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
+ let hir_id = self.lower_node_id(i.id);
+ self.lower_attrs(hir_id, &i.attrs);
let (generics, kind) = match &i.kind {
AssocItemKind::Const(_, ty, expr) => {
@@ -894,8 +817,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
AssocItemKind::Fn(box Fn { sig, generics, body, .. }) => {
self.current_item = Some(i.span);
let asyncness = sig.header.asyncness;
- let body_id =
- self.lower_maybe_async_body(i.span, &sig.decl, asyncness, body.as_deref());
+ let body_id = self.lower_maybe_async_body(
+ i.span,
+ hir_id,
+ &sig.decl,
+ asyncness,
+ body.as_deref(),
+ );
let (generics, sig) = self.lower_method_sig(
generics,
sig,
@@ -928,8 +856,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
AssocItemKind::MacCall(..) => panic!("`TyMac` should have been expanded by now"),
};
- let hir_id = self.lower_node_id(i.id);
- self.lower_attrs(hir_id, &i.attrs);
let item = hir::ImplItem {
owner_id: hir_id.expect_owner(),
ident: self.lower_ident(i.ident),
@@ -1062,6 +988,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_maybe_async_body(
&mut self,
span: Span,
+ fn_id: hir::HirId,
decl: &FnDecl,
asyncness: Async,
body: Option<&Block>,
@@ -1212,6 +1139,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let async_expr = this.make_async_expr(
CaptureBy::Value,
+ Some(fn_id),
closure_id,
None,
body.span,
@@ -1223,11 +1151,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Transform into `drop-temps { <user-body> }`, an expression:
let desugared_span =
this.mark_span_with_reason(DesugaringKind::Async, user_body.span, None);
- let user_body = this.expr_drop_temps(
- desugared_span,
- this.arena.alloc(user_body),
- AttrVec::new(),
- );
+ let user_body =
+ this.expr_drop_temps(desugared_span, this.arena.alloc(user_body));
// As noted above, create the final block like
//
@@ -1244,14 +1169,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(user_body),
);
- this.expr_block(body, AttrVec::new())
+ this.expr_block(body)
},
);
- (
- this.arena.alloc_from_iter(parameters),
- this.expr(body.span, async_expr, AttrVec::new()),
- )
+ (this.arena.alloc_from_iter(parameters), this.expr(body.span, async_expr))
})
}
@@ -1266,7 +1188,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let header = self.lower_fn_header(sig.header);
let mut itctx = ImplTraitContext::Universal;
let (generics, decl) = self.lower_generics(generics, id, &mut itctx, |this| {
- this.lower_fn_decl(&sig.decl, Some(id), sig.span, kind, is_async)
+ this.lower_fn_decl(&sig.decl, id, sig.span, kind, is_async)
});
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
}
@@ -1352,7 +1274,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// keep track of the Span info. Now, `add_implicitly_sized` in `AstConv` checks both param bounds and
// where clauses for `?Sized`.
for pred in &generics.where_clause.predicates {
- let WherePredicate::BoundPredicate(ref bound_pred) = *pred else {
+ let WherePredicate::BoundPredicate(bound_pred) = pred else {
continue;
};
let compute_is_param = || {
@@ -1498,10 +1420,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
}))
}
GenericParamKind::Lifetime => {
- let ident_span = self.lower_span(ident.span);
let ident = self.lower_ident(ident);
let lt_id = self.next_node_id();
- let lifetime = self.new_named_lifetime(id, lt_id, ident_span, ident);
+ let lifetime = self.new_named_lifetime(id, lt_id, ident);
Some(hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
lifetime,
span,
@@ -1513,11 +1434,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicate<'hir> {
- match *pred {
+ match pred {
WherePredicate::BoundPredicate(WhereBoundPredicate {
- ref bound_generic_params,
- ref bounded_ty,
- ref bounds,
+ bound_generic_params,
+ bounded_ty,
+ bounds,
span,
}) => hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
hir_id: self.next_id(),
@@ -1530,29 +1451,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
&ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
)
})),
- span: self.lower_span(span),
+ span: self.lower_span(*span),
origin: PredicateOrigin::WhereClause,
}),
- WherePredicate::RegionPredicate(WhereRegionPredicate {
- ref lifetime,
- ref bounds,
- span,
- }) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
- span: self.lower_span(span),
- lifetime: self.lower_lifetime(lifetime),
- bounds: self.lower_param_bounds(
- bounds,
- &ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
- ),
- in_where_clause: true,
- }),
- WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, span }) => {
+ WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, span }) => {
+ hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
+ span: self.lower_span(*span),
+ lifetime: self.lower_lifetime(lifetime),
+ bounds: self.lower_param_bounds(
+ bounds,
+ &ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
+ ),
+ in_where_clause: true,
+ })
+ }
+ WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, span }) => {
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
lhs_ty: self
.lower_ty(lhs_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
rhs_ty: self
.lower_ty(rhs_ty, &ImplTraitContext::Disallowed(ImplTraitPosition::Type)),
- span: self.lower_span(span),
+ span: self.lower_span(*span),
})
}
}