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