1use std::mem;
2
3use rustc_ast::visit::FnKind;
4use rustc_ast::*;
5use rustc_attr_parsing as attr;
6use rustc_attr_parsing::{AttributeParser, ShouldEmit};
7use rustc_expand::expand::AstFragment;
8use rustc_hir as hir;
9use rustc_hir::Target;
10use rustc_hir::def::DefKind;
11use rustc_hir::def::Namespace::{TypeNS, ValueNS};
12use rustc_hir::def_id::LocalDefId;
13use rustc_middle::middle::resolve::PerOwnerResolverData;
14use rustc_middle::ty::TyCtxtFeed;
15use rustc_span::{Span, Symbol, span_bug, sym};
16use tracing::{debug, instrument};
17
18use crate::macros::MacroRulesScopeRef;
19use crate::{
20 ImplTraitContext, InvocationParent, ParentScope, Resolver, with_owner, with_owner_tables,
21};
22
23pub(crate) fn collect_definitions<'ra>(
24 resolver: &mut Resolver<'ra, '_>,
25 fragment: &AstFragment,
26 parent_scope: ParentScope<'ra>,
27) -> MacroRulesScopeRef<'ra> {
28 let invocation_parent = resolver.invocation_parents[&parent_scope.expansion];
29 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs:29",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(29u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("new fragment to visit with invocation_parent: {0:?}",
invocation_parent) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("new fragment to visit with invocation_parent: {invocation_parent:?}");
30 if true {
{
match (&resolver.current_owner.id, &DUMMY_NODE_ID) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(resolver.current_owner.id, DUMMY_NODE_ID);
31 with_owner(resolver, invocation_parent.owner, |r| {
32 let mut visitor = DefCollector { r, invocation_parent, parent_scope };
33 fragment.visit_with(&mut visitor);
34 visitor.parent_scope.macro_rules
35 })
36}
37
38pub(crate) struct DefCollector<'a, 'ra, 'tcx> {
40 pub(crate) r: &'a mut Resolver<'ra, 'tcx>,
41 invocation_parent: InvocationParent,
42 pub(crate) parent_scope: ParentScope<'ra>,
43}
44
45impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
46 pub(super) fn create_def(
47 &mut self,
48 node_id: NodeId,
49 name: Option<Symbol>,
50 def_kind: DefKind,
51 span: Span,
52 ) -> TyCtxtFeed<'tcx, LocalDefId> {
53 let parent_def = self.invocation_parent.parent_def;
54 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs:54",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(54u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("create_def(node_id={0:?}, def_kind={1:?}, parent_def={2:?})",
node_id, def_kind, parent_def) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
55 "create_def(node_id={:?}, def_kind={:?}, parent_def={:?})",
56 node_id, def_kind, parent_def
57 );
58 self.r.create_def(
59 parent_def,
60 node_id,
61 name,
62 def_kind,
63 self.parent_scope.expansion.to_expn_id(),
64 span.with_parent(None),
65 false,
66 )
67 }
68
69 fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) {
70 let orig_parent_def = mem::replace(&mut self.invocation_parent.parent_def, parent_def);
71 f(self);
72 self.invocation_parent.parent_def = orig_parent_def;
73 }
74
75 pub(super) fn with_owner<F: FnOnce(&mut Self, TyCtxtFeed<'tcx, LocalDefId>)>(
76 &mut self,
77 owner: NodeId,
78 name: Option<Symbol>,
79 def_kind: DefKind,
80 span: Span,
81 f: F,
82 ) {
83 if true {
{
match (&owner, &DUMMY_NODE_ID) {
(left_val, right_val) => {
if *left_val == *right_val {
let kind = ::core::panicking::AssertKind::Ne;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_ne!(owner, DUMMY_NODE_ID);
84 if true {
{
match (&owner, &CRATE_NODE_ID) {
(left_val, right_val) => {
if *left_val == *right_val {
let kind = ::core::panicking::AssertKind::Ne;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_ne!(owner, CRATE_NODE_ID);
85 let parent_def = self.invocation_parent.parent_def;
89 let feed = self.r.create_def(
90 parent_def,
91 owner,
92 name,
93 def_kind,
94 self.parent_scope.expansion.to_expn_id(),
95 span.with_parent(None),
96 true,
97 );
98 let tables = PerOwnerResolverData::new(owner, feed.key());
99
100 let orig_invoc_owner = mem::replace(&mut self.invocation_parent.owner, owner);
101 with_owner_tables(self, owner, tables, |this| f(this, feed));
102 let old = mem::replace(&mut self.invocation_parent.owner, orig_invoc_owner);
103 {
match (&old, &owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(old, owner);
104 }
105
106 fn with_impl_trait<F: FnOnce(&mut Self)>(
107 &mut self,
108 impl_trait_context: ImplTraitContext,
109 f: F,
110 ) {
111 let orig_itc =
112 mem::replace(&mut self.invocation_parent.impl_trait_context, impl_trait_context);
113 f(self);
114 self.invocation_parent.impl_trait_context = orig_itc;
115 }
116
117 fn collect_field(&mut self, field: &'a FieldDef, index: Option<usize>) {
118 let index = |this: &Self| {
119 index.unwrap_or_else(|| {
120 let node_id = NodeId::placeholder_from_expn_id(this.parent_scope.expansion);
121 this.r.placeholder_field_indices[&node_id]
122 })
123 };
124
125 if field.is_placeholder {
126 let old_index = self.r.placeholder_field_indices.insert(field.id, index(self));
127 if !old_index.is_none() {
{
::core::panicking::panic_fmt(format_args!("placeholder field index is reset for a node ID"));
}
};assert!(old_index.is_none(), "placeholder field index is reset for a node ID");
128 self.visit_macro_invoc(field.id);
129 self.visit_invoc(field.id);
130 } else {
131 let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
132 let def = self.create_def(field.id, Some(name), DefKind::Field, field.span);
133 self.with_parent(def.def_id(), |this| this.brg_visit_field_def(field, def));
134 }
135 }
136
137 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("visit_macro_invoc",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(137u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs:139",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(139u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self.invocation_parent")
}> =
::tracing::__macro_support::FieldName::new("self.invocation_parent");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.invocation_parent)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let id = id.placeholder_to_expn_id();
let old_parent =
self.r.invocation_parents.insert(id, self.invocation_parent);
if !old_parent.is_none() {
{
::core::panicking::panic_fmt(format_args!("parent `LocalDefId` is reset for an invocation"));
}
};
}
}
}#[instrument(level = "debug", skip(self))]
138 fn visit_macro_invoc(&mut self, id: NodeId) {
139 debug!(?self.invocation_parent);
140
141 let id = id.placeholder_to_expn_id();
142 let old_parent = self.r.invocation_parents.insert(id, self.invocation_parent);
143 assert!(old_parent.is_none(), "parent `LocalDefId` is reset for an invocation");
144 }
145}
146
147impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
148 fn visit_item(&mut self, i: &'a Item) {
149 let mut opt_syn_ext = None;
152 let def_kind = match &i.kind {
153 ItemKind::Impl(i) => DefKind::Impl { of_trait: i.of_trait.is_some() },
154 ItemKind::ForeignMod(..) => DefKind::ForeignMod,
155 ItemKind::Mod(..) => DefKind::Mod,
156 ItemKind::Trait(..) => DefKind::Trait,
157 ItemKind::TraitAlias(..) => DefKind::TraitAlias,
158 ItemKind::Enum(..) => DefKind::Enum,
159 ItemKind::Struct(..) => DefKind::Struct,
160 ItemKind::Union(..) => DefKind::Union,
161 ItemKind::ExternCrate(..) => DefKind::ExternCrate,
162 ItemKind::TyAlias(..) => DefKind::TyAlias,
163 ItemKind::Static(s) => DefKind::Static {
164 safety: hir::Safety::Safe,
165 mutability: s.mutability,
166 nested: false,
167 },
168 ItemKind::Const(..) => DefKind::Const,
169 ItemKind::ConstBlock(..) => DefKind::Const,
170 ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
171 ItemKind::MacroDef(ident, def) => {
172 let edition = i.span.edition();
173
174 let mut parser = AttributeParser::new(
178 &self.r.tcx.sess,
179 self.r.features,
180 self.r.tcx().registered_attr_tools(()),
181 ShouldEmit::Nothing,
182 );
183 let attrs = parser.parse_attribute_list(
184 &i.attrs,
185 i.span,
186 Target::MacroDef,
187 None,
188 std::convert::identity,
189 |_lint_id, _span, _kind| {
190 },
194 );
195
196 let ext = self.r.compile_macro(def, *ident, &attrs, i.span, i.id, edition);
197 let macro_kinds = ext.macro_kinds();
198 opt_syn_ext = Some(ext);
199 DefKind::Macro(macro_kinds)
200 }
201 ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
202 ItemKind::Use(_) => {
203 return self.with_owner(i.id, None, DefKind::Use, i.span, |this, feed| {
204 this.brg_visit_item(i, feed);
205 });
206 }
207 ItemKind::MacCall(..) => {
208 self.visit_macro_invoc(i.id);
209 self.brg_visit_mac_call_in_module(i.id);
210 return;
211 }
212 ItemKind::DelegationMac(..) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
213 ItemKind::TestBinderConstraints(..) => DefKind::TestBinderConstraints,
214 };
215 self.with_owner(
216 i.id,
217 i.kind.ident().map(|ident| ident.name),
218 def_kind,
219 i.span,
220 |this, feed| {
221 if let Some(ext) = opt_syn_ext {
222 this.r.local_macro_map.insert(feed.def_id(), this.r.arenas.alloc_macro(ext));
223 }
224
225 this.with_parent(feed.def_id(), |this| {
226 this.with_impl_trait(ImplTraitContext::Existential, |this| {
227 this.brg_visit_item(i, feed)
228 })
229 });
230 },
231 );
232 }
233
234 fn visit_block(&mut self, block: &'a Block) {
235 self.brg_visit_block(block);
236 }
237
238 fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
239 match fn_kind {
240 FnKind::Fn(
241 ctxt,
242 _vis,
243 Fn {
244 sig: FnSig { header, decl, span: _ }, ident, generics, contract, body, ..
245 },
246 ) if let Some(coroutine_marker) = header.coroutine_marker
247 && ctxt != visit::FnCtxt::Foreign =>
249 {
250 self.visit_ident(ident);
251 self.visit_fn_header(header);
252 self.visit_generics(generics);
253 if let Some(contract) = contract {
254 self.visit_contract(contract);
255 }
256
257 let FnDecl { inputs, output } = &**decl;
261 for param in inputs {
262 self.visit_param(param);
263 }
264
265 let return_def = self
266 .create_def(
267 coroutine_marker.return_impl_trait_id,
268 None,
269 DefKind::OpaqueTy,
270 coroutine_marker.span,
271 )
272 .def_id();
273 self.with_parent(return_def, |this| this.visit_fn_ret_ty(output));
274
275 if let Some(body) = body {
279 let closure_def = self
280 .create_def(coroutine_marker.closure_id, None, DefKind::Closure, span)
281 .def_id();
282 self.with_parent(closure_def, |this| this.visit_block(body));
283 }
284 }
285 FnKind::Closure(binder, Some(coroutine_marker), decl, body) => {
286 self.visit_closure_binder(binder);
287 visit::walk_fn_decl(self, decl);
288
289 let coroutine_def = self
292 .create_def(coroutine_marker.closure_id, None, DefKind::Closure, span)
293 .def_id();
294 self.with_parent(coroutine_def, |this| this.visit_expr(body));
295 }
296 _ => visit::walk_fn(self, fn_kind),
297 }
298 }
299
300 fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
301 let (ident, def_kind) = match fi.kind {
302 ForeignItemKind::Static(StaticItem {
303 ident,
304 ty: _,
305 mutability,
306 expr: _,
307 safety,
308 define_opaque: _,
309 eii_impl: _,
310 }) => {
311 let safety = match safety {
312 ast::Safety::Unsafe(_) | ast::Safety::Default => hir::Safety::Unsafe,
313 ast::Safety::Safe(_) => hir::Safety::Safe,
314 };
315
316 (ident, DefKind::Static { safety, mutability, nested: false })
317 }
318 ForeignItemKind::Fn(Fn { ident, .. }) => (ident, DefKind::Fn),
319 ForeignItemKind::TyAlias(TyAlias { ident, .. }) => (ident, DefKind::ForeignTy),
320 ForeignItemKind::MacCall(_) => {
321 self.visit_invoc_in_module(fi.id);
322 self.visit_macro_invoc(fi.id);
323 return;
324 }
325 };
326
327 self.with_owner(fi.id, Some(ident.name), def_kind, fi.span, |this, def| {
328 this.with_parent(def.def_id(), |this| {
329 this.build_reduced_graph_for_foreign_item(fi, ident, def);
330 visit::walk_item(this, fi)
331 });
332 })
333 }
334
335 fn visit_variant(&mut self, v: &'a Variant) {
336 if v.is_placeholder {
337 self.visit_macro_invoc(v.id);
338 self.visit_invoc_in_module(v.id);
339 return;
340 }
341 let feed = self.create_def(v.id, Some(v.ident.name), DefKind::Variant, v.span);
342 self.with_parent(feed.def_id(), |this| this.brg_visit_variant(v, feed));
343 }
344
345 fn visit_where_predicate(&mut self, pred: &'a WherePredicate) {
346 if pred.is_placeholder {
347 self.visit_macro_invoc(pred.id);
348 self.visit_invoc(pred.id);
349 } else {
350 visit::walk_where_predicate(self, pred)
351 }
352 }
353
354 fn visit_variant_data(&mut self, data: &'a VariantData) {
355 for (index, field) in data.fields().iter().enumerate() {
359 self.collect_field(field, Some(index));
360 }
361 }
362
363 fn visit_generic_param(&mut self, param: &'a GenericParam) {
364 if param.is_placeholder {
365 self.visit_macro_invoc(param.id);
366 self.visit_invoc(param.id);
367 return;
368 }
369 let def_kind = match param.kind {
370 GenericParamKind::Lifetime { .. } => DefKind::LifetimeParam,
371 GenericParamKind::Type { .. } => DefKind::TyParam,
372 GenericParamKind::Const { .. } => DefKind::ConstParam,
373 };
374 self.create_def(param.id, Some(param.ident.name), def_kind, param.ident.span);
375
376 self.with_impl_trait(ImplTraitContext::Universal, |this| {
383 visit::walk_generic_param(this, param)
384 });
385 }
386
387 fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
388 let (ident, def_kind, ns) = match &i.kind {
389 AssocItemKind::Fn(Fn { ident, .. })
390 | AssocItemKind::Delegation(Delegation { ident, .. }) => {
391 (*ident, DefKind::AssocFn, ValueNS)
392 }
393 AssocItemKind::Const(ConstItem { ident, .. }) => (*ident, DefKind::AssocConst, ValueNS),
394 AssocItemKind::Type(TyAlias { ident, .. }) => (*ident, DefKind::AssocTy, TypeNS),
395 AssocItemKind::MacCall(..) => {
396 self.visit_macro_invoc(i.id);
397 self.visit_assoc_item_mac_call(i, ctxt);
398 return;
399 }
400 AssocItemKind::DelegationMac(..) => {
401 bug_impl(Some(i.span),
format_args!("degation mac invoc should have already been handled"),
Location::caller())span_bug!(i.span, "degation mac invoc should have already been handled")
402 }
403 };
404
405 self.with_owner(i.id, Some(ident.name), def_kind, i.span, |this, feed| {
406 this.with_parent(feed.def_id(), |this| {
407 this.brg_visit_assoc_item(i, ctxt, ident, ns, feed)
408 });
409 })
410 }
411
412 fn visit_pat(&mut self, pat: &'a Pat) {
413 match pat.kind {
414 PatKind::MacCall(..) => {
415 self.visit_macro_invoc(pat.id);
416 self.visit_invoc(pat.id);
417 }
418 _ => visit::walk_pat(self, pat),
419 }
420 }
421
422 fn visit_anon_const(&mut self, constant: &'a AnonConst) {
423 let parent =
424 self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span).def_id();
425 self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
426 }
427
428 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("visit_expr",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(428u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs:430",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(430u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self.invocation_parent")
}> =
::tracing::__macro_support::FieldName::new("self.invocation_parent");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self.invocation_parent)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match &expr.kind {
ExprKind::MacCall(..) => {
self.visit_macro_invoc(expr.id);
self.visit_invoc(expr.id);
}
ExprKind::Closure(..) | ExprKind::Gen(..) => {
let def =
self.create_def(expr.id, None, DefKind::Closure,
expr.span).def_id();
self.with_parent(def, |this| visit::walk_expr(this, expr));
}
_ => visit::walk_expr(self, expr),
}
}
}
}#[instrument(level = "debug", skip(self))]
429 fn visit_expr(&mut self, expr: &'a Expr) {
430 debug!(?self.invocation_parent);
431
432 match &expr.kind {
433 ExprKind::MacCall(..) => {
434 self.visit_macro_invoc(expr.id);
435 self.visit_invoc(expr.id);
436 }
437 ExprKind::Closure(..) | ExprKind::Gen(..) => {
438 let def = self.create_def(expr.id, None, DefKind::Closure, expr.span).def_id();
439 self.with_parent(def, |this| visit::walk_expr(this, expr));
440 }
441 _ => visit::walk_expr(self, expr),
442 }
443 }
444
445 fn visit_ty(&mut self, ty: &'a Ty) {
446 match ty.kind {
447 TyKind::MacCall(..) => {
448 self.visit_macro_invoc(ty.id);
449 self.visit_invoc(ty.id);
450 }
451 TyKind::ImplTrait(opaque_id, _) => {
452 let name = *self
453 .r
454 .impl_trait_names
455 .get(&ty.id)
456 .unwrap_or_else(|| bug_impl(Some(ty.span), format_args!("expected this opaque to be named"),
Location::caller())span_bug!(ty.span, "expected this opaque to be named"));
457 let kind = match self.invocation_parent.impl_trait_context {
458 ImplTraitContext::Universal => DefKind::TyParam,
459 ImplTraitContext::Existential => DefKind::OpaqueTy,
460 ImplTraitContext::InBinding => return visit::walk_ty(self, ty),
461 };
462 let id = self.create_def(opaque_id, Some(name), kind, ty.span).def_id();
463 match self.invocation_parent.impl_trait_context {
464 ImplTraitContext::Universal => visit::walk_ty(self, ty),
467 ImplTraitContext::Existential => {
468 self.with_parent(id, |this| visit::walk_ty(this, ty))
469 }
470 ImplTraitContext::InBinding => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
471 };
472 }
473 _ => visit::walk_ty(self, ty),
474 }
475 }
476
477 fn visit_stmt(&mut self, stmt: &'a Stmt) {
478 match stmt.kind {
479 StmtKind::MacCall(..) => {
480 self.brg_visit_mac_call_in_module(stmt.id);
481 self.visit_macro_invoc(stmt.id)
482 }
483 StmtKind::Let(ref local) => self.with_impl_trait(ImplTraitContext::InBinding, |this| {
488 visit::walk_local(this, local)
489 }),
490 _ => visit::walk_stmt(self, stmt),
491 }
492 }
493
494 fn visit_arm(&mut self, arm: &'a Arm) {
495 if arm.is_placeholder {
496 self.visit_macro_invoc(arm.id);
497 self.visit_invoc(arm.id);
498 } else {
499 visit::walk_arm(self, arm)
500 }
501 }
502
503 fn visit_expr_field(&mut self, f: &'a ExprField) {
504 if f.is_placeholder {
505 self.visit_macro_invoc(f.id);
506 self.visit_invoc(f.id);
507 } else {
508 visit::walk_expr_field(self, f)
509 }
510 }
511
512 fn visit_pat_field(&mut self, fp: &'a PatField) {
513 if fp.is_placeholder {
514 self.visit_macro_invoc(fp.id);
515 self.visit_invoc(fp.id);
516 } else {
517 visit::walk_pat_field(self, fp)
518 }
519 }
520
521 fn visit_param(&mut self, p: &'a Param) {
522 if p.is_placeholder {
523 self.visit_macro_invoc(p.id);
524 self.visit_invoc(p.id);
525 } else {
526 self.with_impl_trait(ImplTraitContext::Universal, |this| visit::walk_param(this, p))
527 }
528 }
529
530 fn visit_field_def(&mut self, field: &'a FieldDef) {
533 self.collect_field(field, None);
534 }
535
536 fn visit_crate(&mut self, krate: &'a Crate) {
537 if krate.is_placeholder {
538 self.visit_macro_invoc(krate.id);
539 self.visit_invoc_in_module(krate.id);
540 } else {
541 if true {
{
match (&self.r.current_owner.id, &CRATE_NODE_ID) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
};debug_assert_eq!(self.r.current_owner.id, CRATE_NODE_ID);
549
550 for elem in &krate.items {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_item(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};visit::walk_list!(self, visit_item, &krate.items);
551 for elem in &krate.attrs {
match ::rustc_ast_ir::visit::VisitorResult::branch(self.visit_attribute(elem))
{
core::ops::ControlFlow::Continue(()) =>
(),
#[allow(unreachable_code)]
core::ops::ControlFlow::Break(r) => {
return ::rustc_ast_ir::visit::VisitorResult::from_residual(r);
}
};
};visit::walk_list!(self, visit_attribute, &krate.attrs);
552 self.contains_macro_use(&krate.attrs);
553 }
554 }
555
556 fn visit_attribute(&mut self, attr: &'a Attribute) {
557 use SyntheticAttr::*;
558 let orig_in_attr = mem::replace(&mut self.invocation_parent.in_attr, true);
559 match &attr.kind {
560 AttrKind::Normal(normal) => {
561 if attr::is_builtin_attr(&normal.item) {
562 self.r
563 .builtin_attrs
564 .push((normal.item.path.segments[0].ident, self.parent_scope));
565 }
566 }
567 AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) => {}
568 AttrKind::DocComment(..) => {}
569 }
570 visit::walk_attribute(self, attr);
571 self.invocation_parent.in_attr = orig_in_attr;
572 }
573
574 fn visit_inline_asm(&mut self, asm: &'a InlineAsm) {
575 let InlineAsm {
576 asm_macro: _,
577 template: _,
578 template_strs: _,
579 operands,
580 clobber_abis: _,
581 options: _,
582 line_spans: _,
583 } = asm;
584 for (op, _span) in operands {
585 match op {
586 InlineAsmOperand::In { expr, reg: _ }
587 | InlineAsmOperand::Out { expr: Some(expr), reg: _, late: _ }
588 | InlineAsmOperand::InOut { expr, reg: _, late: _ } => {
589 self.visit_expr(expr);
590 }
591 InlineAsmOperand::Out { expr: None, reg: _, late: _ } => {}
592 InlineAsmOperand::SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
593 self.visit_expr(in_expr);
594 if let Some(expr) = out_expr {
595 self.visit_expr(expr);
596 }
597 }
598 InlineAsmOperand::Const { anon_const } => {
599 let def = self
600 .create_def(anon_const.id, None, DefKind::AnonConst, anon_const.value.span)
601 .def_id();
602 self.with_parent(def, |this| visit::walk_anon_const(this, anon_const));
603 }
604 InlineAsmOperand::Sym { sym } => self.visit_inline_asm_sym(sym),
605 InlineAsmOperand::Label { block } => self.visit_block(block),
606 }
607 }
608 }
609}