use rustc_ast::ast::*;
use rustc_ast::attr;
use rustc_ast::node_id::NodeMap;
+use rustc_ast::ptr::P;
use rustc_ast::visit::{self, AssocCtxt, Visitor};
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::DefId;
+use rustc_hir::def_id::LocalDefId;
use rustc_span::source_map::{respan, DesugaringKind};
use rustc_span::symbol::{kw, sym};
use rustc_span::Span;
_ => &[],
};
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {
- hir::GenericParamKind::Lifetime { .. } => Some(param.name.modern()),
+ hir::GenericParamKind::Lifetime { .. } => Some(param.name.normalize_to_macros_2_0()),
_ => None,
});
self.in_scope_lifetimes.extend(lt_def_names);
let mut vis = self.lower_visibility(&i.vis, None);
let attrs = self.lower_attrs(&i.attrs);
- if let ItemKind::MacroDef(ref def) = i.kind {
- if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
- let body = self.lower_token_stream(def.body.inner_tokens());
+ if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind {
+ if !macro_rules || attr::contains_name(&i.attrs, sym::macro_export) {
let hir_id = self.lower_node_id(i.id);
+ let body = P(self.lower_mac_args(body));
self.exported_macros.push(hir::MacroDef {
- name: ident.name,
+ ident,
vis,
attrs,
hir_id,
span: i.span,
- body,
- legacy: def.legacy,
+ ast: MacroDef { body, macro_rules },
});
} else {
self.non_exported_macro_attrs.extend(attrs.iter().cloned());
hir::ItemKind::Const(ty, body_id)
}
ItemKind::Fn(_, FnSig { ref decl, header }, ref generics, ref body) => {
- let fn_def_id = self.resolver.definitions().local_def_id(id);
+ let fn_def_id = self.resolver.definitions().local_def_id(id).expect_local();
self.with_new_scopes(|this| {
this.current_item = Some(ident.span);
AnonymousLifetimeMode::PassThrough,
|this, idty| {
let ret_id = asyncness.opt_return_id();
- this.lower_fn_decl(&decl, Some((fn_def_id, idty)), true, ret_id)
+ this.lower_fn_decl(
+ &decl,
+ Some((fn_def_id.to_def_id(), idty)),
+ true,
+ ret_id,
+ )
},
);
let sig = hir::FnSig { decl, header: this.lower_fn_header(header) };
self_ty: ref ty,
items: ref impl_items,
} => {
- let def_id = self.resolver.definitions().local_def_id(id);
+ let def_id = self.resolver.definitions().local_def_id(id).expect_local();
// Lower the "impl header" first. This ordering is important
// for in-band lifetimes! Consider `'a` here:
self.lower_generics(generics, ImplTraitContext::disallowed()),
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
),
- ItemKind::MacroDef(..) | ItemKind::Mac(..) => {
+ ItemKind::MacroDef(..) | ItemKind::MacCall(..) => {
bug!("`TyMac` should have been expanded by now")
}
}
}
fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
- let def_id = self.resolver.definitions().local_def_id(i.id);
+ let def_id = self.resolver.definitions().local_def_id(i.id).expect_local();
hir::ForeignItem {
hir_id: self.lower_node_id(i.id),
ident: i.ident,
hir::ForeignItemKind::Static(ty, m)
}
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
- ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
+ ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
},
vis: self.lower_visibility(&i.vis, None),
span: i.span,
}
fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
- let trait_item_def_id = self.resolver.definitions().local_def_id(i.id);
+ let trait_item_def_id = self.resolver.definitions().local_def_id(i.id).expect_local();
let (generics, kind) = match i.kind {
AssocItemKind::Const(_, ref ty, ref default) => {
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
- (generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Required(names)))
+ (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
}
AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
- (generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Provided(body_id)))
+ (generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
}
AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => {
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
(generics, kind)
}
- AssocItemKind::Macro(..) => bug!("macro item shouldn't exist at this point"),
+ AssocItemKind::MacCall(..) => bug!("macro item shouldn't exist at this point"),
};
hir::TraitItem {
AssocItemKind::Fn(_, sig, _, default) => {
(hir::AssocItemKind::Method { has_self: sig.decl.has_self() }, default.is_some())
}
- AssocItemKind::Macro(..) => unimplemented!(),
+ AssocItemKind::MacCall(..) => unimplemented!(),
};
let id = hir::TraitItemId { hir_id: self.lower_node_id(i.id) };
let defaultness = hir::Defaultness::Default { has_value: has_default };
}
/// Construct `ExprKind::Err` for the given `span`.
- fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> {
+ crate fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::Err, AttrVec::new())
}
fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
- let impl_item_def_id = self.resolver.definitions().local_def_id(i.id);
+ let impl_item_def_id = self.resolver.definitions().local_def_id(i.id).expect_local();
let (generics, kind) = match &i.kind {
AssocItemKind::Const(_, ty, expr) => {
asyncness.opt_return_id(),
);
- (generics, hir::ImplItemKind::Method(sig, body_id))
+ (generics, hir::ImplItemKind::Fn(sig, body_id))
}
AssocItemKind::TyAlias(_, generics, _, ty) => {
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
};
(generics, kind)
}
- AssocItemKind::Macro(..) => bug!("`TyMac` should have been expanded by now"),
+ AssocItemKind::MacCall(..) => bug!("`TyMac` should have been expanded by now"),
};
hir::ImplItem {
AssocItemKind::Fn(_, sig, ..) => {
hir::AssocItemKind::Method { has_self: sig.decl.has_self() }
}
- AssocItemKind::Macro(..) => unimplemented!(),
+ AssocItemKind::MacCall(..) => unimplemented!(),
},
}
id
}
- fn lower_body(
+ pub(super) fn lower_body(
&mut self,
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
) -> hir::BodyId {
&mut self,
generics: &Generics,
sig: &FnSig,
- fn_def_id: DefId,
+ fn_def_id: LocalDefId,
impl_trait_return_allow: bool,
is_async: Option<NodeId>,
) -> (hir::Generics<'hir>, hir::FnSig<'hir>) {
|this, idty| {
this.lower_fn_decl(
&sig.decl,
- Some((fn_def_id, idty)),
+ Some((fn_def_id.to_def_id(), idty)),
impl_trait_return_allow,
is_async,
)