2021-02-13 20:41:02 +01:00
|
|
|
use crate::{ImplTraitContext, Resolver};
|
2020-03-14 22:22:29 +03:00
|
|
|
use rustc_ast::visit::{self, FnKind};
|
2020-04-27 23:26:11 +05:30
|
|
|
use rustc_ast::*;
|
2019-12-29 17:23:55 +03:00
|
|
|
use rustc_expand::expand::AstFragment;
|
2019-11-03 14:36:59 +02:00
|
|
|
use rustc_hir::def_id::LocalDefId;
|
2020-03-21 04:39:48 +01:00
|
|
|
use rustc_hir::definitions::*;
|
2021-06-25 20:43:04 +02:00
|
|
|
use rustc_span::hygiene::LocalExpnId;
|
2021-10-17 19:32:34 +03:00
|
|
|
use rustc_span::symbol::sym;
|
2019-12-31 20:15:40 +03:00
|
|
|
use rustc_span::Span;
|
2016-04-14 12:14:03 +12:00
|
|
|
|
2022-05-20 19:51:09 -04:00
|
|
|
pub(crate) fn collect_definitions(
|
2022-12-08 12:59:02 +00:00
|
|
|
resolver: &mut Resolver<'_, '_>,
|
2019-11-23 18:19:57 +03:00
|
|
|
fragment: &AstFragment,
|
2021-06-25 20:43:04 +02:00
|
|
|
expansion: LocalExpnId,
|
2019-11-23 18:19:57 +03:00
|
|
|
) {
|
2021-02-13 20:41:02 +01:00
|
|
|
let (parent_def, impl_trait_context) = resolver.invocation_parents[&expansion];
|
|
|
|
fragment.visit_with(&mut DefCollector { resolver, parent_def, expansion, impl_trait_context });
|
2019-11-23 18:19:57 +03:00
|
|
|
}
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Creates `DefId`s for nodes in the AST.
|
2022-12-08 12:59:02 +00:00
|
|
|
struct DefCollector<'a, 'b, 'tcx> {
|
|
|
|
resolver: &'a mut Resolver<'b, 'tcx>,
|
2019-11-03 14:36:59 +02:00
|
|
|
parent_def: LocalDefId,
|
2021-02-13 20:41:02 +01:00
|
|
|
impl_trait_context: ImplTraitContext,
|
2021-06-25 20:43:04 +02:00
|
|
|
expansion: LocalExpnId,
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2022-12-08 12:59:02 +00:00
|
|
|
impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> {
|
2019-11-03 14:36:59 +02:00
|
|
|
fn create_def(&mut self, node_id: NodeId, data: DefPathData, span: Span) -> LocalDefId {
|
2019-07-02 23:42:00 +03:00
|
|
|
let parent_def = self.parent_def;
|
2016-04-14 12:14:03 +12:00
|
|
|
debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def);
|
2021-05-02 21:19:28 +02:00
|
|
|
self.resolver.create_def(
|
|
|
|
parent_def,
|
|
|
|
node_id,
|
|
|
|
data,
|
|
|
|
self.expansion.to_expn_id(),
|
|
|
|
span.with_parent(None),
|
|
|
|
)
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2019-11-03 14:36:59 +02:00
|
|
|
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) {
|
2019-07-02 23:42:00 +03:00
|
|
|
let orig_parent_def = std::mem::replace(&mut self.parent_def, parent_def);
|
2016-04-14 17:24:30 +12:00
|
|
|
f(self);
|
2019-07-02 23:42:00 +03:00
|
|
|
self.parent_def = orig_parent_def;
|
2016-04-14 17:24:30 +12:00
|
|
|
}
|
2016-05-02 23:11:19 +03:00
|
|
|
|
2021-02-13 20:41:02 +01:00
|
|
|
fn with_impl_trait<F: FnOnce(&mut Self)>(
|
|
|
|
&mut self,
|
|
|
|
impl_trait_context: ImplTraitContext,
|
|
|
|
f: F,
|
|
|
|
) {
|
|
|
|
let orig_itc = std::mem::replace(&mut self.impl_trait_context, impl_trait_context);
|
|
|
|
f(self);
|
|
|
|
self.impl_trait_context = orig_itc;
|
|
|
|
}
|
|
|
|
|
2021-03-16 00:36:07 +03:00
|
|
|
fn collect_field(&mut self, field: &'a FieldDef, index: Option<usize>) {
|
2019-11-23 14:16:38 +03:00
|
|
|
let index = |this: &Self| {
|
|
|
|
index.unwrap_or_else(|| {
|
|
|
|
let node_id = NodeId::placeholder_from_expn_id(this.expansion);
|
2020-06-20 19:59:29 +01:00
|
|
|
this.resolver.placeholder_field_indices[&node_id]
|
2019-11-23 14:16:38 +03:00
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2019-09-14 17:36:27 +03:00
|
|
|
if field.is_placeholder {
|
2020-06-20 19:59:29 +01:00
|
|
|
let old_index = self.resolver.placeholder_field_indices.insert(field.id, index(self));
|
|
|
|
assert!(old_index.is_none(), "placeholder field index is reset for a node ID");
|
2019-09-14 17:36:27 +03:00
|
|
|
self.visit_macro_invoc(field.id);
|
|
|
|
} else {
|
2019-11-23 14:16:38 +03:00
|
|
|
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
|
2019-09-14 17:36:27 +03:00
|
|
|
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
|
2021-03-16 00:36:07 +03:00
|
|
|
self.with_parent(def, |this| visit::walk_field_def(this, field));
|
2019-09-14 17:36:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-10 01:41:47 +03:00
|
|
|
fn visit_macro_invoc(&mut self, id: NodeId) {
|
2021-02-13 20:41:02 +01:00
|
|
|
let id = id.placeholder_to_expn_id();
|
2020-06-20 19:59:29 +01:00
|
|
|
let old_parent =
|
2021-02-13 20:41:02 +01:00
|
|
|
self.resolver.invocation_parents.insert(id, (self.parent_def, self.impl_trait_context));
|
2020-06-20 19:59:29 +01:00
|
|
|
assert!(old_parent.is_none(), "parent `LocalDefId` is reset for an invocation");
|
2016-09-14 09:55:20 +00:00
|
|
|
}
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2022-12-08 12:59:02 +00:00
|
|
|
impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_item(&mut self, i: &'a Item) {
|
2016-04-14 12:14:03 +12:00
|
|
|
debug!("visit_item: {:?}", i);
|
|
|
|
|
|
|
|
// Pick the def data. This need not be unique, but the more
|
2018-05-22 14:31:56 +02:00
|
|
|
// information we encapsulate into, the better
|
2019-11-07 13:33:37 +01:00
|
|
|
let def_data = match &i.kind {
|
2020-01-13 20:30:20 -08:00
|
|
|
ItemKind::Impl { .. } => DefPathData::Impl,
|
2021-12-17 16:45:15 +08:00
|
|
|
ItemKind::ForeignMod(..) => DefPathData::ForeignMod,
|
2019-05-03 21:51:24 +03:00
|
|
|
ItemKind::Mod(..)
|
|
|
|
| ItemKind::Trait(..)
|
|
|
|
| ItemKind::TraitAlias(..)
|
|
|
|
| ItemKind::Enum(..)
|
|
|
|
| ItemKind::Struct(..)
|
|
|
|
| ItemKind::Union(..)
|
2019-11-07 19:13:22 +01:00
|
|
|
| ItemKind::ExternCrate(..)
|
2019-10-21 14:25:08 +11:00
|
|
|
| ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
|
2018-06-18 21:18:10 -07:00
|
|
|
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) => {
|
2019-12-08 00:08:09 +01:00
|
|
|
DefPathData::ValueNs(i.ident.name)
|
2018-06-06 15:50:59 -07:00
|
|
|
}
|
2019-10-21 14:25:08 +11:00
|
|
|
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.name),
|
2020-12-31 17:59:09 +03:00
|
|
|
ItemKind::MacCall(..) => {
|
|
|
|
visit::walk_item(self, i);
|
|
|
|
return self.visit_macro_invoc(i.id);
|
|
|
|
}
|
2022-05-12 20:12:35 +02:00
|
|
|
ItemKind::GlobalAsm(..) => DefPathData::GlobalAsm,
|
2017-09-26 23:04:00 +02:00
|
|
|
ItemKind::Use(..) => {
|
|
|
|
return visit::walk_item(self, i);
|
2016-11-24 06:11:31 +02:00
|
|
|
}
|
2016-04-14 12:14:03 +12:00
|
|
|
};
|
2023-11-24 23:39:42 +03:00
|
|
|
let def_id = self.create_def(i.id, def_data, i.span);
|
2016-04-14 12:14:03 +12:00
|
|
|
|
2023-11-24 23:39:42 +03:00
|
|
|
if let ItemKind::MacroDef(..) = i.kind {
|
|
|
|
let macro_data = self.resolver.compile_macro(i, self.resolver.tcx.sess.edition());
|
|
|
|
self.resolver.macro_map.insert(def_id.to_def_id(), macro_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.with_parent(def_id, |this| {
|
2021-02-13 20:41:02 +01:00
|
|
|
this.with_impl_trait(ImplTraitContext::Existential, |this| {
|
|
|
|
match i.kind {
|
|
|
|
ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => {
|
|
|
|
// If this is a unit or tuple-like struct, register the constructor.
|
2022-10-25 20:15:15 +04:00
|
|
|
if let Some(ctor_node_id) = struct_def.ctor_node_id() {
|
|
|
|
this.create_def(ctor_node_id, DefPathData::Ctor, i.span);
|
2021-02-13 20:41:02 +01:00
|
|
|
}
|
2016-04-14 17:24:30 +12:00
|
|
|
}
|
2021-02-13 20:41:02 +01:00
|
|
|
_ => {}
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
2021-02-13 20:41:02 +01:00
|
|
|
visit::walk_item(this, i);
|
|
|
|
})
|
2016-04-14 17:24:30 +12:00
|
|
|
});
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2020-03-14 22:22:29 +03:00
|
|
|
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
|
2021-11-19 22:03:43 +01:00
|
|
|
if let FnKind::Fn(_, _, sig, _, generics, body) = fn_kind {
|
2022-11-19 19:17:14 -03:00
|
|
|
if let Async::Yes { closure_id, .. } = sig.header.asyncness {
|
2021-11-19 22:03:43 +01:00
|
|
|
self.visit_generics(generics);
|
|
|
|
|
2020-03-14 22:22:29 +03:00
|
|
|
// For async functions, we need to create their inner defs inside of a
|
|
|
|
// closure to match their desugared representation. Besides that,
|
|
|
|
// we must mirror everything that `visit::walk_fn` below does.
|
|
|
|
self.visit_fn_header(&sig.header);
|
2021-02-13 20:41:02 +01:00
|
|
|
for param in &sig.decl.inputs {
|
|
|
|
self.visit_param(param);
|
|
|
|
}
|
2022-11-19 19:17:14 -03:00
|
|
|
self.visit_fn_ret_ty(&sig.decl.output);
|
2022-09-24 18:53:53 +00:00
|
|
|
// If this async fn has no body (i.e. it's an async fn signature in a trait)
|
|
|
|
// then the closure_def will never be used, and we should avoid generating a
|
|
|
|
// def-id for it.
|
|
|
|
if let Some(body) = body {
|
|
|
|
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
|
|
|
|
self.with_parent(closure_def, |this| this.visit_block(body));
|
|
|
|
}
|
2020-03-14 22:22:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-12 13:13:22 +10:00
|
|
|
visit::walk_fn(self, fn_kind);
|
2020-03-14 22:22:29 +03:00
|
|
|
}
|
|
|
|
|
2017-09-26 23:04:00 +02:00
|
|
|
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
2022-05-12 20:12:35 +02:00
|
|
|
self.create_def(id, DefPathData::Use, use_tree.span);
|
2017-09-26 23:04:00 +02:00
|
|
|
visit::walk_use_tree(self, use_tree, id);
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
|
2020-02-29 19:32:20 +03:00
|
|
|
if let ForeignItemKind::MacCall(_) = foreign_item.kind {
|
2018-05-17 21:28:50 +03:00
|
|
|
return self.visit_macro_invoc(foreign_item.id);
|
2018-03-10 18:16:26 -08:00
|
|
|
}
|
|
|
|
|
2016-08-09 10:25:31 -04:00
|
|
|
let def = self.create_def(
|
|
|
|
foreign_item.id,
|
2019-10-21 14:25:08 +11:00
|
|
|
DefPathData::ValueNs(foreign_item.ident.name),
|
2018-02-17 13:22:58 +01:00
|
|
|
foreign_item.span,
|
|
|
|
);
|
2016-04-14 12:14:03 +12:00
|
|
|
|
2016-04-14 17:24:30 +12:00
|
|
|
self.with_parent(def, |this| {
|
|
|
|
visit::walk_foreign_item(this, foreign_item);
|
|
|
|
});
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2019-08-24 13:54:40 -03:00
|
|
|
fn visit_variant(&mut self, v: &'a Variant) {
|
2019-09-09 09:26:25 -03:00
|
|
|
if v.is_placeholder {
|
|
|
|
return self.visit_macro_invoc(v.id);
|
|
|
|
}
|
2019-10-21 14:25:08 +11:00
|
|
|
let def = self.create_def(v.id, DefPathData::TypeNs(v.ident.name), v.span);
|
2019-03-21 23:38:50 +01:00
|
|
|
self.with_parent(def, |this| {
|
2022-10-25 20:15:15 +04:00
|
|
|
if let Some(ctor_node_id) = v.data.ctor_node_id() {
|
|
|
|
this.create_def(ctor_node_id, DefPathData::Ctor, v.span);
|
2019-03-21 23:38:50 +01:00
|
|
|
}
|
2019-08-24 13:54:40 -03:00
|
|
|
visit::walk_variant(this, v)
|
2019-03-21 23:38:50 +01:00
|
|
|
});
|
2018-05-17 21:28:50 +03:00
|
|
|
}
|
|
|
|
|
2019-08-24 13:54:40 -03:00
|
|
|
fn visit_variant_data(&mut self, data: &'a VariantData) {
|
2019-09-14 13:56:44 +03:00
|
|
|
// The assumption here is that non-`cfg` macro expansion cannot change field indices.
|
|
|
|
// It currently holds because only inert attributes are accepted on fields,
|
|
|
|
// and every such attribute expands into a single field after it's resolved.
|
2018-05-17 21:28:50 +03:00
|
|
|
for (index, field) in data.fields().iter().enumerate() {
|
2019-09-14 17:36:27 +03:00
|
|
|
self.collect_field(field, Some(index));
|
2018-05-17 21:28:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-27 20:07:09 +01:00
|
|
|
fn visit_generic_param(&mut self, param: &'a GenericParam) {
|
2019-09-09 09:26:25 -03:00
|
|
|
if param.is_placeholder {
|
|
|
|
self.visit_macro_invoc(param.id);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-21 14:25:08 +11:00
|
|
|
let name = param.ident.name;
|
2018-05-26 19:16:21 +01:00
|
|
|
let def_path_data = match param.kind {
|
2019-05-03 22:45:36 +03:00
|
|
|
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeNs(name),
|
2019-05-03 21:51:24 +03:00
|
|
|
GenericParamKind::Type { .. } => DefPathData::TypeNs(name),
|
2019-05-03 22:28:29 +03:00
|
|
|
GenericParamKind::Const { .. } => DefPathData::ValueNs(name),
|
2018-05-26 19:16:21 +01:00
|
|
|
};
|
2019-05-08 22:07:12 +03:00
|
|
|
self.create_def(param.id, def_path_data, param.ident.span);
|
2016-04-14 12:14:03 +12:00
|
|
|
|
2021-02-13 20:41:02 +01:00
|
|
|
// impl-Trait can happen inside generic parameters, like
|
|
|
|
// ```
|
|
|
|
// fn foo<U: Iterator<Item = impl Clone>>() {}
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// In that case, the impl-trait is lowered as an additional generic parameter.
|
|
|
|
self.with_impl_trait(ImplTraitContext::Universal(self.parent_def), |this| {
|
|
|
|
visit::walk_generic_param(this, param)
|
|
|
|
});
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2020-01-30 00:18:54 +01:00
|
|
|
fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
|
|
|
|
let def_data = match &i.kind {
|
2020-02-29 15:51:08 +03:00
|
|
|
AssocItemKind::Fn(..) | AssocItemKind::Const(..) => DefPathData::ValueNs(i.ident.name),
|
2022-10-10 02:05:24 +00:00
|
|
|
AssocItemKind::Type(..) => DefPathData::TypeNs(i.ident.name),
|
2020-02-29 19:32:20 +03:00
|
|
|
AssocItemKind::MacCall(..) => return self.visit_macro_invoc(i.id),
|
2016-04-14 12:14:03 +12:00
|
|
|
};
|
|
|
|
|
2020-01-30 00:18:54 +01:00
|
|
|
let def = self.create_def(i.id, def_data, i.span);
|
|
|
|
self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_pat(&mut self, pat: &'a Pat) {
|
2019-09-26 16:18:31 +01:00
|
|
|
match pat.kind {
|
2020-03-20 15:03:11 +01:00
|
|
|
PatKind::MacCall(..) => self.visit_macro_invoc(pat.id),
|
2017-04-29 14:39:47 +03:00
|
|
|
_ => visit::walk_pat(self, pat),
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 21:28:50 +03:00
|
|
|
fn visit_anon_const(&mut self, constant: &'a AnonConst) {
|
|
|
|
let def = self.create_def(constant.id, DefPathData::AnonConst, constant.value.span);
|
|
|
|
self.with_parent(def, |this| visit::walk_anon_const(this, constant));
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_expr(&mut self, expr: &'a Expr) {
|
2019-09-26 14:39:48 +01:00
|
|
|
let parent_def = match expr.kind {
|
2020-02-29 19:32:20 +03:00
|
|
|
ExprKind::MacCall(..) => return self.visit_macro_invoc(expr.id),
|
2022-09-08 10:52:51 +10:00
|
|
|
ExprKind::Closure(ref closure) => {
|
2018-06-06 15:50:59 -07:00
|
|
|
// Async closures desugar to closures inside of closures, so
|
|
|
|
// we must create two defs.
|
2019-07-02 23:42:00 +03:00
|
|
|
let closure_def = self.create_def(expr.id, DefPathData::ClosureExpr, expr.span);
|
2022-09-08 10:52:51 +10:00
|
|
|
match closure.asyncness {
|
2020-01-30 05:31:04 +01:00
|
|
|
Async::Yes { closure_id, .. } => {
|
2019-07-02 23:42:00 +03:00
|
|
|
self.create_def(closure_id, DefPathData::ClosureExpr, expr.span)
|
2019-12-22 17:42:04 -05:00
|
|
|
}
|
2020-01-30 05:31:04 +01:00
|
|
|
Async::No => closure_def,
|
2018-06-06 15:50:59 -07:00
|
|
|
}
|
|
|
|
}
|
2023-10-20 21:26:57 +00:00
|
|
|
ExprKind::Gen(_, _, _) => self.create_def(expr.id, DefPathData::ClosureExpr, expr.span),
|
2019-07-02 23:42:00 +03:00
|
|
|
_ => self.parent_def,
|
2018-06-06 15:50:59 -07:00
|
|
|
};
|
2016-04-14 12:14:03 +12:00
|
|
|
|
2019-07-02 23:42:00 +03:00
|
|
|
self.with_parent(parent_def, |this| visit::walk_expr(this, expr));
|
2016-04-14 12:14:03 +12:00
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_ty(&mut self, ty: &'a Ty) {
|
2019-09-26 17:25:31 +01:00
|
|
|
match ty.kind {
|
2020-10-04 22:48:57 +02:00
|
|
|
TyKind::MacCall(..) => self.visit_macro_invoc(ty.id),
|
|
|
|
_ => visit::walk_ty(self, ty),
|
2016-07-22 18:56:22 +03:00
|
|
|
}
|
2016-05-02 23:11:19 +03:00
|
|
|
}
|
|
|
|
|
2016-12-06 11:26:52 +01:00
|
|
|
fn visit_stmt(&mut self, stmt: &'a Stmt) {
|
2019-09-26 17:34:50 +01:00
|
|
|
match stmt.kind {
|
2020-02-29 19:32:20 +03:00
|
|
|
StmtKind::MacCall(..) => self.visit_macro_invoc(stmt.id),
|
2016-09-14 09:55:20 +00:00
|
|
|
_ => visit::walk_stmt(self, stmt),
|
|
|
|
}
|
|
|
|
}
|
2017-10-23 17:22:28 +09:00
|
|
|
|
2019-09-09 09:26:25 -03:00
|
|
|
fn visit_arm(&mut self, arm: &'a Arm) {
|
|
|
|
if arm.is_placeholder { self.visit_macro_invoc(arm.id) } else { visit::walk_arm(self, arm) }
|
|
|
|
}
|
|
|
|
|
2021-03-16 00:36:07 +03:00
|
|
|
fn visit_expr_field(&mut self, f: &'a ExprField) {
|
|
|
|
if f.is_placeholder {
|
|
|
|
self.visit_macro_invoc(f.id)
|
|
|
|
} else {
|
|
|
|
visit::walk_expr_field(self, f)
|
|
|
|
}
|
2019-09-09 09:26:25 -03:00
|
|
|
}
|
|
|
|
|
2021-03-16 00:36:07 +03:00
|
|
|
fn visit_pat_field(&mut self, fp: &'a PatField) {
|
2019-09-09 09:26:25 -03:00
|
|
|
if fp.is_placeholder {
|
|
|
|
self.visit_macro_invoc(fp.id)
|
|
|
|
} else {
|
2021-03-16 00:36:07 +03:00
|
|
|
visit::walk_pat_field(self, fp)
|
2019-09-09 09:26:25 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn visit_param(&mut self, p: &'a Param) {
|
2021-02-13 20:41:02 +01:00
|
|
|
if p.is_placeholder {
|
|
|
|
self.visit_macro_invoc(p.id)
|
|
|
|
} else {
|
|
|
|
self.with_impl_trait(ImplTraitContext::Universal(self.parent_def), |this| {
|
|
|
|
visit::walk_param(this, p)
|
|
|
|
})
|
|
|
|
}
|
2019-09-09 09:26:25 -03:00
|
|
|
}
|
|
|
|
|
2019-09-14 13:56:44 +03:00
|
|
|
// This method is called only when we are visiting an individual field
|
|
|
|
// after expanding an attribute on it.
|
2021-03-16 00:36:07 +03:00
|
|
|
fn visit_field_def(&mut self, field: &'a FieldDef) {
|
2019-09-14 17:36:27 +03:00
|
|
|
self.collect_field(field, None);
|
2019-09-09 09:26:25 -03:00
|
|
|
}
|
2021-10-17 19:32:34 +03:00
|
|
|
|
|
|
|
fn visit_crate(&mut self, krate: &'a Crate) {
|
2022-01-05 16:09:55 +08:00
|
|
|
if krate.is_placeholder {
|
|
|
|
self.visit_macro_invoc(krate.id)
|
2021-10-17 19:32:34 +03:00
|
|
|
} else {
|
|
|
|
visit::walk_crate(self, krate)
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 22:18:39 +01:00
|
|
|
}
|