1use std::mem;
2
3use rustc_ast::visit::FnKind;
4use rustc_ast::*;
5use rustc_attr_parsing::{AttributeParser, Early, OmitDoc, ShouldEmit};
6use rustc_expand::expand::AstFragment;
7use rustc_hir as hir;
8use rustc_hir::Target;
9use rustc_hir::def::{CtorKind, CtorOf, DefKind};
10use rustc_hir::def_id::LocalDefId;
11use rustc_middle::span_bug;
12use rustc_span::hygiene::LocalExpnId;
13use rustc_span::{Span, Symbol, sym};
14use tracing::{debug, instrument};
15
16use crate::{ConstArgContext, ImplTraitContext, InvocationParent, Resolver};
17
18pub(crate) fn collect_definitions(
19 resolver: &mut Resolver<'_, '_>,
20 fragment: &AstFragment,
21 expansion: LocalExpnId,
22) {
23 let invocation_parent = resolver.invocation_parents[&expansion];
24 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_resolve/src/def_collector.rs:24",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(24u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("new fragment to visit with invocation_parent: {0:?}",
invocation_parent) as &dyn Value))])
});
} else { ; }
};debug!("new fragment to visit with invocation_parent: {invocation_parent:?}");
25 let mut visitor = DefCollector { resolver, expansion, invocation_parent };
26 fragment.visit_with(&mut visitor);
27}
28
29struct DefCollector<'a, 'ra, 'tcx> {
31 resolver: &'a mut Resolver<'ra, 'tcx>,
32 invocation_parent: InvocationParent,
33 expansion: LocalExpnId,
34}
35
36impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
37 fn create_def(
38 &mut self,
39 node_id: NodeId,
40 name: Option<Symbol>,
41 def_kind: DefKind,
42 span: Span,
43 ) -> LocalDefId {
44 let parent_def = self.invocation_parent.parent_def;
45 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_resolve/src/def_collector.rs:45",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(45u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::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 Value))])
});
} else { ; }
};debug!(
46 "create_def(node_id={:?}, def_kind={:?}, parent_def={:?})",
47 node_id, def_kind, parent_def
48 );
49 self.resolver
50 .create_def(
51 parent_def,
52 node_id,
53 name,
54 def_kind,
55 self.expansion.to_expn_id(),
56 span.with_parent(None),
57 )
58 .def_id()
59 }
60
61 fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_def: LocalDefId, f: F) {
62 let orig_parent_def = mem::replace(&mut self.invocation_parent.parent_def, parent_def);
63 f(self);
64 self.invocation_parent.parent_def = orig_parent_def;
65 }
66
67 fn with_impl_trait<F: FnOnce(&mut Self)>(
68 &mut self,
69 impl_trait_context: ImplTraitContext,
70 f: F,
71 ) {
72 let orig_itc =
73 mem::replace(&mut self.invocation_parent.impl_trait_context, impl_trait_context);
74 f(self);
75 self.invocation_parent.impl_trait_context = orig_itc;
76 }
77
78 fn with_const_arg<F: FnOnce(&mut Self)>(&mut self, ctxt: ConstArgContext, f: F) {
79 let orig = mem::replace(&mut self.invocation_parent.const_arg_context, ctxt);
80 f(self);
81 self.invocation_parent.const_arg_context = orig;
82 }
83
84 fn collect_field(&mut self, field: &'a FieldDef, index: Option<usize>) {
85 let index = |this: &Self| {
86 index.unwrap_or_else(|| {
87 let node_id = NodeId::placeholder_from_expn_id(this.expansion);
88 this.resolver.placeholder_field_indices[&node_id]
89 })
90 };
91
92 if field.is_placeholder {
93 let old_index = self.resolver.placeholder_field_indices.insert(field.id, index(self));
94 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");
95 self.visit_macro_invoc(field.id);
96 } else {
97 let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
98 let def = self.create_def(field.id, Some(name), DefKind::Field, field.span);
99 self.with_parent(def, |this| visit::walk_field_def(this, field));
100 }
101 }
102
103 #[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("compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(103u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&["id"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn 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 compiler/rustc_resolve/src/def_collector.rs:105",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(105u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&["self.invocation_parent"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self.invocation_parent)
as &dyn Value))])
});
} else { ; }
};
let id = id.placeholder_to_expn_id();
let old_parent =
self.resolver.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))]
104 fn visit_macro_invoc(&mut self, id: NodeId) {
105 debug!(?self.invocation_parent);
106
107 let id = id.placeholder_to_expn_id();
108 let old_parent = self.resolver.invocation_parents.insert(id, self.invocation_parent);
109 assert!(old_parent.is_none(), "parent `LocalDefId` is reset for an invocation");
110 }
111}
112
113impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
114 fn visit_item(&mut self, i: &'a Item) {
115 let mut opt_macro_data = None;
118 let def_kind = match &i.kind {
119 ItemKind::Impl(i) => DefKind::Impl { of_trait: i.of_trait.is_some() },
120 ItemKind::ForeignMod(..) => DefKind::ForeignMod,
121 ItemKind::Mod(..) => DefKind::Mod,
122 ItemKind::Trait(..) => DefKind::Trait,
123 ItemKind::TraitAlias(..) => DefKind::TraitAlias,
124 ItemKind::Enum(..) => DefKind::Enum,
125 ItemKind::Struct(..) => DefKind::Struct,
126 ItemKind::Union(..) => DefKind::Union,
127 ItemKind::ExternCrate(..) => DefKind::ExternCrate,
128 ItemKind::TyAlias(..) => DefKind::TyAlias,
129 ItemKind::Static(s) => DefKind::Static {
130 safety: hir::Safety::Safe,
131 mutability: s.mutability,
132 nested: false,
133 },
134 ItemKind::Const(citem) => {
135 let is_type_const = #[allow(non_exhaustive_omitted_patterns)] match citem.rhs_kind {
ConstItemRhsKind::TypeConst { .. } => true,
_ => false,
}matches!(citem.rhs_kind, ConstItemRhsKind::TypeConst { .. });
136 DefKind::Const { is_type_const }
137 }
138 ItemKind::ConstBlock(..) => DefKind::Const { is_type_const: false },
139 ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn,
140 ItemKind::MacroDef(ident, def) => {
141 let edition = i.span.edition();
142
143 let mut parser = AttributeParser::<'_, Early>::new(
147 &self.resolver.tcx.sess,
148 self.resolver.tcx.features(),
149 Vec::new(),
150 Early { emit_errors: ShouldEmit::Nothing },
151 );
152 let attrs = parser.parse_attribute_list(
153 &i.attrs,
154 i.span,
155 Target::MacroDef,
156 OmitDoc::Skip,
157 std::convert::identity,
158 |_lint_id, _span, _kind| {
159 },
163 );
164
165 let macro_data =
166 self.resolver.compile_macro(def, *ident, &attrs, i.span, i.id, edition);
167 let macro_kinds = macro_data.ext.macro_kinds();
168 opt_macro_data = Some(macro_data);
169 DefKind::Macro(macro_kinds)
170 }
171 ItemKind::GlobalAsm(..) => DefKind::GlobalAsm,
172 ItemKind::Use(_) => {
173 self.create_def(i.id, None, DefKind::Use, i.span);
174 return visit::walk_item(self, i);
175 }
176 ItemKind::MacCall(..) | ItemKind::DelegationMac(..) => {
177 return self.visit_macro_invoc(i.id);
178 }
179 };
180 let def_id =
181 self.create_def(i.id, i.kind.ident().map(|ident| ident.name), def_kind, i.span);
182
183 if let Some(macro_data) = opt_macro_data {
184 self.resolver.new_local_macro(def_id, macro_data);
185 }
186
187 self.with_parent(def_id, |this| {
188 this.with_impl_trait(ImplTraitContext::Existential, |this| {
189 match i.kind {
190 ItemKind::Struct(_, _, ref struct_def)
191 | ItemKind::Union(_, _, ref struct_def) => {
192 if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
194 this.create_def(
195 ctor_node_id,
196 None,
197 DefKind::Ctor(CtorOf::Struct, ctor_kind),
198 i.span,
199 );
200 }
201 }
202 _ => {}
203 }
204 visit::walk_item(this, i);
205 })
206 });
207 }
208
209 fn visit_fn(&mut self, fn_kind: FnKind<'a>, _: &AttrVec, span: Span, _: NodeId) {
210 match fn_kind {
211 FnKind::Fn(
212 ctxt,
213 _vis,
214 Fn {
215 sig: FnSig { header, decl, span: _ }, ident, generics, contract, body, ..
216 },
217 ) if let Some(coroutine_kind) = header.coroutine_kind
218 && ctxt != visit::FnCtxt::Foreign =>
220 {
221 self.visit_ident(ident);
222 self.visit_fn_header(header);
223 self.visit_generics(generics);
224 if let Some(contract) = contract {
225 self.visit_contract(contract);
226 }
227
228 let FnDecl { inputs, output } = &**decl;
232 for param in inputs {
233 self.visit_param(param);
234 }
235
236 let (return_id, return_span) = coroutine_kind.return_id();
237 let return_def = self.create_def(return_id, None, DefKind::OpaqueTy, return_span);
238 self.with_parent(return_def, |this| this.visit_fn_ret_ty(output));
239
240 if let Some(body) = body {
244 let closure_def =
245 self.create_def(coroutine_kind.closure_id(), None, DefKind::Closure, span);
246 self.with_parent(closure_def, |this| this.visit_block(body));
247 }
248 }
249 FnKind::Closure(binder, Some(coroutine_kind), decl, body) => {
250 self.visit_closure_binder(binder);
251 visit::walk_fn_decl(self, decl);
252
253 let coroutine_def =
256 self.create_def(coroutine_kind.closure_id(), None, DefKind::Closure, span);
257 self.with_parent(coroutine_def, |this| this.visit_expr(body));
258 }
259 _ => visit::walk_fn(self, fn_kind),
260 }
261 }
262
263 fn visit_nested_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId) {
264 self.create_def(id, None, DefKind::Use, use_tree.span());
265 visit::walk_use_tree(self, use_tree);
266 }
267
268 fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
269 let (ident, def_kind) = match fi.kind {
270 ForeignItemKind::Static(box StaticItem {
271 ident,
272 ty: _,
273 mutability,
274 expr: _,
275 safety,
276 define_opaque: _,
277 eii_impls: _,
278 }) => {
279 let safety = match safety {
280 ast::Safety::Unsafe(_) | ast::Safety::Default => hir::Safety::Unsafe,
281 ast::Safety::Safe(_) => hir::Safety::Safe,
282 };
283
284 (ident, DefKind::Static { safety, mutability, nested: false })
285 }
286 ForeignItemKind::Fn(box Fn { ident, .. }) => (ident, DefKind::Fn),
287 ForeignItemKind::TyAlias(box TyAlias { ident, .. }) => (ident, DefKind::ForeignTy),
288 ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
289 };
290
291 let def = self.create_def(fi.id, Some(ident.name), def_kind, fi.span);
292
293 self.with_parent(def, |this| visit::walk_item(this, fi));
294 }
295
296 fn visit_variant(&mut self, v: &'a Variant) {
297 if v.is_placeholder {
298 return self.visit_macro_invoc(v.id);
299 }
300 let def = self.create_def(v.id, Some(v.ident.name), DefKind::Variant, v.span);
301 self.with_parent(def, |this| {
302 if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(&v.data) {
303 this.create_def(
304 ctor_node_id,
305 None,
306 DefKind::Ctor(CtorOf::Variant, ctor_kind),
307 v.span,
308 );
309 }
310 visit::walk_variant(this, v)
311 });
312 }
313
314 fn visit_where_predicate(&mut self, pred: &'a WherePredicate) {
315 if pred.is_placeholder {
316 self.visit_macro_invoc(pred.id)
317 } else {
318 visit::walk_where_predicate(self, pred)
319 }
320 }
321
322 fn visit_variant_data(&mut self, data: &'a VariantData) {
323 for (index, field) in data.fields().iter().enumerate() {
327 self.collect_field(field, Some(index));
328 }
329 }
330
331 fn visit_generic_param(&mut self, param: &'a GenericParam) {
332 if param.is_placeholder {
333 self.visit_macro_invoc(param.id);
334 return;
335 }
336 let def_kind = match param.kind {
337 GenericParamKind::Lifetime { .. } => DefKind::LifetimeParam,
338 GenericParamKind::Type { .. } => DefKind::TyParam,
339 GenericParamKind::Const { .. } => DefKind::ConstParam,
340 };
341 self.create_def(param.id, Some(param.ident.name), def_kind, param.ident.span);
342
343 self.with_impl_trait(ImplTraitContext::Universal, |this| {
350 visit::walk_generic_param(this, param)
351 });
352 }
353
354 fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
355 let (ident, def_kind) = match &i.kind {
356 AssocItemKind::Fn(box Fn { ident, .. })
357 | AssocItemKind::Delegation(box Delegation { ident, .. }) => (*ident, DefKind::AssocFn),
358 AssocItemKind::Const(box ConstItem { ident, rhs_kind, .. }) => (
359 *ident,
360 DefKind::AssocConst {
361 is_type_const: #[allow(non_exhaustive_omitted_patterns)] match rhs_kind {
ConstItemRhsKind::TypeConst { .. } => true,
_ => false,
}matches!(rhs_kind, ConstItemRhsKind::TypeConst { .. }),
362 },
363 ),
364 AssocItemKind::Type(box TyAlias { ident, .. }) => (*ident, DefKind::AssocTy),
365 AssocItemKind::MacCall(..) => {
366 return self.visit_macro_invoc(i.id);
367 }
368 AssocItemKind::DelegationMac(..) => {
369 ::rustc_middle::util::bug::span_bug_fmt(i.span,
format_args!("degation mac invoc should have already been handled"))span_bug!(i.span, "degation mac invoc should have already been handled")
370 }
371 };
372
373 let def = self.create_def(i.id, Some(ident.name), def_kind, i.span);
374 self.with_parent(def, |this| visit::walk_assoc_item(this, i, ctxt));
375 }
376
377 fn visit_pat(&mut self, pat: &'a Pat) {
378 match pat.kind {
379 PatKind::MacCall(..) => self.visit_macro_invoc(pat.id),
380 _ => visit::walk_pat(self, pat),
381 }
382 }
383
384 fn visit_anon_const(&mut self, constant: &'a AnonConst) {
385 if !self.resolver.tcx.features().min_generic_const_args() {
389 let parent =
390 self.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
391 return self.with_parent(parent, |this| visit::walk_anon_const(this, constant));
392 }
393
394 match constant.mgca_disambiguation {
395 MgcaDisambiguation::Direct => self.with_const_arg(ConstArgContext::Direct, |this| {
396 visit::walk_anon_const(this, constant);
397 }),
398 MgcaDisambiguation::AnonConst => {
399 self.with_const_arg(ConstArgContext::NonDirect, |this| {
400 let parent =
401 this.create_def(constant.id, None, DefKind::AnonConst, constant.value.span);
402 this.with_parent(parent, |this| visit::walk_anon_const(this, constant));
403 })
404 }
405 };
406 }
407
408 #[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("compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(408u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&["expr"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn 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 compiler/rustc_resolve/src/def_collector.rs:410",
"rustc_resolve::def_collector", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_resolve/src/def_collector.rs"),
::tracing_core::__macro_support::Option::Some(410u32),
::tracing_core::__macro_support::Option::Some("rustc_resolve::def_collector"),
::tracing_core::field::FieldSet::new(&["self.invocation_parent"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self.invocation_parent)
as &dyn Value))])
});
} else { ; }
};
let parent_def =
match &expr.kind {
ExprKind::MacCall(..) =>
return self.visit_macro_invoc(expr.id),
ExprKind::Closure(..) | ExprKind::Gen(..) => {
self.create_def(expr.id, None, DefKind::Closure, expr.span)
}
ExprKind::ConstBlock(constant) => {
let def_kind =
match self.invocation_parent.const_arg_context {
ConstArgContext::Direct => DefKind::AnonConst,
ConstArgContext::NonDirect => DefKind::InlineConst,
};
return self.with_const_arg(ConstArgContext::NonDirect,
|this|
{
for attr in &expr.attrs {
visit::walk_attribute(this, attr);
}
let def =
this.create_def(constant.id, None, def_kind,
constant.value.span);
this.with_parent(def,
|this| visit::walk_anon_const(this, constant));
});
}
ExprKind::Struct(_) | ExprKind::Call(..) | ExprKind::Tup(..)
| ExprKind::Array(..) => {
return visit::walk_expr(self, expr);
}
ExprKind::Block(block, _) if
let [stmt] = block.stmts.as_slice() =>
match stmt.kind {
StmtKind::Expr(..) | StmtKind::MacCall(..) =>
return visit::walk_expr(self, expr),
StmtKind::Let(..) | StmtKind::Item(..) | StmtKind::Semi(..)
| StmtKind::Empty => {
self.invocation_parent.parent_def
}
},
_ => self.invocation_parent.parent_def,
};
self.with_const_arg(ConstArgContext::NonDirect,
|this|
{
this.with_parent(parent_def,
|this| visit::walk_expr(this, expr))
})
}
}
}#[instrument(level = "debug", skip(self))]
409 fn visit_expr(&mut self, expr: &'a Expr) {
410 debug!(?self.invocation_parent);
411
412 let parent_def = match &expr.kind {
413 ExprKind::MacCall(..) => return self.visit_macro_invoc(expr.id),
414 ExprKind::Closure(..) | ExprKind::Gen(..) => {
415 self.create_def(expr.id, None, DefKind::Closure, expr.span)
416 }
417 ExprKind::ConstBlock(constant) => {
418 let def_kind = match self.invocation_parent.const_arg_context {
421 ConstArgContext::Direct => DefKind::AnonConst,
422 ConstArgContext::NonDirect => DefKind::InlineConst,
423 };
424
425 return self.with_const_arg(ConstArgContext::NonDirect, |this| {
426 for attr in &expr.attrs {
427 visit::walk_attribute(this, attr);
428 }
429
430 let def = this.create_def(constant.id, None, def_kind, constant.value.span);
431 this.with_parent(def, |this| visit::walk_anon_const(this, constant));
432 });
433 }
434
435 ExprKind::Struct(_) | ExprKind::Call(..) | ExprKind::Tup(..) | ExprKind::Array(..) => {
438 return visit::walk_expr(self, expr);
439 }
440 ExprKind::Block(block, _) if let [stmt] = block.stmts.as_slice() => match stmt.kind {
442 StmtKind::Expr(..) | StmtKind::MacCall(..) => return visit::walk_expr(self, expr),
446
447 StmtKind::Let(..) | StmtKind::Item(..) | StmtKind::Semi(..) | StmtKind::Empty => {
449 self.invocation_parent.parent_def
450 }
451 },
452
453 _ => self.invocation_parent.parent_def,
454 };
455
456 self.with_const_arg(ConstArgContext::NonDirect, |this| {
457 this.with_parent(parent_def, |this| visit::walk_expr(this, expr))
460 })
461 }
462
463 fn visit_ty(&mut self, ty: &'a Ty) {
464 match ty.kind {
465 TyKind::MacCall(..) => self.visit_macro_invoc(ty.id),
466 TyKind::ImplTrait(opaque_id, _) => {
467 let name = *self
468 .resolver
469 .impl_trait_names
470 .get(&ty.id)
471 .unwrap_or_else(|| ::rustc_middle::util::bug::span_bug_fmt(ty.span,
format_args!("expected this opaque to be named"))span_bug!(ty.span, "expected this opaque to be named"));
472 let kind = match self.invocation_parent.impl_trait_context {
473 ImplTraitContext::Universal => DefKind::TyParam,
474 ImplTraitContext::Existential => DefKind::OpaqueTy,
475 ImplTraitContext::InBinding => return visit::walk_ty(self, ty),
476 };
477 let id = self.create_def(opaque_id, Some(name), kind, ty.span);
478 match self.invocation_parent.impl_trait_context {
479 ImplTraitContext::Universal => visit::walk_ty(self, ty),
482 ImplTraitContext::Existential => {
483 self.with_parent(id, |this| visit::walk_ty(this, ty))
484 }
485 ImplTraitContext::InBinding => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
486 };
487 }
488 _ => visit::walk_ty(self, ty),
489 }
490 }
491
492 fn visit_stmt(&mut self, stmt: &'a Stmt) {
493 match stmt.kind {
494 StmtKind::MacCall(..) => self.visit_macro_invoc(stmt.id),
495 StmtKind::Let(ref local) => self.with_impl_trait(ImplTraitContext::InBinding, |this| {
500 visit::walk_local(this, local)
501 }),
502 _ => visit::walk_stmt(self, stmt),
503 }
504 }
505
506 fn visit_arm(&mut self, arm: &'a Arm) {
507 if arm.is_placeholder { self.visit_macro_invoc(arm.id) } else { visit::walk_arm(self, arm) }
508 }
509
510 fn visit_expr_field(&mut self, f: &'a ExprField) {
511 if f.is_placeholder {
512 self.visit_macro_invoc(f.id)
513 } else {
514 visit::walk_expr_field(self, f)
515 }
516 }
517
518 fn visit_pat_field(&mut self, fp: &'a PatField) {
519 if fp.is_placeholder {
520 self.visit_macro_invoc(fp.id)
521 } else {
522 visit::walk_pat_field(self, fp)
523 }
524 }
525
526 fn visit_param(&mut self, p: &'a Param) {
527 if p.is_placeholder {
528 self.visit_macro_invoc(p.id)
529 } else {
530 self.with_impl_trait(ImplTraitContext::Universal, |this| visit::walk_param(this, p))
531 }
532 }
533
534 fn visit_field_def(&mut self, field: &'a FieldDef) {
537 self.collect_field(field, None);
538 }
539
540 fn visit_crate(&mut self, krate: &'a Crate) {
541 if krate.is_placeholder {
542 self.visit_macro_invoc(krate.id)
543 } else {
544 visit::walk_crate(self, krate)
545 }
546 }
547
548 fn visit_attribute(&mut self, attr: &'a Attribute) -> Self::Result {
549 let orig_in_attr = mem::replace(&mut self.invocation_parent.in_attr, true);
550 visit::walk_attribute(self, attr);
551 self.invocation_parent.in_attr = orig_in_attr;
552 }
553
554 fn visit_inline_asm(&mut self, asm: &'a InlineAsm) {
555 let InlineAsm {
556 asm_macro: _,
557 template: _,
558 template_strs: _,
559 operands,
560 clobber_abis: _,
561 options: _,
562 line_spans: _,
563 } = asm;
564 for (op, _span) in operands {
565 match op {
566 InlineAsmOperand::In { expr, reg: _ }
567 | InlineAsmOperand::Out { expr: Some(expr), reg: _, late: _ }
568 | InlineAsmOperand::InOut { expr, reg: _, late: _ } => {
569 self.visit_expr(expr);
570 }
571 InlineAsmOperand::Out { expr: None, reg: _, late: _ } => {}
572 InlineAsmOperand::SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
573 self.visit_expr(in_expr);
574 if let Some(expr) = out_expr {
575 self.visit_expr(expr);
576 }
577 }
578 InlineAsmOperand::Const { anon_const } => {
579 let def = self.create_def(
580 anon_const.id,
581 None,
582 DefKind::InlineConst,
583 anon_const.value.span,
584 );
585 self.with_parent(def, |this| visit::walk_anon_const(this, anon_const));
586 }
587 InlineAsmOperand::Sym { sym } => self.visit_inline_asm_sym(sym),
588 InlineAsmOperand::Label { block } => self.visit_block(block),
589 }
590 }
591 }
592}