1#![feature(const_default)]
35#![feature(const_trait_impl)]
36#![feature(default_field_values)]
37#![feature(deref_patterns)]
38#![recursion_limit = "256"]
39use std::mem;
42use std::sync::Arc;
43
44use rustc_ast::mut_visit::{self, MutVisitor};
45use rustc_ast::node_id::NodeMap;
46use rustc_ast::visit::{self, Visitor};
47use rustc_ast::{self as ast, *};
48use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit};
49use rustc_data_structures::fx::FxIndexMap;
50use rustc_data_structures::sorted_map::SortedMap;
51use rustc_data_structures::stable_hash::{StableHash, StableHasher};
52use rustc_data_structures::steal::Steal;
53use rustc_data_structures::tagged_ptr::TaggedRef;
54use rustc_data_structures::unord::ExtendUnord;
55use rustc_errors::codes::*;
56use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
57use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
58use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
59use rustc_hir::definitions::PerParentDisambiguatorState;
60use rustc_hir::lints::DelayedLint;
61use rustc_hir::{
62 self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
63 LifetimeSyntax, MissingLifetimeKind, ParamName, Target, TraitCandidate, find_attr,
64};
65use rustc_index::{Idx, IndexVec};
66use rustc_macros::extension;
67use rustc_middle::queries::Providers;
68use rustc_middle::span_bug;
69use rustc_middle::ty::{PerOwnerResolverData, ResolverAstLowering, TyCtxt};
70use rustc_session::errors::add_feature_diagnostics;
71use rustc_span::symbol::{Ident, Symbol, kw, sym};
72use rustc_span::{DUMMY_SP, DesugaringKind, Span};
73use smallvec::{SmallVec, smallvec};
74use thin_vec::ThinVec;
75use tracing::{debug, instrument, trace};
76
77use crate::diagnostics::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
78
79macro_rules! arena_vec {
80 ($this:expr; $($x:expr),*) => (
81 $this.arena.alloc_from_iter([$($x),*])
82 );
83}
84
85mod asm;
86mod block;
87mod contract;
88mod delegation;
89mod diagnostics;
90mod expr;
91mod format;
92mod index;
93mod item;
94mod pat;
95mod path;
96pub mod stability;
97
98pub fn provide(providers: &mut Providers) {
99 providers.index_ast = index_ast;
100 providers.lower_to_hir = lower_to_hir;
101}
102
103struct LoweringContext<'a, 'hir> {
104 tcx: TyCtxt<'hir>,
105 resolver: &'a ResolverAstLowering<'hir>,
106 current_disambiguator: PerParentDisambiguatorState,
107
108 arena: &'hir hir::Arena<'hir>,
110
111 bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
113 define_opaque: Option<&'hir [(Span, LocalDefId)]>,
115 attrs: SortedMap<hir::ItemLocalId, &'hir [hir::Attribute]>,
117 children: LocalDefIdMap<hir::MaybeOwner<'hir>>,
119
120 contract_ensures: Option<(Span, Ident, HirId)>,
121
122 coroutine_kind: Option<hir::CoroutineKind>,
123
124 task_context: Option<HirId>,
127
128 current_item: Option<Span>,
131
132 try_block_scope: TryBlockScope,
133 loop_scope: Option<HirId>,
134 is_in_loop_condition: bool,
135 is_in_dyn_type: bool,
136
137 current_hir_id_owner: hir::OwnerId,
138 owner: &'a PerOwnerResolverData<'hir>,
139 item_local_id_counter: hir::ItemLocalId,
140 trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,
141
142 impl_trait_defs: Vec<hir::GenericParam<'hir>>,
143 impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
144
145 ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>,
147 #[cfg(debug_assertions)]
149 node_id_to_local_id: NodeMap<hir::ItemLocalId>,
150 next_node_id: NodeId,
154 node_id_to_def_id: NodeMap<LocalDefId>,
156 partial_res_overrides: NodeMap<NodeId>,
160
161 allow_contracts: Arc<[Symbol]>,
162 allow_try_trait: Arc<[Symbol]>,
163 allow_gen_future: Arc<[Symbol]>,
164 allow_pattern_type: Arc<[Symbol]>,
165 allow_async_gen: Arc<[Symbol]>,
166 allow_async_iterator: Arc<[Symbol]>,
167 allow_for_await: Arc<[Symbol]>,
168 allow_async_fn_traits: Arc<[Symbol]>,
169
170 delayed_lints: Vec<DelayedLint>,
171
172 move_expr_bindings: Vec<Option<expr::MoveExprState<'hir>>>,
176
177 attribute_parser: AttributeParser<'hir>,
178}
179
180impl<'a, 'hir> LoweringContext<'a, 'hir> {
181 fn new(tcx: TyCtxt<'hir>, resolver: &'a ResolverAstLowering<'hir>, owner: NodeId) -> Self {
182 let current_ast_owner = &resolver.owners[&owner];
183 let current_hir_id_owner = hir::OwnerId { def_id: current_ast_owner.def_id };
184 let current_disambiguator = resolver
185 .disambiguators
186 .get(¤t_hir_id_owner.def_id)
187 .map(|s| s.steal())
188 .unwrap_or_else(|| PerParentDisambiguatorState::new(current_hir_id_owner.def_id));
189
190 Self {
191 tcx,
192 resolver,
193 current_disambiguator,
194 owner: current_ast_owner,
195 arena: tcx.hir_arena,
196
197 bodies: Vec::new(),
199 define_opaque: None,
200 attrs: SortedMap::default(),
201 children: LocalDefIdMap::default(),
202 contract_ensures: None,
203 current_hir_id_owner,
204 item_local_id_counter: hir::ItemLocalId::new(1),
207 ident_and_label_to_local_id: Default::default(),
208 #[cfg(debug_assertions)]
209 node_id_to_local_id: Default::default(),
210 trait_map: Default::default(),
211 next_node_id: resolver.next_node_id,
212 node_id_to_def_id: NodeMap::default(),
213 partial_res_overrides: NodeMap::default(),
214
215 try_block_scope: TryBlockScope::Function,
217 loop_scope: None,
218 is_in_loop_condition: false,
219 is_in_dyn_type: false,
220 coroutine_kind: None,
221 task_context: None,
222 current_item: None,
223 impl_trait_defs: Vec::new(),
224 impl_trait_bounds: Vec::new(),
225 allow_contracts: [sym::contracts_internals].into(),
226 allow_try_trait: [
227 sym::try_trait_v2,
228 sym::try_trait_v2_residual,
229 sym::yeet_desugar_details,
230 ]
231 .into(),
232 allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
233 allow_gen_future: if tcx.features().async_fn_track_caller() {
234 [sym::gen_future, sym::closure_track_caller].into()
235 } else {
236 [sym::gen_future].into()
237 },
238 allow_for_await: [sym::async_gen_internals, sym::async_iterator].into(),
239 allow_async_fn_traits: [sym::async_fn_traits].into(),
240 allow_async_gen: [sym::async_gen_internals].into(),
241 allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
244
245 move_expr_bindings: Vec::new(),
246 attribute_parser: AttributeParser::new(
247 tcx.sess,
248 tcx.features(),
249 tcx.registered_tools(()),
250 ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
251 ),
252 delayed_lints: Vec::new(),
253 }
254 }
255
256 pub(crate) fn dcx(&self) -> DiagCtxtHandle<'hir> {
257 self.tcx.dcx()
258 }
259}
260
261struct SpanLowerer {
262 is_incremental: bool,
263 def_id: LocalDefId,
264}
265
266impl SpanLowerer {
267 fn lower(&self, span: Span) -> Span {
268 if self.is_incremental {
269 span.with_parent(Some(self.def_id))
270 } else {
271 span
273 }
274 }
275}
276
277impl<'tcx> ResolverAstLoweringExt<'tcx> for ResolverAstLowering<'tcx> {
fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'tcx>)
-> Option<Vec<usize>> {
let ExprKind::Path(None, path) = &expr.kind else { return None; };
if path.segments.last().unwrap().args.is_some() { return None; }
let def_id =
self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
if def_id.is_local() { return None; }
{
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcLegacyConstGenerics {
fn_indexes, .. }) => {
break 'done Some(fn_indexes);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.map(|fn_indexes|
fn_indexes.iter().map(|(num, _)| *num).collect())
}
#[doc = " Obtain the list of lifetimes parameters to add to an item."]
#[doc = ""]
#[doc =
" Extra lifetime parameters should only be added in places that can appear"]
#[doc = " as a `binder` in `LifetimeRes`."]
#[doc = ""]
#[doc =
" The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring"]
#[doc = " should appear at the enclosing `PolyTraitRef`."]
fn extra_lifetime_params(&self, id: NodeId)
-> &[(Ident, NodeId, MissingLifetimeKind)] {
self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
}
}#[extension(trait ResolverAstLoweringExt<'tcx>)]
278impl<'tcx> ResolverAstLowering<'tcx> {
279 fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'tcx>) -> Option<Vec<usize>> {
280 let ExprKind::Path(None, path) = &expr.kind else {
281 return None;
282 };
283
284 if path.segments.last().unwrap().args.is_some() {
287 return None;
288 }
289
290 let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
294
295 if def_id.is_local() {
299 return None;
300 }
301
302 find_attr!(
304 tcx, def_id,
305 RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes
306 )
307 .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
308 }
309
310 fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
318 self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
319 }
320}
321
322#[derive(#[automatically_derived]
impl<'a> ::core::fmt::Debug for RelaxedBoundPolicy<'a> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RelaxedBoundPolicy::Allowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Allowed", &__self_0),
RelaxedBoundPolicy::Forbidden(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Forbidden", &__self_0),
}
}
}Debug)]
327enum RelaxedBoundPolicy<'a> {
328 Allowed(&'a mut FxIndexMap<DefId, Span>),
330 Forbidden(RelaxedBoundForbiddenReason),
331}
332impl RelaxedBoundPolicy<'_> {
333 fn reborrow(&mut self) -> RelaxedBoundPolicy<'_> {
334 match self {
335 RelaxedBoundPolicy::Allowed(m) => RelaxedBoundPolicy::Allowed(m),
336 RelaxedBoundPolicy::Forbidden(reason) => RelaxedBoundPolicy::Forbidden(*reason),
337 }
338 }
339}
340
341#[derive(#[automatically_derived]
impl ::core::clone::Clone for RelaxedBoundForbiddenReason {
#[inline]
fn clone(&self) -> RelaxedBoundForbiddenReason { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RelaxedBoundForbiddenReason { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for RelaxedBoundForbiddenReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RelaxedBoundForbiddenReason::TraitObjectTy => "TraitObjectTy",
RelaxedBoundForbiddenReason::SuperTrait => "SuperTrait",
RelaxedBoundForbiddenReason::TraitAlias => "TraitAlias",
RelaxedBoundForbiddenReason::AssocTyBounds => "AssocTyBounds",
RelaxedBoundForbiddenReason::WhereBound => "WhereBound",
})
}
}Debug)]
342enum RelaxedBoundForbiddenReason {
343 TraitObjectTy,
344 SuperTrait,
345 TraitAlias,
346 AssocTyBounds,
347 WhereBound,
350}
351
352#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ImplTraitContext::Universal =>
::core::fmt::Formatter::write_str(f, "Universal"),
ImplTraitContext::OpaqueTy { origin: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"OpaqueTy", "origin", &__self_0),
ImplTraitContext::InBinding =>
::core::fmt::Formatter::write_str(f, "InBinding"),
ImplTraitContext::FeatureGated(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FeatureGated", __self_0, &__self_1),
ImplTraitContext::Disallowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Disallowed", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitContext { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ImplTraitContext {
#[inline]
fn clone(&self) -> ImplTraitContext {
let _:
::core::clone::AssertParamIsClone<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::clone::AssertParamIsClone<ImplTraitPosition>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitContext {
#[inline]
fn eq(&self, other: &ImplTraitContext) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ImplTraitContext::OpaqueTy { origin: __self_0 },
ImplTraitContext::OpaqueTy { origin: __arg1_0 }) =>
__self_0 == __arg1_0,
(ImplTraitContext::FeatureGated(__self_0, __self_1),
ImplTraitContext::FeatureGated(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ImplTraitContext::Disallowed(__self_0),
ImplTraitContext::Disallowed(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::cmp::AssertParamIsEq<ImplTraitPosition>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq)]
355enum ImplTraitContext {
356 Universal,
362
363 OpaqueTy { origin: hir::OpaqueTyOrigin<LocalDefId> },
368
369 InBinding,
374
375 FeatureGated(ImplTraitPosition, Symbol),
377 Disallowed(ImplTraitPosition),
379}
380
381#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitPosition {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ImplTraitPosition::Path => "Path",
ImplTraitPosition::Variable => "Variable",
ImplTraitPosition::Trait => "Trait",
ImplTraitPosition::Bound => "Bound",
ImplTraitPosition::Generic => "Generic",
ImplTraitPosition::ExternFnParam => "ExternFnParam",
ImplTraitPosition::ClosureParam => "ClosureParam",
ImplTraitPosition::PointerParam => "PointerParam",
ImplTraitPosition::FnTraitParam => "FnTraitParam",
ImplTraitPosition::ExternFnReturn => "ExternFnReturn",
ImplTraitPosition::ClosureReturn => "ClosureReturn",
ImplTraitPosition::PointerReturn => "PointerReturn",
ImplTraitPosition::FnTraitReturn => "FnTraitReturn",
ImplTraitPosition::GenericDefault => "GenericDefault",
ImplTraitPosition::ConstTy => "ConstTy",
ImplTraitPosition::StaticTy => "StaticTy",
ImplTraitPosition::AssocTy => "AssocTy",
ImplTraitPosition::FieldTy => "FieldTy",
ImplTraitPosition::Cast => "Cast",
ImplTraitPosition::ImplSelf => "ImplSelf",
ImplTraitPosition::OffsetOf => "OffsetOf",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitPosition { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ImplTraitPosition {
#[inline]
fn clone(&self) -> ImplTraitPosition { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitPosition {
#[inline]
fn eq(&self, other: &ImplTraitPosition) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitPosition {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq)]
383enum ImplTraitPosition {
384 Path,
385 Variable,
386 Trait,
387 Bound,
388 Generic,
389 ExternFnParam,
390 ClosureParam,
391 PointerParam,
392 FnTraitParam,
393 ExternFnReturn,
394 ClosureReturn,
395 PointerReturn,
396 FnTraitReturn,
397 GenericDefault,
398 ConstTy,
399 StaticTy,
400 AssocTy,
401 FieldTy,
402 Cast,
403 ImplSelf,
404 OffsetOf,
405}
406
407impl std::fmt::Display for ImplTraitPosition {
408 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
409 let name = match self {
410 ImplTraitPosition::Path => "paths",
411 ImplTraitPosition::Variable => "the type of variable bindings",
412 ImplTraitPosition::Trait => "traits",
413 ImplTraitPosition::Bound => "bounds",
414 ImplTraitPosition::Generic => "generics",
415 ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
416 ImplTraitPosition::ClosureParam => "closure parameters",
417 ImplTraitPosition::PointerParam => "`fn` pointer parameters",
418 ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
419 ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
420 ImplTraitPosition::ClosureReturn => "closure return types",
421 ImplTraitPosition::PointerReturn => "`fn` pointer return types",
422 ImplTraitPosition::FnTraitReturn => "the return type of `Fn` trait bounds",
423 ImplTraitPosition::GenericDefault => "generic parameter defaults",
424 ImplTraitPosition::ConstTy => "const types",
425 ImplTraitPosition::StaticTy => "static types",
426 ImplTraitPosition::AssocTy => "associated types",
427 ImplTraitPosition::FieldTy => "field types",
428 ImplTraitPosition::Cast => "cast expression types",
429 ImplTraitPosition::ImplSelf => "impl headers",
430 ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
431 };
432
433 f.write_fmt(format_args!("{0}", name))write!(f, "{name}")
434 }
435}
436
437#[derive(#[automatically_derived]
impl ::core::marker::Copy for FnDeclKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FnDeclKind {
#[inline]
fn clone(&self) -> FnDeclKind { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FnDeclKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
FnDeclKind::Fn => "Fn",
FnDeclKind::Inherent => "Inherent",
FnDeclKind::ExternFn => "ExternFn",
FnDeclKind::Closure => "Closure",
FnDeclKind::Pointer => "Pointer",
FnDeclKind::Trait => "Trait",
FnDeclKind::Impl => "Impl",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for FnDeclKind {
#[inline]
fn eq(&self, other: &FnDeclKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for FnDeclKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq)]
438enum FnDeclKind {
439 Fn,
440 Inherent,
441 ExternFn,
442 Closure,
443 Pointer,
444 Trait,
445 Impl,
446}
447
448#[derive(#[automatically_derived]
impl ::core::marker::Copy for TryBlockScope { }Copy, #[automatically_derived]
impl ::core::clone::Clone for TryBlockScope {
#[inline]
fn clone(&self) -> TryBlockScope {
let _: ::core::clone::AssertParamIsClone<HirId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for TryBlockScope {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
TryBlockScope::Function =>
::core::fmt::Formatter::write_str(f, "Function"),
TryBlockScope::Homogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Homogeneous", &__self_0),
TryBlockScope::Heterogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Heterogeneous", &__self_0),
}
}
}Debug)]
449enum TryBlockScope {
450 Function,
452 Homogeneous(HirId),
455 Heterogeneous(HirId),
458}
459
460fn index_ast<'tcx>(
461 tcx: TyCtxt<'tcx>,
462 (): (),
463) -> IndexVec<LocalDefId, Steal<(Arc<ResolverAstLowering<'tcx>>, AstOwner)>> {
464 tcx.ensure_done().output_filenames(());
466 tcx.ensure_done().early_lint_checks(());
467 tcx.ensure_done().get_lang_items(());
468 tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
469
470 let (resolver, krate) = tcx.resolver_for_lowering();
471 let mut resolver = resolver.steal();
472 let mut krate = krate.steal();
473
474 let mut indexer = Indexer {
475 owners: &resolver.owners,
476 index: IndexVec::new(),
477 next_node_id: resolver.next_node_id,
478 };
479 indexer.visit_crate(&mut krate);
480 indexer.insert(CRATE_NODE_ID, AstOwner::Crate(Box::new(krate)));
481 resolver.next_node_id = indexer.next_node_id;
482
483 let index = indexer.index;
484 let resolver = Arc::new(resolver);
485 let index = index.into_iter().map(|owner| Steal::new((Arc::clone(&resolver), owner))).collect();
486 return index;
487
488 struct Indexer<'s, 'hir> {
489 owners: &'s NodeMap<PerOwnerResolverData<'hir>>,
490 index: IndexVec<LocalDefId, AstOwner>,
491 next_node_id: NodeId,
492 }
493
494 impl Indexer<'_, '_> {
495 fn insert(&mut self, id: NodeId, node: AstOwner) {
496 let def_id = self.owners[&id].def_id;
497 self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
498 self.index[def_id] = node;
499 }
500
501 fn make_dummy<K>(
502 &mut self,
503 id: NodeId,
504 span: Span,
505 dummy: impl FnOnce(Box<MacCall>) -> K,
506 ) -> Box<Item<K>> {
507 use rustc_ast::token::Delimiter;
508 use rustc_ast::tokenstream::{DelimSpan, TokenStream};
509 use thin_vec::thin_vec;
510
511 Box::new(Item {
512 attrs: AttrVec::default(),
513 id,
514 span,
515 vis: Visibility { kind: VisibilityKind::Public, span, tokens: None },
516 kind: dummy(Box::new(MacCall {
519 path: Path { span, segments: ::thin_vec::ThinVec::new()thin_vec![], tokens: None },
520 args: Box::new(DelimArgs {
521 dspan: DelimSpan::from_single(span),
522 delim: Delimiter::Parenthesis,
523 tokens: TokenStream::new(Vec::new()),
524 }),
525 })),
526 tokens: None,
527 })
528 }
529
530 fn replace_with_dummy<K>(
531 &mut self,
532 item: &mut ast::Item<K>,
533 dummy: impl FnOnce(Box<MacCall>) -> K,
534 node: impl FnOnce(Box<Item<K>>) -> AstOwner,
535 ) {
536 let dummy = self.make_dummy(item.id, item.span, dummy);
537 let item = mem::replace(item, *dummy);
538 self.insert(item.id, node(Box::new(item)));
539 }
540
541 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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_item_id_use_tree",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(541u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["tree", "parent",
"items"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&tree)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&items)
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;
}
{
match tree.kind {
UseTreeKind::Glob(_) | UseTreeKind::Simple(_) => {}
UseTreeKind::Nested { items: ref nested_vec, span } => {
for &(ref nested, id) in nested_vec {
self.insert(id, AstOwner::NestedUseTree(parent));
items.push(self.make_dummy(id, span, ItemKind::MacCall));
let def_id = self.owners[&id].def_id;
self.visit_item_id_use_tree(nested, def_id, items);
}
}
}
}
}
}#[tracing::instrument(level = "trace", skip(self))]
542 fn visit_item_id_use_tree(
543 &mut self,
544 tree: &UseTree,
545 parent: LocalDefId,
546 items: &mut SmallVec<[Box<Item>; 1]>,
547 ) {
548 match tree.kind {
549 UseTreeKind::Glob(_) | UseTreeKind::Simple(_) => {}
550 UseTreeKind::Nested { items: ref nested_vec, span } => {
551 for &(ref nested, id) in nested_vec {
552 self.insert(id, AstOwner::NestedUseTree(parent));
553 items.push(self.make_dummy(id, span, ItemKind::MacCall));
554
555 let def_id = self.owners[&id].def_id;
556 self.visit_item_id_use_tree(nested, def_id, items);
557 }
558 }
559 }
560 }
561 }
562
563 impl MutVisitor for Indexer<'_, '_> {
564 fn visit_attribute(&mut self, _: &mut Attribute) {
565 }
568
569 fn flat_map_item(&mut self, mut item: Box<Item>) -> SmallVec<[Box<Item>; 1]> {
570 let def_id = self.owners[&item.id].def_id;
571 mut_visit::walk_item(self, &mut *item);
572 let dummy = self.make_dummy(item.id, item.span, ItemKind::MacCall);
573 let mut items = {
let count = 0usize + 1usize;
let mut vec = ::smallvec::SmallVec::new();
if count <= vec.inline_size() {
vec.push(dummy);
vec
} else {
::smallvec::SmallVec::from_vec(::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[dummy])))
}
}smallvec![dummy];
574 if let ItemKind::Use(ref use_tree) = item.kind {
575 self.visit_item_id_use_tree(use_tree, def_id, &mut items);
576 }
577 self.insert(item.id, AstOwner::Item(item));
578 items
579 }
580
581 fn flat_map_stmt(&mut self, stmt: Stmt) -> SmallVec<[Stmt; 1]> {
582 let Stmt { id, span, kind } = stmt;
583 let mut id = Some(id);
584 mut_visit::walk_flat_map_stmt_kind(self, kind)
585 .into_iter()
586 .map(|kind| {
587 let id = id.take().unwrap_or_else(|| {
592 let next = self.next_node_id;
593 self.next_node_id.increment_by(1);
594 next
595 });
596 Stmt { id, kind, span }
597 })
598 .collect()
599 }
600
601 fn visit_assoc_item(&mut self, item: &mut AssocItem, ctxt: visit::AssocCtxt) {
602 mut_visit::walk_assoc_item(self, item, ctxt);
603 match ctxt {
604 visit::AssocCtxt::Trait => {
605 self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::TraitItem)
606 }
607 visit::AssocCtxt::Impl { .. } => {
608 self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::ImplItem)
609 }
610 }
611 }
612
613 fn visit_foreign_item(&mut self, item: &mut ForeignItem) {
614 mut_visit::walk_item(self, item);
615 self.replace_with_dummy(item, ForeignItemKind::MacCall, AstOwner::ForeignItem);
616 }
617 }
618}
619
620#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("lower_to_hir",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(620u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["def_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::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&def_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: hir::MaybeOwner<'_> = loop {};
return __tracing_attr_fake_return;
}
{
tcx.ensure_done().output_filenames(());
tcx.ensure_done().early_lint_checks(());
tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
tcx.ensure_done().get_lang_items(());
let ast_index = tcx.index_ast(());
let resolver_and_node = ast_index.get(def_id).map(Steal::steal);
let fallback_to_ancestor =
|parent_id|
{
let mut parent_info = tcx.lower_to_hir(parent_id);
if let hir::MaybeOwner::NonOwner(hir_id) = parent_info {
parent_info = tcx.lower_to_hir(hir_id.owner);
}
let parent_info = parent_info.unwrap();
*parent_info.children.get(&def_id).unwrap_or_else(||
{
{
::core::panicking::panic_fmt(format_args!("{0:?} does not appear in children of {1:?}",
def_id, parent_info.nodes.node().def_id()));
}
})
};
let Some((resolver, node)) =
resolver_and_node else {
return fallback_to_ancestor(tcx.local_parent(def_id));
};
let mut item_lowerer =
item::ItemLowerer { tcx, resolver: &*resolver };
let item =
match &node {
AstOwner::Crate(c) => item_lowerer.lower_crate(&c),
AstOwner::Item(item) => item_lowerer.lower_item(&item),
AstOwner::TraitItem(item) =>
item_lowerer.lower_trait_item(&item),
AstOwner::ImplItem(item) =>
item_lowerer.lower_impl_item(&item),
AstOwner::ForeignItem(item) =>
item_lowerer.lower_foreign_item(&item),
AstOwner::NestedUseTree(owner_id) =>
fallback_to_ancestor(*owner_id),
AstOwner::NonOwner =>
fallback_to_ancestor(tcx.local_parent(def_id)),
};
tcx.sess.time("drop_ast", || mem::drop(node));
item
}
}
}#[instrument(level = "trace", skip(tcx))]
621fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> {
622 tcx.ensure_done().output_filenames(());
624 tcx.ensure_done().early_lint_checks(());
625 tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
626 tcx.ensure_done().get_lang_items(());
627 let ast_index = tcx.index_ast(());
628 let resolver_and_node = ast_index.get(def_id).map(Steal::steal);
629
630 let fallback_to_ancestor = |parent_id| {
631 let mut parent_info = tcx.lower_to_hir(parent_id);
635 if let hir::MaybeOwner::NonOwner(hir_id) = parent_info {
636 parent_info = tcx.lower_to_hir(hir_id.owner);
642 }
643
644 let parent_info = parent_info.unwrap();
645 *parent_info.children.get(&def_id).unwrap_or_else(|| {
646 panic!(
647 "{:?} does not appear in children of {:?}",
648 def_id,
649 parent_info.nodes.node().def_id()
650 )
651 })
652 };
653
654 let Some((resolver, node)) = resolver_and_node else {
655 return fallback_to_ancestor(tcx.local_parent(def_id));
659 };
660
661 let mut item_lowerer = item::ItemLowerer { tcx, resolver: &*resolver };
662
663 let item = match &node {
664 AstOwner::Crate(c) => item_lowerer.lower_crate(&c),
666 AstOwner::Item(item) => item_lowerer.lower_item(&item),
667 AstOwner::TraitItem(item) => item_lowerer.lower_trait_item(&item),
668 AstOwner::ImplItem(item) => item_lowerer.lower_impl_item(&item),
669 AstOwner::ForeignItem(item) => item_lowerer.lower_foreign_item(&item),
670 AstOwner::NestedUseTree(owner_id) => fallback_to_ancestor(*owner_id),
671 AstOwner::NonOwner => fallback_to_ancestor(tcx.local_parent(def_id)),
674 };
675
676 tcx.sess.time("drop_ast", || mem::drop(node));
677
678 item
679}
680
681#[derive(#[automatically_derived]
impl ::core::marker::Copy for ParamMode { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ParamMode {
#[inline]
fn clone(&self) -> ParamMode { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ParamMode {
#[inline]
fn eq(&self, other: &ParamMode) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for ParamMode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ParamMode::Explicit => "Explicit",
ParamMode::Optional => "Optional",
})
}
}Debug)]
682enum ParamMode {
683 Explicit,
685 Optional,
687}
688
689#[derive(#[automatically_derived]
impl ::core::marker::Copy for AllowReturnTypeNotation { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AllowReturnTypeNotation {
#[inline]
fn clone(&self) -> AllowReturnTypeNotation { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AllowReturnTypeNotation {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AllowReturnTypeNotation::Yes => "Yes",
AllowReturnTypeNotation::No => "No",
})
}
}Debug)]
690enum AllowReturnTypeNotation {
691 Yes,
693 No,
695}
696
697enum GenericArgsMode {
698 ParenSugar,
700 ReturnTypeNotation,
702 Err,
704 Silence,
706}
707
708impl<'hir> LoweringContext<'_, 'hir> {
709 fn create_def(
710 &mut self,
711 node_id: NodeId,
712 name: Option<Symbol>,
713 def_kind: DefKind,
714 span: Span,
715 ) -> LocalDefId {
716 let parent = self.current_hir_id_owner.def_id;
717 {
match (&node_id, &ast::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);
}
}
}
};assert_ne!(node_id, ast::DUMMY_NODE_ID);
718 if !self.opt_local_def_id(node_id).is_none() {
{
::core::panicking::panic_fmt(format_args!("adding a def\'n for node-id {0:?} and def kind {1:?} but a previous def\'n exists: {2:?}",
node_id, def_kind,
self.tcx.hir_def_key(self.local_def_id(node_id))));
}
};assert!(
719 self.opt_local_def_id(node_id).is_none(),
720 "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
721 node_id,
722 def_kind,
723 self.tcx.hir_def_key(self.local_def_id(node_id)),
724 );
725
726 let def_id = self
727 .tcx
728 .at(span)
729 .create_def(parent, name, def_kind, None, &mut self.current_disambiguator)
730 .def_id();
731
732 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:732",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(732u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::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: def_id_to_node_id[{0:?}] <-> {1:?}",
def_id, node_id) as &dyn Value))])
});
} else { ; }
};debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
733 self.node_id_to_def_id.insert(node_id, def_id);
734
735 def_id
736 }
737
738 fn next_node_id(&mut self) -> NodeId {
739 let start = self.next_node_id;
740 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
741 self.next_node_id = NodeId::from_u32(next);
742 start
743 }
744
745 x;#[instrument(level = "trace", skip(self), ret)]
748 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
749 self.node_id_to_def_id
750 .get(&node)
751 .or_else(|| self.owner.node_id_to_def_id.get(&node))
752 .copied()
753 }
754
755 fn local_def_id(&self, node: NodeId) -> LocalDefId {
756 self.opt_local_def_id(node).unwrap_or_else(|| {
757 self.resolver.owners.items().any(|(id, items)| {
758 items.node_id_to_def_id.items().any(|(node_id, def_id)| {
759 if *node_id == node {
760 let actual_owner = items.node_id_to_def_id.get(id);
761 {
::core::panicking::panic_fmt(format_args!("{0:?} ({1}) was found in {2:?} ({3})",
def_id, node_id, actual_owner, id));
}panic!("{def_id:?} ({node_id}) was found in {actual_owner:?} ({id})",)
762 }
763 false
764 })
765 });
766 {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
};panic!("no entry for node id: `{node:?}`");
767 })
768 }
769
770 fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
771 match self.partial_res_overrides.get(&id) {
772 Some(self_param_id) => Some(PartialRes::new(Res::Local(*self_param_id))),
773 None => self.resolver.partial_res_map.get(&id).copied(),
774 }
775 }
776
777 fn owner_id(&self, node: NodeId) -> hir::OwnerId {
779 hir::OwnerId { def_id: self.resolver.owners[&node].def_id }
780 }
781
782 #[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("with_hir_id_owner",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(787u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["owner"],
::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(&owner)
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;
}
{
let owner_id = self.owner_id(owner);
let def_id = owner_id.def_id;
let new_disambig =
self.resolver.disambiguators.get(&def_id).map(|s|
s.steal()).unwrap_or_else(||
PerParentDisambiguatorState::new(def_id));
let disambiguator =
mem::replace(&mut self.current_disambiguator, new_disambig);
let current_ast_owner =
mem::replace(&mut self.owner, &self.resolver.owners[&owner]);
let current_attrs = mem::take(&mut self.attrs);
let current_bodies = mem::take(&mut self.bodies);
let current_define_opaque = mem::take(&mut self.define_opaque);
let current_ident_and_label_to_local_id =
mem::take(&mut self.ident_and_label_to_local_id);
let current_node_id_to_local_id =
mem::take(&mut self.node_id_to_local_id);
let current_trait_map = mem::take(&mut self.trait_map);
let current_owner =
mem::replace(&mut self.current_hir_id_owner, owner_id);
let current_local_counter =
mem::replace(&mut self.item_local_id_counter,
hir::ItemLocalId::new(1));
let current_impl_trait_defs =
mem::take(&mut self.impl_trait_defs);
let current_impl_trait_bounds =
mem::take(&mut self.impl_trait_bounds);
let current_delayed_lints = mem::take(&mut self.delayed_lints);
let current_children = mem::take(&mut self.children);
{
let _old =
self.node_id_to_local_id.insert(owner,
hir::ItemLocalId::ZERO);
if true {
{
match (&_old, &None) {
(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);
}
}
}
};
};
}
let item = f(self);
{
match (&owner_id, &item.def_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);
}
}
}
};
if !self.impl_trait_defs.is_empty() {
::core::panicking::panic("assertion failed: self.impl_trait_defs.is_empty()")
};
if !self.impl_trait_bounds.is_empty() {
::core::panicking::panic("assertion failed: self.impl_trait_bounds.is_empty()")
};
let info = self.make_owner_info(item);
self.current_disambiguator = disambiguator;
self.owner = current_ast_owner;
self.attrs = current_attrs;
self.bodies = current_bodies;
self.define_opaque = current_define_opaque;
self.ident_and_label_to_local_id =
current_ident_and_label_to_local_id;
{ self.node_id_to_local_id = current_node_id_to_local_id; }
self.trait_map = current_trait_map;
self.current_hir_id_owner = current_owner;
self.item_local_id_counter = current_local_counter;
self.impl_trait_defs = current_impl_trait_defs;
self.impl_trait_bounds = current_impl_trait_bounds;
self.delayed_lints = current_delayed_lints;
self.children = current_children;
self.children.extend_unord(info.children.items().map(|(&def_id,
&info)| (def_id, info)));
if true {
if !!self.children.contains_key(&owner_id.def_id) {
::core::panicking::panic("assertion failed: !self.children.contains_key(&owner_id.def_id)")
};
};
self.children.insert(owner_id.def_id,
hir::MaybeOwner::Owner(info));
}
}
}#[instrument(level = "debug", skip(self, f))]
788 fn with_hir_id_owner(
789 &mut self,
790 owner: NodeId,
791 f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>,
792 ) {
793 let owner_id = self.owner_id(owner);
794 let def_id = owner_id.def_id;
795
796 let new_disambig = self
797 .resolver
798 .disambiguators
799 .get(&def_id)
800 .map(|s| s.steal())
801 .unwrap_or_else(|| PerParentDisambiguatorState::new(def_id));
802
803 let disambiguator = mem::replace(&mut self.current_disambiguator, new_disambig);
804 let current_ast_owner = mem::replace(&mut self.owner, &self.resolver.owners[&owner]);
805 let current_attrs = mem::take(&mut self.attrs);
806 let current_bodies = mem::take(&mut self.bodies);
807 let current_define_opaque = mem::take(&mut self.define_opaque);
808 let current_ident_and_label_to_local_id = mem::take(&mut self.ident_and_label_to_local_id);
809
810 #[cfg(debug_assertions)]
811 let current_node_id_to_local_id = mem::take(&mut self.node_id_to_local_id);
812 let current_trait_map = mem::take(&mut self.trait_map);
813 let current_owner = mem::replace(&mut self.current_hir_id_owner, owner_id);
814 let current_local_counter =
815 mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
816 let current_impl_trait_defs = mem::take(&mut self.impl_trait_defs);
817 let current_impl_trait_bounds = mem::take(&mut self.impl_trait_bounds);
818 let current_delayed_lints = mem::take(&mut self.delayed_lints);
819 let current_children = mem::take(&mut self.children);
820
821 #[cfg(debug_assertions)]
827 {
828 let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
829 debug_assert_eq!(_old, None);
830 }
831
832 let item = f(self);
833 assert_eq!(owner_id, item.def_id());
834 assert!(self.impl_trait_defs.is_empty());
836 assert!(self.impl_trait_bounds.is_empty());
837 let info = self.make_owner_info(item);
838
839 self.current_disambiguator = disambiguator;
840 self.owner = current_ast_owner;
841 self.attrs = current_attrs;
842 self.bodies = current_bodies;
843 self.define_opaque = current_define_opaque;
844 self.ident_and_label_to_local_id = current_ident_and_label_to_local_id;
845
846 #[cfg(debug_assertions)]
847 {
848 self.node_id_to_local_id = current_node_id_to_local_id;
849 }
850 self.trait_map = current_trait_map;
851 self.current_hir_id_owner = current_owner;
852 self.item_local_id_counter = current_local_counter;
853 self.impl_trait_defs = current_impl_trait_defs;
854 self.impl_trait_bounds = current_impl_trait_bounds;
855 self.delayed_lints = current_delayed_lints;
856 self.children = current_children;
857 self.children.extend_unord(info.children.items().map(|(&def_id, &info)| (def_id, info)));
858
859 debug_assert!(!self.children.contains_key(&owner_id.def_id));
860 self.children.insert(owner_id.def_id, hir::MaybeOwner::Owner(info));
861 }
862
863 fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
864 let attrs = mem::take(&mut self.attrs);
865 let mut bodies = mem::take(&mut self.bodies);
866 let define_opaque = mem::take(&mut self.define_opaque);
867 let trait_map = mem::take(&mut self.trait_map);
868 let delayed_lints = Steal::new(mem::take(&mut self.delayed_lints).into_boxed_slice());
869 let children = mem::take(&mut self.children);
870
871 #[cfg(debug_assertions)]
872 for (id, attrs) in attrs.iter() {
873 if attrs.is_empty() {
875 {
::core::panicking::panic_fmt(format_args!("Stored empty attributes for {0:?}",
id));
};panic!("Stored empty attributes for {:?}", id);
876 }
877 }
878
879 bodies.sort_by_key(|(k, _)| *k);
880 let bodies = SortedMap::from_presorted_elements(bodies);
881
882 let rustc_middle::hir::Hashes { bodies_hash, attrs_hash } =
884 self.tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque);
885 let num_nodes = self.item_local_id_counter.as_usize();
886 let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
887 let nodes = hir::OwnerNodes { opt_hash: bodies_hash, nodes, bodies };
888 let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
889
890 let opt_hash = self.tcx.needs_hir_hash().then(|| {
891 self.tcx.with_stable_hashing_context(|mut hcx| {
892 let mut stable_hasher = StableHasher::new();
893 bodies_hash.unwrap().stable_hash(&mut hcx, &mut stable_hasher);
894 attrs_hash.unwrap().stable_hash(&mut hcx, &mut stable_hasher);
895 parenting.stable_hash(&mut hcx, &mut stable_hasher);
897 trait_map.stable_hash(&mut hcx, &mut stable_hasher);
898 children.stable_hash(&mut hcx, &mut stable_hasher);
899 stable_hasher.finish()
900 })
901 });
902
903 self.arena.alloc(hir::OwnerInfo {
904 opt_hash,
905 nodes,
906 parenting,
907 attrs,
908 trait_map,
909 delayed_lints,
910 children,
911 })
912 }
913
914 x;#[instrument(level = "debug", skip(self), ret)]
920 fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
921 assert_ne!(ast_node_id, DUMMY_NODE_ID);
922
923 let owner = self.current_hir_id_owner;
924 let local_id = self.item_local_id_counter;
925 assert_ne!(local_id, hir::ItemLocalId::ZERO);
926 self.item_local_id_counter.increment_by(1);
927 let hir_id = HirId { owner, local_id };
928
929 if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
930 self.children.insert(def_id, hir::MaybeOwner::NonOwner(hir_id));
931 }
932
933 if let Some(traits) = self.owner.trait_map.get(&ast_node_id) {
934 self.trait_map.insert(hir_id.local_id, *traits);
935 }
936
937 #[cfg(debug_assertions)]
939 {
940 let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
941 assert_eq!(old, None);
942 }
943
944 hir_id
945 }
946
947 x;#[instrument(level = "debug", skip(self), ret)]
949 fn next_id(&mut self) -> HirId {
950 let owner = self.current_hir_id_owner;
951 let local_id = self.item_local_id_counter;
952 assert_ne!(local_id, hir::ItemLocalId::ZERO);
953 self.item_local_id_counter.increment_by(1);
954 HirId { owner, local_id }
955 }
956
957 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("lower_res",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(957u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&res)
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: Res = loop {};
return __tracing_attr_fake_return;
}
{
let res: Result<Res, ()> =
res.apply_id(|id|
{
let owner = self.current_hir_id_owner;
let local_id =
self.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
Ok(HirId { owner, local_id })
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:964",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(964u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&res) as
&dyn Value))])
});
} else { ; }
};
res.unwrap_or(Res::Err)
}
}
}#[instrument(level = "trace", skip(self))]
958 fn lower_res(&mut self, res: Res<NodeId>) -> Res {
959 let res: Result<Res, ()> = res.apply_id(|id| {
960 let owner = self.current_hir_id_owner;
961 let local_id = self.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
962 Ok(HirId { owner, local_id })
963 });
964 trace!(?res);
965
966 res.unwrap_or(Res::Err)
972 }
973
974 fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
975 self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
976 }
977
978 fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
979 if true {
{
match (&id, &self.owner.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!(id, self.owner.id);
980 let per_ns = self.owner.import_res.map(|res| res.map(|res| self.lower_res(res)));
981 if per_ns.is_empty() {
982 self.dcx().span_delayed_bug(span, "no resolution for an import");
984 let err = Some(Res::Err);
985 return PerNS { type_ns: err, value_ns: err, macro_ns: err };
986 }
987 per_ns
988 }
989
990 fn make_lang_item_qpath(
991 &mut self,
992 lang_item: hir::LangItem,
993 span: Span,
994 args: Option<&'hir hir::GenericArgs<'hir>>,
995 ) -> hir::QPath<'hir> {
996 hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
997 }
998
999 fn make_lang_item_path(
1000 &mut self,
1001 lang_item: hir::LangItem,
1002 span: Span,
1003 args: Option<&'hir hir::GenericArgs<'hir>>,
1004 ) -> &'hir hir::Path<'hir> {
1005 let def_id = self.tcx.require_lang_item(lang_item, span);
1006 let def_kind = self.tcx.def_kind(def_id);
1007 let res = Res::Def(def_kind, def_id);
1008 self.arena.alloc(hir::Path {
1009 span,
1010 res,
1011 segments: self.arena.alloc_from_iter([hir::PathSegment {
1012 ident: Ident::new(lang_item.name(), span),
1013 hir_id: self.next_id(),
1014 res,
1015 args,
1016 infer_args: args.is_none(),
1017 delegation_child_segment: false,
1018 }]),
1019 })
1020 }
1021
1022 fn mark_span_with_reason(
1025 &self,
1026 reason: DesugaringKind,
1027 span: Span,
1028 allow_internal_unstable: Option<Arc<[Symbol]>>,
1029 ) -> Span {
1030 self.tcx.with_stable_hashing_context(|hcx| {
1031 span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
1032 })
1033 }
1034
1035 fn span_lowerer(&self) -> SpanLowerer {
1036 SpanLowerer {
1037 is_incremental: self.tcx.sess.opts.incremental.is_some(),
1038 def_id: self.current_hir_id_owner.def_id,
1039 }
1040 }
1041
1042 fn lower_span(&self, span: Span) -> Span {
1045 self.span_lowerer().lower(span)
1046 }
1047
1048 fn lower_ident(&self, ident: Ident) -> Ident {
1049 Ident::new(ident.name, self.lower_span(ident.span))
1050 }
1051
1052 #[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("lifetime_res_to_generic_param",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1053u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["ident", "node_id",
"kind", "source"],
::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(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
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: hir::GenericParam<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let _def_id =
self.create_def(node_id, Some(kw::UnderscoreLifetime),
DefKind::LifetimeParam, ident.span);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1068",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1068u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["_def_id"],
::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(&_def_id) as
&dyn Value))])
});
} else { ; }
};
let hir_id = self.lower_node_id(node_id);
let def_id = self.local_def_id(node_id);
hir::GenericParam {
hir_id,
def_id,
name: hir::ParamName::Fresh,
span: self.lower_span(ident.span),
pure_wrt_drop: false,
kind: hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided(kind),
},
colon_span: None,
source,
}
}
}
}#[instrument(level = "debug", skip(self))]
1054 fn lifetime_res_to_generic_param(
1055 &mut self,
1056 ident: Ident,
1057 node_id: NodeId,
1058 kind: MissingLifetimeKind,
1059 source: hir::GenericParamSource,
1060 ) -> hir::GenericParam<'hir> {
1061 let _def_id = self.create_def(
1063 node_id,
1064 Some(kw::UnderscoreLifetime),
1065 DefKind::LifetimeParam,
1066 ident.span,
1067 );
1068 debug!(?_def_id);
1069
1070 let hir_id = self.lower_node_id(node_id);
1071 let def_id = self.local_def_id(node_id);
1072 hir::GenericParam {
1073 hir_id,
1074 def_id,
1075 name: hir::ParamName::Fresh,
1076 span: self.lower_span(ident.span),
1077 pure_wrt_drop: false,
1078 kind: hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided(kind) },
1079 colon_span: None,
1080 source,
1081 }
1082 }
1083
1084 x;#[instrument(level = "debug", skip(self), ret)]
1090 #[inline]
1091 fn lower_lifetime_binder(
1092 &mut self,
1093 binder: NodeId,
1094 generic_params: &[GenericParam],
1095 ) -> &'hir [hir::GenericParam<'hir>] {
1096 let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
1099 debug!(?extra_lifetimes);
1100 let extra_lifetimes: Vec<_> = extra_lifetimes
1101 .iter()
1102 .map(|&(ident, node_id, res)| {
1103 self.lifetime_res_to_generic_param(
1104 ident,
1105 node_id,
1106 res,
1107 hir::GenericParamSource::Binder,
1108 )
1109 })
1110 .collect();
1111 let arena = self.arena;
1112 let explicit_generic_params =
1113 self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
1114 arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
1115 }
1116
1117 fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
1118 let was_in_dyn_type = self.is_in_dyn_type;
1119 self.is_in_dyn_type = in_scope;
1120
1121 let result = f(self);
1122
1123 self.is_in_dyn_type = was_in_dyn_type;
1124
1125 result
1126 }
1127
1128 fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
1129 let current_item = self.current_item;
1130 self.current_item = Some(scope_span);
1131
1132 let was_in_loop_condition = self.is_in_loop_condition;
1133 self.is_in_loop_condition = false;
1134
1135 let old_contract = self.contract_ensures.take();
1136
1137 let try_block_scope = mem::replace(&mut self.try_block_scope, TryBlockScope::Function);
1138 let loop_scope = self.loop_scope.take();
1139 let ret = f(self);
1140 self.try_block_scope = try_block_scope;
1141 self.loop_scope = loop_scope;
1142
1143 self.contract_ensures = old_contract;
1144
1145 self.is_in_loop_condition = was_in_loop_condition;
1146
1147 self.current_item = current_item;
1148
1149 ret
1150 }
1151
1152 fn lower_attrs(
1153 &mut self,
1154 id: HirId,
1155 attrs: &[Attribute],
1156 target_span: Span,
1157 target: Target,
1158 ) -> &'hir [hir::Attribute] {
1159 self.lower_attrs_with_extra(id, attrs, target_span, target, &[])
1160 }
1161
1162 fn lower_attrs_with_extra(
1163 &mut self,
1164 id: HirId,
1165 attrs: &[Attribute],
1166 target_span: Span,
1167 target: Target,
1168 extra_hir_attributes: &[hir::Attribute],
1169 ) -> &'hir [hir::Attribute] {
1170 if attrs.is_empty() && extra_hir_attributes.is_empty() {
1171 &[]
1172 } else {
1173 let mut lowered_attrs =
1174 self.lower_attrs_vec(attrs, self.lower_span(target_span), id, target);
1175 lowered_attrs.extend(extra_hir_attributes.iter().cloned());
1176
1177 {
match (&id.owner, &self.current_hir_id_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!(id.owner, self.current_hir_id_owner);
1178 let ret = self.arena.alloc_from_iter(lowered_attrs);
1179
1180 if ret.is_empty() {
1187 &[]
1188 } else {
1189 self.attrs.insert(id.local_id, ret);
1190 ret
1191 }
1192 }
1193 }
1194
1195 fn lower_attrs_vec(
1196 &mut self,
1197 attrs: &[Attribute],
1198 target_span: Span,
1199 target_hir_id: HirId,
1200 target: Target,
1201 ) -> Vec<hir::Attribute> {
1202 let l = self.span_lowerer();
1203 self.attribute_parser.parse_attribute_list(
1204 attrs,
1205 target_span,
1206 target,
1207 OmitDoc::Lower,
1208 |s| l.lower(s),
1209 |lint_id, span, kind| {
1210 self.delayed_lints.push(DelayedLint {
1211 lint_id,
1212 id: target_hir_id,
1213 span,
1214 callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
1215 let sess = sess
1216 .downcast_ref::<rustc_session::Session>()
1217 .expect("expected `Session`");
1218 (kind.0)(dcx, level, sess)
1219 }),
1220 });
1221 },
1222 )
1223 }
1224
1225 fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
1226 {
match (&id.owner, &self.current_hir_id_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!(id.owner, self.current_hir_id_owner);
1227 {
match (&target_id.owner, &self.current_hir_id_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!(target_id.owner, self.current_hir_id_owner);
1228 if let Some(&a) = self.attrs.get(&target_id.local_id) {
1229 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
1230 self.attrs.insert(id.local_id, a);
1231 }
1232 }
1233
1234 fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
1235 args.clone()
1236 }
1237
1238 #[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("lower_assoc_item_constraint",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1239u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[],
::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,
&{ meta.fields().value_set(&[]) })
} 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: hir::AssocItemConstraint<'hir> =
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_ast_lowering/src/lib.rs:1245",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1245u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["constraint",
"itctx"],
::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(&constraint)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&itctx) as
&dyn Value))])
});
} else { ; }
};
let gen_args =
if let Some(gen_args) = &constraint.gen_args {
let gen_args_ctor =
match gen_args {
GenericArgs::AngleBracketed(data) => {
self.lower_angle_bracketed_parameter_data(data,
ParamMode::Explicit, itctx).0
}
GenericArgs::Parenthesized(data) => {
if let Some(first_char) =
constraint.ident.as_str().chars().next() &&
first_char.is_ascii_lowercase() {
let err =
match (&data.inputs[..], &data.output) {
([_, ..], FnRetTy::Default(_)) => {
diagnostics::BadReturnTypeNotation::Inputs {
span: data.inputs_span,
}
}
([], FnRetTy::Default(_)) => {
diagnostics::BadReturnTypeNotation::NeedsDots {
span: data.inputs_span,
}
}
(_, FnRetTy::Ty(ty)) => {
let span = data.inputs_span.shrink_to_hi().to(ty.span);
diagnostics::BadReturnTypeNotation::Output {
span,
suggestion: diagnostics::RTNSuggestion {
output: span,
input: data.inputs_span,
},
}
}
};
let mut err = self.dcx().create_err(err);
if !self.tcx.features().return_type_notation() &&
self.tcx.sess.is_nightly_build() {
add_feature_diagnostics(&mut err, &self.tcx.sess,
sym::return_type_notation);
}
err.emit();
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: data.span,
}
} else {
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
self.lower_angle_bracketed_parameter_data(&data.as_angle_bracketed_args(),
ParamMode::Explicit, itctx).0
}
}
GenericArgs::ParenthesizedElided(span) =>
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: *span,
},
};
gen_args_ctor.into_generic_args(self)
} else { hir::GenericArgs::NONE };
let kind =
match &constraint.kind {
AssocItemConstraintKind::Equality { term } => {
let term =
match term {
Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
Term::Const(c) =>
self.lower_anon_const_to_const_arg_and_alloc(c).into(),
};
hir::AssocItemConstraintKind::Equality { term }
}
AssocItemConstraintKind::Bound { bounds } => {
if self.is_in_dyn_type {
let suggestion =
match itctx {
ImplTraitContext::OpaqueTy { .. } |
ImplTraitContext::Universal => {
let bound_end_span =
constraint.gen_args.as_ref().map_or(constraint.ident.span,
|args| args.span());
if bound_end_span.eq_ctxt(constraint.span) {
Some(self.tcx.sess.source_map().next_point(bound_end_span))
} else { None }
}
_ => None,
};
let guar =
self.dcx().emit_err(diagnostics::MisplacedAssocTyBinding {
span: constraint.span,
suggestion,
});
let err_ty =
&*self.arena.alloc(self.ty(constraint.span,
hir::TyKind::Err(guar)));
hir::AssocItemConstraintKind::Equality {
term: err_ty.into(),
}
} else {
let bounds =
self.lower_param_bounds(bounds,
RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
itctx);
hir::AssocItemConstraintKind::Bound { bounds }
}
}
};
hir::AssocItemConstraint {
hir_id: self.lower_node_id(constraint.id),
ident: self.lower_ident(constraint.ident),
gen_args,
kind,
span: self.lower_span(constraint.span),
}
}
}
}#[instrument(level = "debug", skip_all)]
1240 fn lower_assoc_item_constraint(
1241 &mut self,
1242 constraint: &AssocItemConstraint,
1243 itctx: ImplTraitContext,
1244 ) -> hir::AssocItemConstraint<'hir> {
1245 debug!(?constraint, ?itctx);
1246 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1248 let gen_args_ctor = match gen_args {
1249 GenericArgs::AngleBracketed(data) => {
1250 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1251 }
1252 GenericArgs::Parenthesized(data) => {
1253 if let Some(first_char) = constraint.ident.as_str().chars().next()
1254 && first_char.is_ascii_lowercase()
1255 {
1256 let err = match (&data.inputs[..], &data.output) {
1257 ([_, ..], FnRetTy::Default(_)) => {
1258 diagnostics::BadReturnTypeNotation::Inputs {
1259 span: data.inputs_span,
1260 }
1261 }
1262 ([], FnRetTy::Default(_)) => {
1263 diagnostics::BadReturnTypeNotation::NeedsDots {
1264 span: data.inputs_span,
1265 }
1266 }
1267 (_, FnRetTy::Ty(ty)) => {
1269 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1270 diagnostics::BadReturnTypeNotation::Output {
1271 span,
1272 suggestion: diagnostics::RTNSuggestion {
1273 output: span,
1274 input: data.inputs_span,
1275 },
1276 }
1277 }
1278 };
1279 let mut err = self.dcx().create_err(err);
1280 if !self.tcx.features().return_type_notation()
1281 && self.tcx.sess.is_nightly_build()
1282 {
1283 add_feature_diagnostics(
1284 &mut err,
1285 &self.tcx.sess,
1286 sym::return_type_notation,
1287 );
1288 }
1289 err.emit();
1290 GenericArgsCtor {
1291 args: Default::default(),
1292 constraints: &[],
1293 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1294 span: data.span,
1295 }
1296 } else {
1297 self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1298 self.lower_angle_bracketed_parameter_data(
1299 &data.as_angle_bracketed_args(),
1300 ParamMode::Explicit,
1301 itctx,
1302 )
1303 .0
1304 }
1305 }
1306 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1307 args: Default::default(),
1308 constraints: &[],
1309 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1310 span: *span,
1311 },
1312 };
1313 gen_args_ctor.into_generic_args(self)
1314 } else {
1315 hir::GenericArgs::NONE
1316 };
1317 let kind = match &constraint.kind {
1318 AssocItemConstraintKind::Equality { term } => {
1319 let term = match term {
1320 Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
1321 Term::Const(c) => self.lower_anon_const_to_const_arg_and_alloc(c).into(),
1322 };
1323 hir::AssocItemConstraintKind::Equality { term }
1324 }
1325 AssocItemConstraintKind::Bound { bounds } => {
1326 if self.is_in_dyn_type {
1328 let suggestion = match itctx {
1329 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1330 let bound_end_span = constraint
1331 .gen_args
1332 .as_ref()
1333 .map_or(constraint.ident.span, |args| args.span());
1334 if bound_end_span.eq_ctxt(constraint.span) {
1335 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1336 } else {
1337 None
1338 }
1339 }
1340 _ => None,
1341 };
1342
1343 let guar = self.dcx().emit_err(diagnostics::MisplacedAssocTyBinding {
1344 span: constraint.span,
1345 suggestion,
1346 });
1347 let err_ty =
1348 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1349 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1350 } else {
1351 let bounds = self.lower_param_bounds(
1352 bounds,
1353 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1354 itctx,
1355 );
1356 hir::AssocItemConstraintKind::Bound { bounds }
1357 }
1358 }
1359 };
1360
1361 hir::AssocItemConstraint {
1362 hir_id: self.lower_node_id(constraint.id),
1363 ident: self.lower_ident(constraint.ident),
1364 gen_args,
1365 kind,
1366 span: self.lower_span(constraint.span),
1367 }
1368 }
1369
1370 fn emit_bad_parenthesized_trait_in_assoc_ty(&self, data: &ParenthesizedArgs) {
1371 let sub = if data.inputs.is_empty() {
1373 let parentheses_span =
1374 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1375 AssocTyParenthesesSub::Empty { parentheses_span }
1376 }
1377 else {
1379 let open_param = data.inputs_span.shrink_to_lo().to(data
1381 .inputs
1382 .first()
1383 .unwrap()
1384 .span
1385 .shrink_to_lo());
1386 let close_param =
1388 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1389 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1390 };
1391 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub });
1392 }
1393
1394 #[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("lower_generic_arg",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1394u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["arg", "itctx"],
::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(&arg)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
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: hir::GenericArg<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
match arg {
ast::GenericArg::Lifetime(lt) =>
GenericArg::Lifetime(self.lower_lifetime(lt,
LifetimeSource::Path {
angle_brackets: hir::AngleBrackets::Full,
}, lt.ident.into())),
ast::GenericArg::Type(ty) => {
if ty.is_maybe_parenthesised_infer() {
return GenericArg::Infer(hir::InferArg {
hir_id: self.lower_node_id(ty.id),
span: self.lower_span(ty.span),
});
}
match &ty.kind {
TyKind::Path(None, path) => {
if let Some(res) =
self.get_partial_res(ty.id).and_then(|partial_res|
partial_res.full_res()) {
if !res.matches_ns(Namespace::TypeNS) &&
path.is_potential_trivial_const_arg() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1431",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1431u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::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!("lower_generic_arg: Lowering type argument as const argument: {0:?}",
ty) as &dyn Value))])
});
} else { ; }
};
let ct =
self.lower_const_path_to_const_arg(path, res, ty.id,
ty.span);
return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
}
}
}
_ => {}
}
GenericArg::Type(self.lower_ty_alloc(ty,
itctx).try_as_ambig_ty().unwrap())
}
ast::GenericArg::Const(ct) => {
let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
match ct.try_as_ambig_ct() {
Some(ct) => GenericArg::Const(ct),
None =>
GenericArg::Infer(hir::InferArg {
hir_id: ct.hir_id,
span: ct.span,
}),
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1395 fn lower_generic_arg(
1396 &mut self,
1397 arg: &ast::GenericArg,
1398 itctx: ImplTraitContext,
1399 ) -> hir::GenericArg<'hir> {
1400 match arg {
1401 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1402 lt,
1403 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1404 lt.ident.into(),
1405 )),
1406 ast::GenericArg::Type(ty) => {
1407 if ty.is_maybe_parenthesised_infer() {
1410 return GenericArg::Infer(hir::InferArg {
1411 hir_id: self.lower_node_id(ty.id),
1412 span: self.lower_span(ty.span),
1413 });
1414 }
1415
1416 match &ty.kind {
1417 TyKind::Path(None, path) => {
1424 if let Some(res) = self
1425 .get_partial_res(ty.id)
1426 .and_then(|partial_res| partial_res.full_res())
1427 {
1428 if !res.matches_ns(Namespace::TypeNS)
1429 && path.is_potential_trivial_const_arg()
1430 {
1431 debug!(
1432 "lower_generic_arg: Lowering type argument as const argument: {:?}",
1433 ty,
1434 );
1435
1436 let ct =
1437 self.lower_const_path_to_const_arg(path, res, ty.id, ty.span);
1438 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1439 }
1440 }
1441 }
1442 _ => {}
1443 }
1444 GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
1445 }
1446 ast::GenericArg::Const(ct) => {
1447 let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1448 match ct.try_as_ambig_ct() {
1449 Some(ct) => GenericArg::Const(ct),
1450 None => GenericArg::Infer(hir::InferArg { hir_id: ct.hir_id, span: ct.span }),
1451 }
1452 }
1453 }
1454 }
1455
1456 #[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("lower_ty_alloc",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1456u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["t", "itctx"],
::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(&t)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
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: &'hir hir::Ty<'hir> = loop {};
return __tracing_attr_fake_return;
}
{ self.arena.alloc(self.lower_ty(t, itctx)) }
}
}#[instrument(level = "debug", skip(self))]
1457 fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1458 self.arena.alloc(self.lower_ty(t, itctx))
1459 }
1460
1461 fn lower_path_ty(
1462 &mut self,
1463 t: &Ty,
1464 qself: &Option<Box<QSelf>>,
1465 path: &Path,
1466 param_mode: ParamMode,
1467 itctx: ImplTraitContext,
1468 ) -> hir::Ty<'hir> {
1469 if qself.is_none()
1475 && let Some(partial_res) = self.get_partial_res(t.id)
1476 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1477 {
1478 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1479 let bound = this.lower_poly_trait_ref(
1480 &PolyTraitRef {
1481 bound_generic_params: ThinVec::new(),
1482 modifiers: TraitBoundModifiers::NONE,
1483 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1484 span: t.span,
1485 parens: ast::Parens::No,
1486 },
1487 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1488 itctx,
1489 );
1490 let bounds = this.arena.alloc_from_iter([bound]);
1491 let lifetime_bound = this.elided_dyn_bound(t.span);
1492 (bounds, lifetime_bound)
1493 });
1494 let kind = hir::TyKind::TraitObject(
1495 bounds,
1496 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1497 );
1498 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1499 }
1500
1501 let id = self.lower_node_id(t.id);
1502 let qpath = self.lower_qpath(
1503 t.id,
1504 qself,
1505 path,
1506 param_mode,
1507 AllowReturnTypeNotation::Yes,
1508 itctx,
1509 None,
1510 );
1511 self.ty_path(id, t.span, qpath)
1512 }
1513
1514 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1515 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1516 }
1517
1518 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1519 self.ty(span, hir::TyKind::Tup(tys))
1520 }
1521
1522 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1523 let kind = match &t.kind {
1524 TyKind::Infer => hir::TyKind::Infer(()),
1525 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1526 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
1527 TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
1528 TyKind::Ref(region, mt) => {
1529 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1530 hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
1531 }
1532 TyKind::PinnedRef(region, mt) => {
1533 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1534 let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1535 let span = self.lower_span(t.span);
1536 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1537 let args = self.arena.alloc(hir::GenericArgs {
1538 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1539 constraints: &[],
1540 parenthesized: hir::GenericArgsParentheses::No,
1541 span_ext: span,
1542 });
1543 let path = self.make_lang_item_qpath(hir::LangItem::Pin, span, Some(args));
1544 hir::TyKind::Path(path)
1545 }
1546 TyKind::FnPtr(f) => {
1547 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1548 hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1549 generic_params,
1550 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1551 abi: self.lower_extern(f.ext),
1552 decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
1553 param_idents: self.lower_fn_params_to_idents(&f.decl),
1554 }))
1555 }
1556 TyKind::UnsafeBinder(f) => {
1557 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1558 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1559 generic_params,
1560 inner_ty: self.lower_ty_alloc(&f.inner_ty, itctx),
1561 }))
1562 }
1563 TyKind::Never => hir::TyKind::Never,
1564 TyKind::Tup(tys) => hir::TyKind::Tup(
1565 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty(ty, itctx))),
1566 ),
1567 TyKind::Paren(ty) => {
1568 return self.lower_ty(ty, itctx);
1569 }
1570 TyKind::Path(qself, path) => {
1571 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1572 }
1573 TyKind::ImplicitSelf => {
1574 let hir_id = self.next_id();
1575 let res = self.expect_full_res(t.id);
1576 let res = self.lower_res(res);
1577 hir::TyKind::Path(hir::QPath::Resolved(
1578 None,
1579 self.arena.alloc(hir::Path {
1580 res,
1581 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1582 Ident::with_dummy_span(kw::SelfUpper),
1583 hir_id,
1584 res
1585 )],
1586 span: self.lower_span(t.span),
1587 }),
1588 ))
1589 }
1590 TyKind::Array(ty, length) => hir::TyKind::Array(
1591 self.lower_ty_alloc(ty, itctx),
1592 self.lower_array_length_to_const_arg(length),
1593 ),
1594 TyKind::TraitObject(bounds, kind) => {
1595 let mut lifetime_bound = None;
1596 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1597 let bounds =
1598 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1599 GenericBound::Trait(ty) => {
1603 let trait_ref = this.lower_poly_trait_ref(
1604 ty,
1605 RelaxedBoundPolicy::Forbidden(
1606 RelaxedBoundForbiddenReason::TraitObjectTy,
1607 ),
1608 itctx,
1609 );
1610 Some(trait_ref)
1611 }
1612 GenericBound::Outlives(lifetime) => {
1613 if lifetime_bound.is_none() {
1614 lifetime_bound = Some(this.lower_lifetime(
1615 lifetime,
1616 LifetimeSource::Other,
1617 lifetime.ident.into(),
1618 ));
1619 }
1620 None
1621 }
1622 GenericBound::Use(_, span) => {
1624 this.dcx()
1625 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1626 None
1627 }
1628 }));
1629 let lifetime_bound =
1630 lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
1631 (bounds, lifetime_bound)
1632 });
1633 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1634 }
1635 TyKind::ImplTrait(def_node_id, bounds) => {
1636 let span = t.span;
1637 match itctx {
1638 ImplTraitContext::OpaqueTy { origin } => {
1639 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1640 }
1641 ImplTraitContext::Universal => {
1642 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1643 ast::GenericBound::Use(_, span) => Some(span),
1644 _ => None,
1645 }) {
1646 self.tcx.dcx().emit_err(diagnostics::NoPreciseCapturesOnApit { span });
1647 }
1648
1649 let def_id = self.local_def_id(*def_node_id);
1650 let name = self.tcx.item_name(def_id.to_def_id());
1651 let ident = Ident::new(name, span);
1652 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1653 *def_node_id,
1654 span,
1655 ident,
1656 bounds,
1657 );
1658 self.impl_trait_defs.push(param);
1659 if let Some(bounds) = bounds {
1660 self.impl_trait_bounds.push(bounds);
1661 }
1662 path
1663 }
1664 ImplTraitContext::InBinding => {
1665 hir::TyKind::TraitAscription(self.lower_param_bounds(
1666 bounds,
1667 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1668 itctx,
1669 ))
1670 }
1671 ImplTraitContext::FeatureGated(position, feature) => {
1672 let guar = self
1673 .tcx
1674 .sess
1675 .create_feature_err(
1676 MisplacedImplTrait {
1677 span: t.span,
1678 position: DiagArgFromDisplay(&position),
1679 },
1680 feature,
1681 )
1682 .emit();
1683 hir::TyKind::Err(guar)
1684 }
1685 ImplTraitContext::Disallowed(position) => {
1686 let guar = self.dcx().emit_err(MisplacedImplTrait {
1687 span: t.span,
1688 position: DiagArgFromDisplay(&position),
1689 });
1690 hir::TyKind::Err(guar)
1691 }
1692 }
1693 }
1694 TyKind::Pat(ty, pat) => {
1695 hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
1696 }
1697 TyKind::FieldOf(ty, variant, field) => hir::TyKind::FieldOf(
1698 self.lower_ty_alloc(ty, itctx),
1699 self.arena.alloc(hir::TyFieldPath {
1700 variant: variant.map(|variant| self.lower_ident(variant)),
1701 field: self.lower_ident(*field),
1702 }),
1703 ),
1704 TyKind::MacCall(_) => {
1705 ::rustc_middle::util::bug::span_bug_fmt(t.span,
format_args!("`TyKind::MacCall` should have been expanded by now"))span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
1706 }
1707 TyKind::CVarArgs => {
1708 let guar = self.dcx().span_delayed_bug(
1709 t.span,
1710 "`TyKind::CVarArgs` should have been handled elsewhere",
1711 );
1712 hir::TyKind::Err(guar)
1713 }
1714 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1715 };
1716
1717 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1718 }
1719
1720 fn lower_ty_direct_lifetime(
1721 &mut self,
1722 t: &Ty,
1723 region: Option<Lifetime>,
1724 ) -> &'hir hir::Lifetime {
1725 let (region, syntax) = match region {
1726 Some(region) => (region, region.ident.into()),
1727
1728 None => {
1729 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1730 self.owner.get_lifetime_res(t.id)
1731 {
1732 {
match (&start.plus(1), &end) {
(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!(start.plus(1), end);
1733 start
1734 } else {
1735 self.next_node_id()
1736 };
1737 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1738 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1739 (region, LifetimeSyntax::Implicit)
1740 }
1741 };
1742 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1743 }
1744
1745 x;#[instrument(level = "debug", skip(self), ret)]
1777 fn lower_opaque_impl_trait(
1778 &mut self,
1779 span: Span,
1780 origin: hir::OpaqueTyOrigin<LocalDefId>,
1781 opaque_ty_node_id: NodeId,
1782 bounds: &GenericBounds,
1783 itctx: ImplTraitContext,
1784 ) -> hir::TyKind<'hir> {
1785 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1791
1792 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1793 this.lower_param_bounds(
1794 bounds,
1795 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1796 itctx,
1797 )
1798 })
1799 }
1800
1801 fn lower_opaque_inner(
1802 &mut self,
1803 opaque_ty_node_id: NodeId,
1804 origin: hir::OpaqueTyOrigin<LocalDefId>,
1805 opaque_ty_span: Span,
1806 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1807 ) -> hir::TyKind<'hir> {
1808 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1809 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1810 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1810",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1810u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["opaque_ty_def_id",
"opaque_ty_hir_id"],
::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(&opaque_ty_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&opaque_ty_hir_id)
as &dyn Value))])
});
} else { ; }
};debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
1811
1812 let bounds = lower_item_bounds(self);
1813 let opaque_ty_def = hir::OpaqueTy {
1814 hir_id: opaque_ty_hir_id,
1815 def_id: opaque_ty_def_id,
1816 bounds,
1817 origin,
1818 span: self.lower_span(opaque_ty_span),
1819 };
1820 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1821
1822 hir::TyKind::OpaqueDef(opaque_ty_def)
1823 }
1824
1825 fn lower_precise_capturing_args(
1826 &mut self,
1827 precise_capturing_args: &[PreciseCapturingArg],
1828 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1829 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1830 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1831 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1832 ),
1833 PreciseCapturingArg::Arg(path, id) => {
1834 let [segment] = path.segments.as_slice() else {
1835 ::core::panicking::panic("explicit panic");panic!();
1836 };
1837 let res = self.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1838 partial_res.full_res().expect("no partial res expected for precise capture arg")
1839 });
1840 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1841 hir_id: self.lower_node_id(*id),
1842 ident: self.lower_ident(segment.ident),
1843 res: self.lower_res(res),
1844 })
1845 }
1846 }))
1847 }
1848
1849 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1850 self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1851 PatKind::Missing => None,
1852 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1853 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1854 _ => {
1855 self.dcx().span_delayed_bug(
1856 param.pat.span,
1857 "non-missing/ident/wild param pat must trigger an error",
1858 );
1859 None
1860 }
1861 }))
1862 }
1863
1864 #[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("lower_fn_decl",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1873u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["decl", "fn_node_id",
"fn_span", "kind", "coro"],
::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(&decl)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_node_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
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: &'hir hir::FnDecl<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let c_variadic = decl.c_variadic();
let mut splatted = decl.splatted();
let mut inputs = &decl.inputs[..];
if decl.c_variadic() {
splatted = None;
inputs = &inputs[..inputs.len() - 1];
}
let inputs =
self.arena.alloc_from_iter(inputs.iter().map(|param|
{
let itctx =
match kind {
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl |
FnDeclKind::Trait => {
ImplTraitContext::Universal
}
FnDeclKind::ExternFn => {
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
}
FnDeclKind::Closure => {
ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
}
FnDeclKind::Pointer => {
ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
}
};
self.lower_ty(¶m.ty, itctx)
}));
let output =
match coro {
Some(coro) => {
let fn_def_id = self.owner.def_id;
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id,
coro, kind)
}
None =>
match &decl.output {
FnRetTy::Ty(ty) => {
let itctx =
match kind {
FnDeclKind::Fn | FnDeclKind::Inherent =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.owner.def_id,
in_trait_or_impl: None,
},
},
FnDeclKind::Trait =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.owner.def_id,
in_trait_or_impl: Some(hir::RpitContext::Trait),
},
},
FnDeclKind::Impl =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.owner.def_id,
in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
},
},
FnDeclKind::ExternFn => {
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
}
FnDeclKind::Closure => {
ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
}
FnDeclKind::Pointer => {
ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
}
};
hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
}
FnRetTy::Default(span) =>
hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
},
};
let fn_decl_kind =
hir::FnDeclFlags::default().set_implicit_self(decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None,
|arg|
{
let is_mutable_pat =
#[allow(non_exhaustive_omitted_patterns)] match arg.pat.kind
{
PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..) =>
true,
_ => false,
};
match &arg.ty.kind {
TyKind::ImplicitSelf if is_mutable_pat =>
hir::ImplicitSelfKind::Mut,
TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt) if
mt.ty.kind.is_implicit_self() => {
match mt.mutbl {
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
}
}
_ => hir::ImplicitSelfKind::None,
}
})).set_lifetime_elision_allowed(self.owner.id == fn_node_id
&&
self.owner.lifetime_elision_allowed).set_c_variadic(c_variadic).set_splatted(splatted,
inputs.len()).unwrap();
self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
}
}
}#[instrument(level = "debug", skip(self))]
1874 fn lower_fn_decl(
1875 &mut self,
1876 decl: &FnDecl,
1877 fn_node_id: NodeId,
1878 fn_span: Span,
1879 kind: FnDeclKind,
1880 coro: Option<CoroutineKind>,
1881 ) -> &'hir hir::FnDecl<'hir> {
1882 let c_variadic = decl.c_variadic();
1883 let mut splatted = decl.splatted();
1884
1885 let mut inputs = &decl.inputs[..];
1889 if decl.c_variadic() {
1890 splatted = None;
1892 inputs = &inputs[..inputs.len() - 1];
1893 }
1894 let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
1895 let itctx = match kind {
1896 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
1897 ImplTraitContext::Universal
1898 }
1899 FnDeclKind::ExternFn => {
1900 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
1901 }
1902 FnDeclKind::Closure => {
1903 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
1904 }
1905 FnDeclKind::Pointer => {
1906 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
1907 }
1908 };
1909 self.lower_ty(¶m.ty, itctx)
1910 }));
1911
1912 let output = match coro {
1913 Some(coro) => {
1914 let fn_def_id = self.owner.def_id;
1915 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
1916 }
1917 None => match &decl.output {
1918 FnRetTy::Ty(ty) => {
1919 let itctx = match kind {
1920 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
1921 origin: hir::OpaqueTyOrigin::FnReturn {
1922 parent: self.owner.def_id,
1923 in_trait_or_impl: None,
1924 },
1925 },
1926 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
1927 origin: hir::OpaqueTyOrigin::FnReturn {
1928 parent: self.owner.def_id,
1929 in_trait_or_impl: Some(hir::RpitContext::Trait),
1930 },
1931 },
1932 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1933 origin: hir::OpaqueTyOrigin::FnReturn {
1934 parent: self.owner.def_id,
1935 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
1936 },
1937 },
1938 FnDeclKind::ExternFn => {
1939 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
1940 }
1941 FnDeclKind::Closure => {
1942 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
1943 }
1944 FnDeclKind::Pointer => {
1945 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
1946 }
1947 };
1948 hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
1949 }
1950 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
1951 },
1952 };
1953
1954 let fn_decl_kind = hir::FnDeclFlags::default()
1955 .set_implicit_self(decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
1956 let is_mutable_pat = matches!(
1957 arg.pat.kind,
1958 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
1959 );
1960
1961 match &arg.ty.kind {
1962 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
1963 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
1964 TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
1968 if mt.ty.kind.is_implicit_self() =>
1969 {
1970 match mt.mutbl {
1971 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1972 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
1973 }
1974 }
1975 _ => hir::ImplicitSelfKind::None,
1976 }
1977 }))
1978 .set_lifetime_elision_allowed(
1979 self.owner.id == fn_node_id && self.owner.lifetime_elision_allowed,
1980 )
1981 .set_c_variadic(c_variadic)
1982 .set_splatted(splatted, inputs.len())
1983 .unwrap();
1984
1985 self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
1986 }
1987
1988 #[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("lower_coroutine_fn_ret_ty",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1996u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["output",
"fn_def_id", "coro", "fn_kind"],
::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(&output)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_kind)
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: hir::FnRetTy<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let span = self.lower_span(output.span());
let (opaque_ty_node_id, allowed_features) =
match coro {
CoroutineKind::Async { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::Gen { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
(return_impl_trait_id,
Some(Arc::clone(&self.allow_async_iterator)))
}
};
let opaque_ty_span =
self.mark_span_with_reason(DesugaringKind::Async, span,
allowed_features);
let in_trait_or_impl =
match fn_kind {
FnDeclKind::Trait => Some(hir::RpitContext::Trait),
FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
FnDeclKind::Fn | FnDeclKind::Inherent => None,
FnDeclKind::ExternFn | FnDeclKind::Closure |
FnDeclKind::Pointer =>
::core::panicking::panic("internal error: entered unreachable code"),
};
let opaque_ty_ref =
self.lower_opaque_inner(opaque_ty_node_id,
hir::OpaqueTyOrigin::AsyncFn {
parent: fn_def_id,
in_trait_or_impl,
}, opaque_ty_span,
|this|
{
let bound =
this.lower_coroutine_fn_output_type_to_bound(output, coro,
opaque_ty_span,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: fn_def_id,
in_trait_or_impl,
},
});
this.arena.alloc_from_iter([bound])
});
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}
}
}#[instrument(level = "debug", skip(self))]
1997 fn lower_coroutine_fn_ret_ty(
1998 &mut self,
1999 output: &FnRetTy,
2000 fn_def_id: LocalDefId,
2001 coro: CoroutineKind,
2002 fn_kind: FnDeclKind,
2003 ) -> hir::FnRetTy<'hir> {
2004 let span = self.lower_span(output.span());
2005
2006 let (opaque_ty_node_id, allowed_features) = match coro {
2007 CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
2008 CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
2009 CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
2010 (return_impl_trait_id, Some(Arc::clone(&self.allow_async_iterator)))
2011 }
2012 };
2013
2014 let opaque_ty_span =
2015 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
2016
2017 let in_trait_or_impl = match fn_kind {
2018 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
2019 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
2020 FnDeclKind::Fn | FnDeclKind::Inherent => None,
2021 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
2022 };
2023
2024 let opaque_ty_ref = self.lower_opaque_inner(
2025 opaque_ty_node_id,
2026 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
2027 opaque_ty_span,
2028 |this| {
2029 let bound = this.lower_coroutine_fn_output_type_to_bound(
2030 output,
2031 coro,
2032 opaque_ty_span,
2033 ImplTraitContext::OpaqueTy {
2034 origin: hir::OpaqueTyOrigin::FnReturn {
2035 parent: fn_def_id,
2036 in_trait_or_impl,
2037 },
2038 },
2039 );
2040 arena_vec![this; bound]
2041 },
2042 );
2043
2044 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
2045 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
2046 }
2047
2048 fn lower_coroutine_fn_output_type_to_bound(
2050 &mut self,
2051 output: &FnRetTy,
2052 coro: CoroutineKind,
2053 opaque_ty_span: Span,
2054 itctx: ImplTraitContext,
2055 ) -> hir::GenericBound<'hir> {
2056 let output_ty = match output {
2058 FnRetTy::Ty(ty) => {
2059 self.lower_ty_alloc(ty, itctx)
2063 }
2064 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
2065 };
2066
2067 let (assoc_ty_name, trait_lang_item) = match coro {
2069 CoroutineKind::Async { .. } => (sym::Output, hir::LangItem::Future),
2070 CoroutineKind::Gen { .. } => (sym::Item, hir::LangItem::Iterator),
2071 CoroutineKind::AsyncGen { .. } => (sym::Item, hir::LangItem::AsyncIterator),
2072 };
2073
2074 let bound_args = self.arena.alloc(hir::GenericArgs {
2075 args: &[],
2076 constraints: self.arena.alloc_from_iter([self.assoc_ty_binding(assoc_ty_name,
opaque_ty_span, output_ty)])arena_vec![self; self.assoc_ty_binding(assoc_ty_name, opaque_ty_span, output_ty)],
2077 parenthesized: hir::GenericArgsParentheses::No,
2078 span_ext: DUMMY_SP,
2079 });
2080
2081 hir::GenericBound::Trait(hir::PolyTraitRef {
2082 bound_generic_params: &[],
2083 modifiers: hir::TraitBoundModifiers::NONE,
2084 trait_ref: hir::TraitRef {
2085 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
2086 hir_ref_id: self.next_id(),
2087 },
2088 span: opaque_ty_span,
2089 })
2090 }
2091
2092 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("lower_param_bound",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2092u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["tpb", "rbp",
"itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(&tpb)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
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: hir::GenericBound<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
match tpb {
GenericBound::Trait(p) => {
hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp,
itctx))
}
GenericBound::Outlives(lifetime) =>
hir::GenericBound::Outlives(self.lower_lifetime(lifetime,
LifetimeSource::OutlivesBound, lifetime.ident.into())),
GenericBound::Use(args, span) =>
hir::GenericBound::Use(self.lower_precise_capturing_args(args),
self.lower_span(*span)),
}
}
}
}#[instrument(level = "trace", skip(self))]
2093 fn lower_param_bound(
2094 &mut self,
2095 tpb: &GenericBound,
2096 rbp: RelaxedBoundPolicy<'_>,
2097 itctx: ImplTraitContext,
2098 ) -> hir::GenericBound<'hir> {
2099 match tpb {
2100 GenericBound::Trait(p) => {
2101 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
2102 }
2103 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
2104 lifetime,
2105 LifetimeSource::OutlivesBound,
2106 lifetime.ident.into(),
2107 )),
2108 GenericBound::Use(args, span) => hir::GenericBound::Use(
2109 self.lower_precise_capturing_args(args),
2110 self.lower_span(*span),
2111 ),
2112 }
2113 }
2114
2115 fn lower_lifetime(
2116 &mut self,
2117 l: &Lifetime,
2118 source: LifetimeSource,
2119 syntax: LifetimeSyntax,
2120 ) -> &'hir hir::Lifetime {
2121 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
2122 }
2123
2124 fn lower_lifetime_hidden_in_path(
2125 &mut self,
2126 id: NodeId,
2127 span: Span,
2128 angle_brackets: AngleBrackets,
2129 ) -> &'hir hir::Lifetime {
2130 self.new_named_lifetime(
2131 id,
2132 id,
2133 Ident::new(kw::UnderscoreLifetime, span),
2134 LifetimeSource::Path { angle_brackets },
2135 LifetimeSyntax::Implicit,
2136 )
2137 }
2138
2139 #[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("new_named_lifetime",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2139u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["id", "new_id",
"ident", "source", "syntax"],
::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)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&new_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&syntax)
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: &'hir hir::Lifetime = loop {};
return __tracing_attr_fake_return;
}
{
let res =
if let Some(res) = self.owner.get_lifetime_res(id) {
match res {
LifetimeRes::Param { param, .. } =>
hir::LifetimeKind::Param(param),
LifetimeRes::Fresh { param, .. } => {
{
match (&ident.name, &kw::UnderscoreLifetime) {
(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);
}
}
}
};
let param = self.local_def_id(param);
hir::LifetimeKind::Param(param)
}
LifetimeRes::Infer => {
{
match (&ident.name, &kw::UnderscoreLifetime) {
(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);
}
}
}
};
hir::LifetimeKind::Infer
}
LifetimeRes::Static { .. } => {
if !#[allow(non_exhaustive_omitted_patterns)] match ident.name
{
kw::StaticLifetime | kw::UnderscoreLifetime => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime)")
};
hir::LifetimeKind::Static
}
LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
LifetimeRes::ElidedAnchor { .. } => {
{
::core::panicking::panic_fmt(format_args!("Unexpected `ElidedAnchar` {0:?} at {1:?}",
ident, ident.span));
};
}
}
} else {
hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span,
"unresolved lifetime"))
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:2173",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2173u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::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(&res) as
&dyn Value))])
});
} else { ; }
};
self.arena.alloc(hir::Lifetime::new(self.lower_node_id(new_id),
self.lower_ident(ident), res, source, syntax))
}
}
}#[instrument(level = "debug", skip(self))]
2140 fn new_named_lifetime(
2141 &mut self,
2142 id: NodeId,
2143 new_id: NodeId,
2144 ident: Ident,
2145 source: LifetimeSource,
2146 syntax: LifetimeSyntax,
2147 ) -> &'hir hir::Lifetime {
2148 let res = if let Some(res) = self.owner.get_lifetime_res(id) {
2149 match res {
2150 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
2151 LifetimeRes::Fresh { param, .. } => {
2152 assert_eq!(ident.name, kw::UnderscoreLifetime);
2153 let param = self.local_def_id(param);
2154 hir::LifetimeKind::Param(param)
2155 }
2156 LifetimeRes::Infer => {
2157 assert_eq!(ident.name, kw::UnderscoreLifetime);
2158 hir::LifetimeKind::Infer
2159 }
2160 LifetimeRes::Static { .. } => {
2161 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
2162 hir::LifetimeKind::Static
2163 }
2164 LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
2165 LifetimeRes::ElidedAnchor { .. } => {
2166 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
2167 }
2168 }
2169 } else {
2170 hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
2171 };
2172
2173 debug!(?res);
2174 self.arena.alloc(hir::Lifetime::new(
2175 self.lower_node_id(new_id),
2176 self.lower_ident(ident),
2177 res,
2178 source,
2179 syntax,
2180 ))
2181 }
2182
2183 fn lower_generic_params_mut(
2184 &mut self,
2185 params: &[GenericParam],
2186 source: hir::GenericParamSource,
2187 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
2188 params.iter().map(move |param| self.lower_generic_param(param, source))
2189 }
2190
2191 fn lower_generic_params(
2192 &mut self,
2193 params: &[GenericParam],
2194 source: hir::GenericParamSource,
2195 ) -> &'hir [hir::GenericParam<'hir>] {
2196 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
2197 }
2198
2199 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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("lower_generic_param",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2199u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["param", "source"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::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(¶m)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
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: hir::GenericParam<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let (name, kind) = self.lower_generic_param_kind(param, source);
let hir_id = self.lower_node_id(param.id);
let param_attrs = ¶m.attrs;
let param_span = param.span();
let param =
hir::GenericParam {
hir_id,
def_id: self.local_def_id(param.id),
name,
span: self.lower_span(param.span()),
pure_wrt_drop: attr::contains_name(¶m.attrs,
sym::may_dangle),
kind,
colon_span: param.colon_span.map(|s| self.lower_span(s)),
source,
};
self.lower_attrs(hir_id, param_attrs, param_span,
Target::from_generic_param(¶m));
param
}
}
}#[instrument(level = "trace", skip(self))]
2200 fn lower_generic_param(
2201 &mut self,
2202 param: &GenericParam,
2203 source: hir::GenericParamSource,
2204 ) -> hir::GenericParam<'hir> {
2205 let (name, kind) = self.lower_generic_param_kind(param, source);
2206
2207 let hir_id = self.lower_node_id(param.id);
2208 let param_attrs = ¶m.attrs;
2209 let param_span = param.span();
2210 let param = hir::GenericParam {
2211 hir_id,
2212 def_id: self.local_def_id(param.id),
2213 name,
2214 span: self.lower_span(param.span()),
2215 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
2216 kind,
2217 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2218 source,
2219 };
2220 self.lower_attrs(hir_id, param_attrs, param_span, Target::from_generic_param(¶m));
2221 param
2222 }
2223
2224 fn lower_generic_param_kind(
2225 &mut self,
2226 param: &GenericParam,
2227 source: hir::GenericParamSource,
2228 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2229 match ¶m.kind {
2230 GenericParamKind::Lifetime => {
2231 let ident = self.lower_ident(param.ident);
2234 let param_name =
2235 if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) {
2236 ParamName::Error(ident)
2237 } else {
2238 ParamName::Plain(ident)
2239 };
2240 let kind =
2241 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2242
2243 (param_name, kind)
2244 }
2245 GenericParamKind::Type { default, .. } => {
2246 let default = default
2249 .as_ref()
2250 .filter(|_| match source {
2251 hir::GenericParamSource::Generics => true,
2252 hir::GenericParamSource::Binder => {
2253 self.dcx().emit_err(diagnostics::GenericParamDefaultInBinder {
2254 span: param.span(),
2255 });
2256
2257 false
2258 }
2259 })
2260 .map(|def| {
2261 self.lower_ty_alloc(
2262 def,
2263 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2264 )
2265 });
2266
2267 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2268
2269 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2270 }
2271 GenericParamKind::Const { ty, span: _, default } => {
2272 let ty = self.lower_ty_alloc(
2273 ty,
2274 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2275 );
2276
2277 let default = default
2280 .as_ref()
2281 .filter(|anon_const| match source {
2282 hir::GenericParamSource::Generics => true,
2283 hir::GenericParamSource::Binder => {
2284 let err =
2285 diagnostics::GenericParamDefaultInBinder { span: param.span() };
2286 if expr::WillCreateDefIdsVisitor
2287 .visit_expr(&anon_const.value)
2288 .is_break()
2289 {
2290 self.dcx().emit_fatal(err)
2294 } else {
2295 self.dcx().emit_err(err);
2296 false
2297 }
2298 }
2299 })
2300 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2301
2302 (
2303 hir::ParamName::Plain(self.lower_ident(param.ident)),
2304 hir::GenericParamKind::Const { ty, default },
2305 )
2306 }
2307 }
2308 }
2309
2310 fn lower_trait_ref(
2311 &mut self,
2312 modifiers: ast::TraitBoundModifiers,
2313 p: &TraitRef,
2314 itctx: ImplTraitContext,
2315 ) -> hir::TraitRef<'hir> {
2316 let path = match self.lower_qpath(
2317 p.ref_id,
2318 &None,
2319 &p.path,
2320 ParamMode::Explicit,
2321 AllowReturnTypeNotation::No,
2322 itctx,
2323 Some(modifiers),
2324 ) {
2325 hir::QPath::Resolved(None, path) => path,
2326 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2327 };
2328 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2329 }
2330
2331 #[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("lower_poly_trait_ref",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2331u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["bound_generic_params",
"modifiers", "trait_ref", "span", "rbp", "itctx"],
::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(&bound_generic_params)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&modifiers)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
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: hir::PolyTraitRef<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let bound_generic_params =
self.lower_lifetime_binder(trait_ref.ref_id,
bound_generic_params);
let trait_ref =
self.lower_trait_ref(*modifiers, trait_ref, itctx);
let modifiers = self.lower_trait_bound_modifiers(*modifiers);
if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
self.validate_relaxed_bound(trait_ref, *span, rbp);
}
hir::PolyTraitRef {
bound_generic_params,
modifiers,
trait_ref,
span: self.lower_span(*span),
}
}
}
}#[instrument(level = "debug", skip(self))]
2332 fn lower_poly_trait_ref(
2333 &mut self,
2334 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2335 rbp: RelaxedBoundPolicy<'_>,
2336 itctx: ImplTraitContext,
2337 ) -> hir::PolyTraitRef<'hir> {
2338 let bound_generic_params =
2339 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2340 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2341 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2342
2343 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2344 self.validate_relaxed_bound(trait_ref, *span, rbp);
2345 }
2346
2347 hir::PolyTraitRef {
2348 bound_generic_params,
2349 modifiers,
2350 trait_ref,
2351 span: self.lower_span(*span),
2352 }
2353 }
2354
2355 fn validate_relaxed_bound(
2356 &self,
2357 trait_ref: hir::TraitRef<'_>,
2358 span: Span,
2359 rbp: RelaxedBoundPolicy<'_>,
2360 ) {
2361 match rbp {
2371 RelaxedBoundPolicy::Allowed(dedup_map) => {
2372 let Some(trait_def_id) = trait_ref.trait_def_id() else { return };
2374 let tcx = self.tcx;
2375 let err = |s| {
2376 let name = tcx.item_name(trait_def_id);
2377 tcx.dcx()
2378 .struct_span_err(
2379 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[span, s]))vec![span, s],
2380 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("duplicate relaxed `{0}` bounds",
name))
})format!("duplicate relaxed `{name}` bounds"),
2381 )
2382 .with_code(E0203)
2383 .emit();
2384 };
2385 dedup_map.entry(trait_def_id).and_modify(|&mut s| err(s)).or_insert(span);
2386 return;
2387 }
2388 RelaxedBoundPolicy::Forbidden(reason) => {
2389 let gate = |context, subject| {
2390 let extended = self.tcx.features().more_maybe_bounds();
2391 let is_sized = trait_ref
2392 .trait_def_id()
2393 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, hir::LangItem::Sized));
2394
2395 if extended && !is_sized {
2396 return;
2397 }
2398
2399 let prefix = if extended { "`Sized` " } else { "" };
2400 let mut diag = self.dcx().struct_span_err(
2401 span,
2402 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("relaxed {0}bounds are not permitted in {1}",
prefix, context))
})format!("relaxed {prefix}bounds are not permitted in {context}"),
2403 );
2404 if is_sized {
2405 diag.note(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} are not implicitly bounded by `Sized`, so there is nothing to relax",
subject))
})format!(
2406 "{subject} are not implicitly bounded by `Sized`, \
2407 so there is nothing to relax"
2408 ));
2409 }
2410 diag.emit();
2411 };
2412
2413 match reason {
2414 RelaxedBoundForbiddenReason::TraitObjectTy => {
2415 gate("trait object types", "trait object types");
2416 return;
2417 }
2418 RelaxedBoundForbiddenReason::SuperTrait => {
2419 gate("supertrait bounds", "traits");
2420 return;
2421 }
2422 RelaxedBoundForbiddenReason::TraitAlias => {
2423 gate("trait alias bounds", "trait aliases");
2424 return;
2425 }
2426 RelaxedBoundForbiddenReason::AssocTyBounds
2427 | RelaxedBoundForbiddenReason::WhereBound => {}
2428 };
2429 }
2430 }
2431
2432 self.dcx()
2433 .struct_span_err(span, "this relaxed bound is not permitted here")
2434 .with_note(
2435 "in this context, relaxed bounds are only allowed on \
2436 type parameters defined on the closest item",
2437 )
2438 .emit();
2439 }
2440
2441 fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
2442 hir::MutTy { ty: self.lower_ty_alloc(&mt.ty, itctx), mutbl: mt.mutbl }
2443 }
2444
2445 x;#[instrument(level = "debug", skip(self), ret)]
2446 fn lower_param_bounds(
2447 &mut self,
2448 bounds: &[GenericBound],
2449 rbp: RelaxedBoundPolicy<'_>,
2450 itctx: ImplTraitContext,
2451 ) -> hir::GenericBounds<'hir> {
2452 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2453 }
2454
2455 fn lower_param_bounds_mut(
2456 &mut self,
2457 bounds: &[GenericBound],
2458 mut rbp: RelaxedBoundPolicy<'_>,
2459 itctx: ImplTraitContext,
2460 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2461 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp.reborrow(), itctx))
2462 }
2463
2464 x;#[instrument(level = "debug", skip(self), ret)]
2465 fn lower_universal_param_and_bounds(
2466 &mut self,
2467 node_id: NodeId,
2468 span: Span,
2469 ident: Ident,
2470 bounds: &[GenericBound],
2471 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2472 let def_id = self.local_def_id(node_id);
2474 let span = self.lower_span(span);
2475
2476 let param = hir::GenericParam {
2478 hir_id: self.lower_node_id(node_id),
2479 def_id,
2480 name: ParamName::Plain(self.lower_ident(ident)),
2481 pure_wrt_drop: false,
2482 span,
2483 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2484 colon_span: None,
2485 source: hir::GenericParamSource::Generics,
2486 };
2487
2488 let preds = self.lower_generic_bound_predicate(
2489 ident,
2490 node_id,
2491 &GenericParamKind::Type { default: None },
2492 bounds,
2493 None,
2494 span,
2495 RelaxedBoundPolicy::Allowed(&mut Default::default()),
2496 ImplTraitContext::Universal,
2497 hir::PredicateOrigin::ImplTrait,
2498 );
2499
2500 let hir_id = self.next_id();
2501 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2502 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2503 None,
2504 self.arena.alloc(hir::Path {
2505 span,
2506 res,
2507 segments:
2508 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2509 }),
2510 ));
2511
2512 (param, preds, ty)
2513 }
2514
2515 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2518 let block = self.lower_block(b, false);
2519 self.expr_block(block)
2520 }
2521
2522 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2523 match c.value.peel_parens().kind {
2526 ExprKind::Underscore => {
2527 let ct_kind = hir::ConstArgKind::Infer(());
2528 self.arena.alloc(hir::ConstArg {
2529 hir_id: self.lower_node_id(c.id),
2530 kind: ct_kind,
2531 span: self.lower_span(c.value.span),
2532 })
2533 }
2534 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2535 }
2536 }
2537
2538 #[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("lower_const_path_to_const_arg",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2541u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["path", "res",
"ty_id", "span"],
::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(&path)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
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: &'hir hir::ConstArg<'hir> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let is_trivial_path =
path.is_potential_trivial_const_arg() &&
#[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::ConstParam, _) => true,
_ => false,
};
let ct_kind =
if is_trivial_path || tcx.features().min_generic_const_args()
{
let qpath =
self.lower_qpath(ty_id, &None, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
hir::ConstArgKind::Path(qpath)
} else {
let node_id = self.next_node_id();
let span = self.lower_span(span);
let def_id =
self.create_def(node_id, None, DefKind::AnonConst, span);
let hir_id = self.lower_node_id(node_id);
let path_expr =
Expr {
id: ty_id,
kind: ExprKind::Path(None, path.clone()),
span,
attrs: AttrVec::new(),
tokens: None,
};
let ct =
self.with_new_scopes(span,
|this|
{
self.arena.alloc(hir::AnonConst {
def_id,
hir_id,
body: this.lower_const_body(path_expr.span,
Some(&path_expr)),
span,
})
});
hir::ConstArgKind::Anon(ct)
};
self.arena.alloc(hir::ConstArg {
hir_id: self.next_id(),
kind: ct_kind,
span: self.lower_span(span),
})
}
}
}#[instrument(level = "debug", skip(self))]
2542 fn lower_const_path_to_const_arg(
2543 &mut self,
2544 path: &Path,
2545 res: Res<NodeId>,
2546 ty_id: NodeId,
2547 span: Span,
2548 ) -> &'hir hir::ConstArg<'hir> {
2549 let tcx = self.tcx;
2550
2551 let is_trivial_path = path.is_potential_trivial_const_arg()
2552 && matches!(res, Res::Def(DefKind::ConstParam, _));
2553 let ct_kind = if is_trivial_path || tcx.features().min_generic_const_args() {
2554 let qpath = self.lower_qpath(
2555 ty_id,
2556 &None,
2557 path,
2558 ParamMode::Explicit,
2559 AllowReturnTypeNotation::No,
2560 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2562 None,
2563 );
2564 hir::ConstArgKind::Path(qpath)
2565 } else {
2566 let node_id = self.next_node_id();
2568 let span = self.lower_span(span);
2569
2570 let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2575 let hir_id = self.lower_node_id(node_id);
2576
2577 let path_expr = Expr {
2578 id: ty_id,
2579 kind: ExprKind::Path(None, path.clone()),
2580 span,
2581 attrs: AttrVec::new(),
2582 tokens: None,
2583 };
2584
2585 let ct = self.with_new_scopes(span, |this| {
2586 self.arena.alloc(hir::AnonConst {
2587 def_id,
2588 hir_id,
2589 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2590 span,
2591 })
2592 });
2593 hir::ConstArgKind::Anon(ct)
2594 };
2595
2596 self.arena.alloc(hir::ConstArg {
2597 hir_id: self.next_id(),
2598 kind: ct_kind,
2599 span: self.lower_span(span),
2600 })
2601 }
2602
2603 fn lower_const_item_rhs(
2604 &mut self,
2605 rhs_kind: &ConstItemRhsKind,
2606 span: Span,
2607 ) -> hir::ConstItemRhs<'hir> {
2608 match rhs_kind {
2609 ConstItemRhsKind::Body { rhs: Some(body) } => {
2610 hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body)))
2611 }
2612 ConstItemRhsKind::Body { rhs: None } => {
2613 hir::ConstItemRhs::Body(self.lower_const_body(span, None))
2614 }
2615 ConstItemRhsKind::TypeConst { rhs: Some(anon) } => {
2616 hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon))
2617 }
2618 ConstItemRhsKind::TypeConst { rhs: None } => {
2619 let const_arg = ConstArg {
2620 hir_id: self.next_id(),
2621 kind: hir::ConstArgKind::Error(
2622 self.dcx().span_delayed_bug(DUMMY_SP, "no block"),
2623 ),
2624 span: DUMMY_SP,
2625 };
2626 hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg))
2627 }
2628 }
2629 }
2630
2631 x;#[instrument(level = "debug", skip(self), ret)]
2632 fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir> {
2633 let span = self.lower_span(expr.span);
2634
2635 let overly_complex_const = |this: &mut Self| {
2636 let msg = "complex const arguments must be placed inside of a `const` block";
2637 let e = if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
2638 this.dcx().struct_span_fatal(expr.span, msg).emit()
2642 } else {
2643 this.dcx().struct_span_err(expr.span, msg).emit()
2644 };
2645
2646 ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e), span }
2647 };
2648
2649 match &expr.kind {
2650 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2651 let qpath = self.lower_qpath(
2652 func.id,
2653 qself,
2654 path,
2655 ParamMode::Explicit,
2656 AllowReturnTypeNotation::No,
2657 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2658 None,
2659 );
2660
2661 let lowered_args = self.arena.alloc_from_iter(args.iter().map(|arg| {
2662 let const_arg = self.lower_expr_to_const_arg_direct(arg);
2663 &*self.arena.alloc(const_arg)
2664 }));
2665
2666 ConstArg {
2667 hir_id: self.next_id(),
2668 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2669 span,
2670 }
2671 }
2672 ExprKind::Tup(exprs) => {
2673 let exprs = self.arena.alloc_from_iter(exprs.iter().map(|expr| {
2674 let expr = self.lower_expr_to_const_arg_direct(&expr);
2675 &*self.arena.alloc(expr)
2676 }));
2677
2678 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(exprs), span }
2679 }
2680 ExprKind::Path(qself, path) => {
2681 let qpath = self.lower_qpath(
2682 expr.id,
2683 qself,
2684 path,
2685 ParamMode::Explicit,
2686 AllowReturnTypeNotation::No,
2687 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2689 None,
2690 );
2691
2692 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath), span }
2693 }
2694 ExprKind::Struct(se) => {
2695 let path = self.lower_qpath(
2696 expr.id,
2697 &se.qself,
2698 &se.path,
2699 ParamMode::Explicit,
2703 AllowReturnTypeNotation::No,
2704 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2705 None,
2706 );
2707
2708 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2709 let hir_id = self.lower_node_id(f.id);
2710 self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField);
2714 let expr = self.lower_expr_to_const_arg_direct(&f.expr);
2715
2716 &*self.arena.alloc(hir::ConstArgExprField {
2717 hir_id,
2718 field: self.lower_ident(f.ident),
2719 expr: self.arena.alloc(expr),
2720 span: self.lower_span(f.span),
2721 })
2722 }));
2723
2724 ConstArg {
2725 hir_id: self.next_id(),
2726 kind: hir::ConstArgKind::Struct(path, fields),
2727 span,
2728 }
2729 }
2730 ExprKind::Array(elements) => {
2731 let lowered_elems = self.arena.alloc_from_iter(elements.iter().map(|element| {
2732 let const_arg = self.lower_expr_to_const_arg_direct(element);
2733 &*self.arena.alloc(const_arg)
2734 }));
2735 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
2736 span: self.lower_span(expr.span),
2737 elems: lowered_elems,
2738 });
2739
2740 ConstArg {
2741 hir_id: self.next_id(),
2742 kind: hir::ConstArgKind::Array(array_expr),
2743 span,
2744 }
2745 }
2746 ExprKind::Underscore => ConstArg {
2747 hir_id: self.lower_node_id(expr.id),
2748 kind: hir::ConstArgKind::Infer(()),
2749 span,
2750 },
2751 ExprKind::Block(block, _) => {
2752 if let [stmt] = block.stmts.as_slice()
2753 && let StmtKind::Expr(expr) = &stmt.kind
2754 {
2755 return self.lower_expr_to_const_arg_direct(expr);
2756 }
2757
2758 overly_complex_const(self)
2759 }
2760 ExprKind::Lit(literal) => {
2761 let span = self.lower_span(expr.span);
2762 let literal = self.lower_lit(literal, span);
2763
2764 ConstArg {
2765 hir_id: self.lower_node_id(expr.id),
2766 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
2767 span,
2768 }
2769 }
2770 ExprKind::Unary(UnOp::Neg, inner_expr)
2771 if let ExprKind::Lit(literal) = &inner_expr.kind =>
2772 {
2773 let span = self.lower_span(expr.span);
2774 let literal = self.lower_lit(literal, span);
2775
2776 if !matches!(literal.node, LitKind::Int(..)) {
2777 let err =
2778 self.dcx().struct_span_err(expr.span, "negated literal must be an integer");
2779
2780 return ConstArg {
2781 hir_id: self.next_id(),
2782 kind: hir::ConstArgKind::Error(err.emit()),
2783 span,
2784 };
2785 }
2786
2787 ConstArg {
2788 hir_id: self.lower_node_id(expr.id),
2789 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: true },
2790 span,
2791 }
2792 }
2793 ExprKind::ConstBlock(anon_const) => {
2794 let def_id = self.local_def_id(anon_const.id);
2795 assert_eq!(DefKind::InlineConst, self.tcx.def_kind(def_id));
2796 self.lower_anon_const_to_const_arg(anon_const, span)
2797 }
2798 _ => overly_complex_const(self),
2799 }
2800 }
2801
2802 fn lower_anon_const_to_const_arg_and_alloc(
2805 &mut self,
2806 anon: &AnonConst,
2807 ) -> &'hir hir::ConstArg<'hir> {
2808 self.arena.alloc(self.lower_anon_const_to_const_arg(anon, anon.value.span))
2809 }
2810
2811 #[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("lower_anon_const_to_const_arg",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2811u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["anon", "span"],
::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(&anon)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
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: hir::ConstArg<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
if tcx.features().min_generic_const_args() {
return match anon.mgca_disambiguation {
MgcaDisambiguation::AnonConst => {
let lowered_anon =
self.lower_anon_const_to_anon_const(anon, span);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
span: lowered_anon.span,
}
}
MgcaDisambiguation::Direct =>
self.lower_expr_to_const_arg_direct(&anon.value),
};
}
let expr =
if let ExprKind::Block(block, _) = &anon.value.kind &&
let [stmt] = block.stmts.as_slice() &&
let StmtKind::Expr(expr) = &stmt.kind &&
let ExprKind::Path(..) = &expr.kind {
expr
} else { &anon.value };
let maybe_res =
self.get_partial_res(expr.id).and_then(|partial_res|
partial_res.full_res());
if let ExprKind::Path(qself, path) = &expr.kind &&
path.is_potential_trivial_const_arg() &&
#[allow(non_exhaustive_omitted_patterns)] match maybe_res {
Some(Res::Def(DefKind::ConstParam, _)) => true,
_ => false,
} {
let qpath =
self.lower_qpath(expr.id, qself, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
return ConstArg {
hir_id: self.lower_node_id(anon.id),
kind: hir::ConstArgKind::Path(qpath),
span: self.lower_span(expr.span),
};
}
let lowered_anon =
self.lower_anon_const_to_anon_const(anon, anon.value.span);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
span: self.lower_span(expr.span),
}
}
}
}#[instrument(level = "debug", skip(self))]
2812 fn lower_anon_const_to_const_arg(
2813 &mut self,
2814 anon: &AnonConst,
2815 span: Span,
2816 ) -> hir::ConstArg<'hir> {
2817 let tcx = self.tcx;
2818
2819 if tcx.features().min_generic_const_args() {
2825 return match anon.mgca_disambiguation {
2826 MgcaDisambiguation::AnonConst => {
2827 let lowered_anon = self.lower_anon_const_to_anon_const(anon, span);
2828 ConstArg {
2829 hir_id: self.next_id(),
2830 kind: hir::ConstArgKind::Anon(lowered_anon),
2831 span: lowered_anon.span,
2832 }
2833 }
2834 MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
2835 };
2836 }
2837
2838 let expr = if let ExprKind::Block(block, _) = &anon.value.kind
2841 && let [stmt] = block.stmts.as_slice()
2842 && let StmtKind::Expr(expr) = &stmt.kind
2843 && let ExprKind::Path(..) = &expr.kind
2844 {
2845 expr
2846 } else {
2847 &anon.value
2848 };
2849
2850 let maybe_res =
2851 self.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2852 if let ExprKind::Path(qself, path) = &expr.kind
2853 && path.is_potential_trivial_const_arg()
2854 && matches!(maybe_res, Some(Res::Def(DefKind::ConstParam, _)))
2855 {
2856 let qpath = self.lower_qpath(
2857 expr.id,
2858 qself,
2859 path,
2860 ParamMode::Explicit,
2861 AllowReturnTypeNotation::No,
2862 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2863 None,
2864 );
2865
2866 return ConstArg {
2867 hir_id: self.lower_node_id(anon.id),
2868 kind: hir::ConstArgKind::Path(qpath),
2869 span: self.lower_span(expr.span),
2870 };
2871 }
2872
2873 let lowered_anon = self.lower_anon_const_to_anon_const(anon, anon.value.span);
2874 ConstArg {
2875 hir_id: self.next_id(),
2876 kind: hir::ConstArgKind::Anon(lowered_anon),
2877 span: self.lower_span(expr.span),
2878 }
2879 }
2880
2881 fn lower_anon_const_to_anon_const(
2884 &mut self,
2885 c: &AnonConst,
2886 span: Span,
2887 ) -> &'hir hir::AnonConst {
2888 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
2889 let def_id = this.local_def_id(c.id);
2890 let hir_id = this.lower_node_id(c.id);
2891 hir::AnonConst {
2892 def_id,
2893 hir_id,
2894 body: this.lower_const_body(c.value.span, Some(&c.value)),
2895 span: this.lower_span(span),
2896 }
2897 }))
2898 }
2899
2900 fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
2901 match u {
2902 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
2903 UserProvided => hir::UnsafeSource::UserProvided,
2904 }
2905 }
2906
2907 fn lower_trait_bound_modifiers(
2908 &mut self,
2909 modifiers: TraitBoundModifiers,
2910 ) -> hir::TraitBoundModifiers {
2911 let constness = match modifiers.constness {
2912 BoundConstness::Never => BoundConstness::Never,
2913 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
2914 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
2915 };
2916 let polarity = match modifiers.polarity {
2917 BoundPolarity::Positive => BoundPolarity::Positive,
2918 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
2919 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2920 };
2921 hir::TraitBoundModifiers { constness, polarity }
2922 }
2923
2924 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2927 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
2928 }
2929
2930 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
2931 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
2932 }
2933
2934 fn stmt_let_pat(
2935 &mut self,
2936 attrs: Option<&'hir [hir::Attribute]>,
2937 span: Span,
2938 init: Option<&'hir hir::Expr<'hir>>,
2939 pat: &'hir hir::Pat<'hir>,
2940 source: hir::LocalSource,
2941 ) -> hir::Stmt<'hir> {
2942 let hir_id = self.next_id();
2943 if let Some(a) = attrs {
2944 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
2945 self.attrs.insert(hir_id.local_id, a);
2946 }
2947 let local = hir::LetStmt {
2948 super_: None,
2949 hir_id,
2950 init,
2951 pat,
2952 els: None,
2953 source,
2954 span: self.lower_span(span),
2955 ty: None,
2956 };
2957 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2958 }
2959
2960 fn stmt_super_let_pat(
2961 &mut self,
2962 span: Span,
2963 pat: &'hir hir::Pat<'hir>,
2964 init: Option<&'hir hir::Expr<'hir>>,
2965 ) -> hir::Stmt<'hir> {
2966 let hir_id = self.next_id();
2967 let span = self.lower_span(span);
2968 let local = hir::LetStmt {
2969 super_: Some(span),
2970 hir_id,
2971 init,
2972 pat,
2973 els: None,
2974 source: hir::LocalSource::Normal,
2975 span,
2976 ty: None,
2977 };
2978 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2979 }
2980
2981 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
2982 self.block_all(expr.span, &[], Some(expr))
2983 }
2984
2985 fn block_all(
2986 &mut self,
2987 span: Span,
2988 stmts: &'hir [hir::Stmt<'hir>],
2989 expr: Option<&'hir hir::Expr<'hir>>,
2990 ) -> &'hir hir::Block<'hir> {
2991 let blk = hir::Block {
2992 stmts,
2993 expr,
2994 hir_id: self.next_id(),
2995 rules: hir::BlockCheckMode::DefaultBlock,
2996 span: self.lower_span(span),
2997 targeted_by_break: false,
2998 };
2999 self.arena.alloc(blk)
3000 }
3001
3002 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3003 let field = self.single_pat_field(span, pat);
3004 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field)
3005 }
3006
3007 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3008 let field = self.single_pat_field(span, pat);
3009 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowBreak, field)
3010 }
3011
3012 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3013 let field = self.single_pat_field(span, pat);
3014 self.pat_lang_item_variant(span, hir::LangItem::OptionSome, field)
3015 }
3016
3017 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
3018 self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[])
3019 }
3020
3021 fn single_pat_field(
3022 &mut self,
3023 span: Span,
3024 pat: &'hir hir::Pat<'hir>,
3025 ) -> &'hir [hir::PatField<'hir>] {
3026 let field = hir::PatField {
3027 hir_id: self.next_id(),
3028 ident: Ident::new(sym::integer(0), self.lower_span(span)),
3029 is_shorthand: false,
3030 pat,
3031 span: self.lower_span(span),
3032 };
3033 self.arena.alloc_from_iter([field])arena_vec![self; field]
3034 }
3035
3036 fn pat_lang_item_variant(
3037 &mut self,
3038 span: Span,
3039 lang_item: hir::LangItem,
3040 fields: &'hir [hir::PatField<'hir>],
3041 ) -> &'hir hir::Pat<'hir> {
3042 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
3043 self.pat(span, hir::PatKind::Struct(path, fields, None))
3044 }
3045
3046 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
3047 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
3048 }
3049
3050 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
3051 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
3052 }
3053
3054 fn pat_ident_binding_mode(
3055 &mut self,
3056 span: Span,
3057 ident: Ident,
3058 bm: hir::BindingMode,
3059 ) -> (&'hir hir::Pat<'hir>, HirId) {
3060 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
3061 (self.arena.alloc(pat), hir_id)
3062 }
3063
3064 fn pat_ident_binding_mode_mut(
3065 &mut self,
3066 span: Span,
3067 ident: Ident,
3068 bm: hir::BindingMode,
3069 ) -> (hir::Pat<'hir>, HirId) {
3070 let hir_id = self.next_id();
3071
3072 (
3073 hir::Pat {
3074 hir_id,
3075 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
3076 span: self.lower_span(span),
3077 default_binding_modes: true,
3078 },
3079 hir_id,
3080 )
3081 }
3082
3083 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
3084 self.arena.alloc(hir::Pat {
3085 hir_id: self.next_id(),
3086 kind,
3087 span: self.lower_span(span),
3088 default_binding_modes: true,
3089 })
3090 }
3091
3092 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
3093 hir::Pat {
3094 hir_id: self.next_id(),
3095 kind,
3096 span: self.lower_span(span),
3097 default_binding_modes: false,
3098 }
3099 }
3100
3101 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
3102 let kind = match qpath {
3103 hir::QPath::Resolved(None, path) => {
3104 match path.res {
3106 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
3107 let principal = hir::PolyTraitRef {
3108 bound_generic_params: &[],
3109 modifiers: hir::TraitBoundModifiers::NONE,
3110 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
3111 span: self.lower_span(span),
3112 };
3113
3114 hir_id = self.next_id();
3117 hir::TyKind::TraitObject(
3118 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
3119 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
3120 )
3121 }
3122 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
3123 }
3124 }
3125 _ => hir::TyKind::Path(qpath),
3126 };
3127
3128 hir::Ty { hir_id, kind, span: self.lower_span(span) }
3129 }
3130
3131 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
3136 let r = hir::Lifetime::new(
3137 self.next_id(),
3138 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
3139 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
3140 LifetimeSource::Other,
3141 LifetimeSyntax::Implicit,
3142 );
3143 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:3143",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(3143u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::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!("elided_dyn_bound: r={0:?}",
r) as &dyn Value))])
});
} else { ; }
};debug!("elided_dyn_bound: r={:?}", r);
3144 self.arena.alloc(r)
3145 }
3146}
3147
3148struct GenericArgsCtor<'hir> {
3150 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
3151 constraints: &'hir [hir::AssocItemConstraint<'hir>],
3152 parenthesized: hir::GenericArgsParentheses,
3153 span: Span,
3154}
3155
3156impl<'hir> GenericArgsCtor<'hir> {
3157 fn is_empty(&self) -> bool {
3158 self.args.is_empty()
3159 && self.constraints.is_empty()
3160 && self.parenthesized == hir::GenericArgsParentheses::No
3161 }
3162
3163 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
3164 let ga = hir::GenericArgs {
3165 args: this.arena.alloc_from_iter(self.args),
3166 constraints: self.constraints,
3167 parenthesized: self.parenthesized,
3168 span_ext: this.lower_span(self.span),
3169 };
3170 this.arena.alloc(ga)
3171 }
3172}