1#![feature(const_default)]
35#![feature(const_trait_impl)]
36#![feature(default_field_values)]
37#![feature(deref_patterns)]
38#![recursion_limit = "256"]
39use std::mem;
42use std::sync::{Arc, LazyLock};
43
44use rustc_ast::mut_visit::{self, MutVisitor};
45use rustc_ast::node_id::NodeMap;
46use rustc_ast::visit::{self, Visitor};
47use rustc_ast::{self as ast, *};
48use rustc_attr_ir::find_attr;
49use rustc_attr_ir::lang_items::LangItem;
50use rustc_attr_ir::target::Target;
51use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
52use rustc_data_structures::fx::FxIndexMap;
53use rustc_data_structures::sorted_map::SortedMap;
54use rustc_data_structures::stable_hash::{StableHash, StableHasher};
55use rustc_data_structures::steal::Steal;
56use rustc_data_structures::tagged_ptr::TaggedRef;
57use rustc_errors::codes::*;
58use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, ErrorGuaranteed};
59use rustc_hir::def::{DefKind, Namespace, PerNS, Res};
60use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
61use rustc_hir::definitions::PerParentDisambiguatorState;
62use rustc_hir::lints::DelayedLint;
63use rustc_hir::{
64 self as hir, AngleBrackets, CRATE_OWNER_ID, ConstArg, GenericArg, HirId, ItemLocalMap,
65 LifetimeSource, LifetimeSyntax, MissingLifetimeKind, ParamName, TraitCandidate,
66};
67use rustc_index::{Idx, IndexSlice, IndexVec};
68use rustc_macros::extension;
69use rustc_middle::middle::resolve::{
70 AstOwner, LifetimeRes, PartialRes, PerOwnerResolverData, ResolverAstLowering,
71};
72use rustc_middle::queries::Providers;
73use rustc_middle::ty::TyCtxt;
74use rustc_session::diagnostics::add_feature_diagnostics;
75use rustc_span::symbol::{Ident, Symbol, kw, sym};
76use rustc_span::{DUMMY_SP, DesugaringKind, Span, span_bug};
77use smallvec::{SmallVec, smallvec};
78use thin_vec::ThinVec;
79use tracing::{debug, instrument, trace};
80
81use crate::diagnostics::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
82
83macro_rules! arena_vec {
84 ($this:expr; $($x:expr),*) => (
85 $this.arena.alloc_from_iter([$($x),*])
86 );
87}
88
89mod asm;
90mod block;
91mod contract;
92mod delegation;
93mod diagnostics;
94mod expr;
95mod format;
96mod index;
97mod item;
98mod pat;
99mod path;
100pub mod stability;
101
102pub fn provide(providers: &mut Providers) {
103 providers.index_ast = index_ast;
104 providers.lower_to_hir = lower_to_hir;
105 providers.resolve_type_relative_delegations =
106 delegation::resolution::resolve_type_relative_delegations;
107}
108
109#[cfg(debug_assertions)]
110pub(crate) mod re_lowering {
111 use rustc_ast::NodeId;
112 use rustc_ast::node_id::NodeMap;
113 use rustc_hir as hir;
114
115 use crate::LoweringContext;
116
117 #[derive(#[automatically_derived]
impl ::core::fmt::Debug for ReloweringChecker {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ReloweringChecker", "node_id_to_local_id",
&self.node_id_to_local_id, "can_relower", &&self.can_relower)
}
}Debug, #[automatically_derived]
impl ::core::default::Default for ReloweringChecker {
#[inline]
fn default() -> Self {
ReloweringChecker {
node_id_to_local_id: ::core::default::Default::default(),
can_relower: ::core::default::Default::default(),
}
}
}Default)]
118 pub(crate) struct ReloweringChecker {
119 node_id_to_local_id: NodeMap<hir::ItemLocalId>,
120 can_relower: bool,
121 }
122
123 impl ReloweringChecker {
124 pub(crate) fn assert_node_is_not_relowered(
125 &mut self,
126 ast_node_id: NodeId,
127 local_id: hir::ItemLocalId,
128 ) {
129 if !self.can_relower {
130 let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
131 {
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);
}
}
}
};assert_eq!(old, None);
132 }
133 }
134
135 pub(crate) fn allow_relowering<'a, 'hir, TRes>(
136 ctx: &mut LoweringContext<'a, 'hir>,
137 op: impl FnOnce(&mut LoweringContext<'a, 'hir>) -> TRes,
138 ) -> TRes {
139 if !!ctx.curr_owner.relowering_checker.can_relower {
{
::core::panicking::panic_fmt(format_args!("reentrant relowering is not supported"));
}
};assert!(
140 !ctx.curr_owner.relowering_checker.can_relower,
141 "reentrant relowering is not supported"
142 );
143
144 ctx.curr_owner.relowering_checker.can_relower = true;
145
146 let res = op(ctx);
147
148 ctx.curr_owner.relowering_checker.can_relower = false;
149
150 res
151 }
152 }
153}
154
155struct PerOwnerLoweringState<'a, 'hir> {
156 owner: &'a PerOwnerResolverData<'hir>,
158 disambiguator: PerParentDisambiguatorState,
159
160 item_local_id_counter: hir::ItemLocalId,
162 ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>,
165 #[cfg(debug_assertions)]
168 relowering_checker: re_lowering::ReloweringChecker,
169
170 attrs: SortedMap<hir::ItemLocalId, &'hir [rustc_attr_ir::Attribute]>,
173 bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
175 define_opaque: Option<&'hir [(Span, LocalDefId)]>,
177 trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>,
178 delayed_lints: Vec<DelayedLint>,
179 children: LocalDefIdMap<hir::MaybeOwner<'hir>>,
181
182 impl_trait_defs: Vec<hir::GenericParam<'hir>>,
184 impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
185}
186
187impl<'a, 'hir> PerOwnerLoweringState<'a, 'hir> {
188 fn new(resolver: &'a ResolverAstLowering<'hir>, owner: NodeId) -> Self {
189 let owner = &resolver.owners[&owner];
190
191 let disambiguator = resolver
192 .disambiguators
193 .get(&owner.def_id)
194 .map(|s| s.steal())
195 .unwrap_or_else(|| PerParentDisambiguatorState::new(owner.def_id));
196
197 PerOwnerLoweringState {
198 owner,
199 disambiguator,
200 item_local_id_counter: hir::ItemLocalId::new(1),
203 ident_and_label_to_local_id: Default::default(),
204 #[cfg(debug_assertions)]
205 relowering_checker: Default::default(),
206 attrs: SortedMap::default(),
207 bodies: Vec::new(),
208 define_opaque: None,
209 trait_map: Default::default(),
210 delayed_lints: Vec::new(),
211 children: LocalDefIdMap::default(),
212 impl_trait_defs: Vec::new(),
213 impl_trait_bounds: Vec::new(),
214 }
215 }
216
217 fn owner_id(&self) -> hir::OwnerId {
218 hir::OwnerId { def_id: self.owner.def_id }
219 }
220
221 fn into_owner_info(
222 self,
223 tcx: TyCtxt<'hir>,
224 node: hir::OwnerNode<'hir>,
225 ) -> &'hir hir::OwnerInfo<'hir> {
226 {
match (&self.owner_id(), &node.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);
}
}
}
};assert_eq!(self.owner_id(), node.def_id());
227 if !self.impl_trait_defs.is_empty() {
::core::panicking::panic("assertion failed: self.impl_trait_defs.is_empty()")
};assert!(self.impl_trait_defs.is_empty());
228 if !self.impl_trait_bounds.is_empty() {
::core::panicking::panic("assertion failed: self.impl_trait_bounds.is_empty()")
};assert!(self.impl_trait_bounds.is_empty());
229
230 let attrs = self.attrs;
231 let mut bodies = self.bodies;
232 let define_opaque = self.define_opaque;
233 let trait_map = self.trait_map;
234 let delayed_lints = Steal::new(self.delayed_lints.into_boxed_slice());
235 let children = self.children;
236
237 #[cfg(debug_assertions)]
238 for (id, attrs) in attrs.iter() {
239 if attrs.is_empty() {
241 {
::core::panicking::panic_fmt(format_args!("Stored empty attributes for {0:?}",
id));
};panic!("Stored empty attributes for {:?}", id);
242 }
243 }
244
245 bodies.sort_by_key(|(k, _)| *k);
246 let bodies = SortedMap::from_presorted_elements(bodies);
247
248 let rustc_middle::hir::Hashes { bodies_hash, attrs_hash } =
250 tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque);
251 let num_nodes = self.item_local_id_counter.as_usize();
252 let (nodes, parenting) = index::index_hir(tcx, node, &bodies, num_nodes);
253 let nodes = hir::OwnerNodes { opt_hash: bodies_hash, nodes, bodies };
254 let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
255
256 let opt_hash = tcx.needs_owner_info_hash().then(|| {
257 tcx.with_stable_hashing_context(|mut hcx| {
258 let mut stable_hasher = StableHasher::new();
259 bodies_hash.unwrap().stable_hash(&mut hcx, &mut stable_hasher);
260 attrs_hash.unwrap().stable_hash(&mut hcx, &mut stable_hasher);
261 parenting.stable_hash(&mut hcx, &mut stable_hasher);
263 trait_map.stable_hash(&mut hcx, &mut stable_hasher);
264 children.stable_hash(&mut hcx, &mut stable_hasher);
265 stable_hasher.finish()
266 })
267 });
268
269 tcx.hir_arena.alloc(hir::OwnerInfo {
270 opt_hash,
271 nodes,
272 parenting,
273 attrs,
274 trait_map,
275 delayed_lints,
276 children,
277 })
278 }
279}
280
281struct LoweringContext<'a, 'hir> {
282 tcx: TyCtxt<'hir>,
283 resolver: &'a ResolverAstLowering<'hir>,
284
285 curr_owner: PerOwnerLoweringState<'a, 'hir>,
286
287 arena: &'hir hir::Arena<'hir>,
289
290 contract_ensures: Option<(Span, Ident, HirId)>,
291
292 coroutine_kind: Option<hir::CoroutineKind>,
293
294 task_context: Option<HirId>,
297
298 current_item_span: Option<Span>,
301
302 try_block_scope: TryBlockScope,
303 loop_scope: Option<HirId>,
304 is_in_loop_condition: bool,
305 is_in_dyn_type: bool,
306
307 next_node_id: NodeId,
311 node_id_to_def_id: NodeMap<LocalDefId>,
313 partial_res_overrides: NodeMap<NodeId>,
317
318 move_expr_bindings: Vec<Option<expr::MoveExprState<'hir>>>,
322
323 lowering_move_expr_initializer: bool,
325
326 attribute_parser: AttributeParser<'hir>,
327}
328
329macro_rules! allow {
330 ($($name:ident: $list:expr;)*) => {
331 $( static $name: LazyLock<Arc<[Symbol]>> = LazyLock::new(|| $list.into()); )*
332 }
333}
334
335static ALLOW_CONTRACTS: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::contracts_internals].into());
static ALLOW_TRY_TRAIT: LazyLock<Arc<[Symbol]>> =
LazyLock::new(||
[sym::try_trait_v2, sym::try_trait_v2_residual,
sym::yeet_desugar_details].into());
static ALLOW_PATTERN_TYPE: LazyLock<Arc<[Symbol]>> =
LazyLock::new(||
[sym::pattern_types, sym::pattern_type_range_trait].into());
static ALLOW_GEN_FUTURE: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::gen_future].into());
static ALLOW_GEN_FUTURE_WITH_ASYNC_FN_TRACK_CALLER: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::gen_future, sym::closure_track_caller].into());
static ALLOW_FOR_AWAIT: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::async_gen_internals, sym::async_iterator].into());
static ALLOW_ASYNC_FN_TRAITS: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::async_fn_traits].into());
static ALLOW_ASYNC_GEN: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::async_gen_internals].into());
static ALLOW_ASYNC_ITERATOR: LazyLock<Arc<[Symbol]>> =
LazyLock::new(|| [sym::gen_future, sym::async_iterator].into());allow! {
336 ALLOW_CONTRACTS: [sym::contracts_internals];
337 ALLOW_TRY_TRAIT: [sym::try_trait_v2, sym::try_trait_v2_residual, sym::yeet_desugar_details];
338 ALLOW_PATTERN_TYPE: [sym::pattern_types, sym::pattern_type_range_trait];
339 ALLOW_GEN_FUTURE: [sym::gen_future];
340 ALLOW_GEN_FUTURE_WITH_ASYNC_FN_TRACK_CALLER: [sym::gen_future, sym::closure_track_caller];
341 ALLOW_FOR_AWAIT: [sym::async_gen_internals, sym::async_iterator];
342 ALLOW_ASYNC_FN_TRAITS: [sym::async_fn_traits];
343 ALLOW_ASYNC_GEN: [sym::async_gen_internals];
344 ALLOW_ASYNC_ITERATOR: [sym::gen_future, sym::async_iterator];
347}
348
349impl<'a, 'hir> LoweringContext<'a, 'hir> {
350 fn new(tcx: TyCtxt<'hir>, resolver: &'a ResolverAstLowering<'hir>, owner: NodeId) -> Self {
351 Self {
352 tcx,
353 resolver,
354 curr_owner: PerOwnerLoweringState::new(resolver, owner),
355 arena: tcx.hir_arena,
356
357 contract_ensures: None,
358
359 next_node_id: resolver.next_node_id,
360 node_id_to_def_id: NodeMap::default(),
361 partial_res_overrides: NodeMap::default(),
362
363 try_block_scope: TryBlockScope::Function,
365 loop_scope: None,
366 is_in_loop_condition: false,
367 is_in_dyn_type: false,
368 coroutine_kind: None,
369 task_context: None,
370 current_item_span: None,
371
372 move_expr_bindings: Vec::new(),
373 lowering_move_expr_initializer: false,
374 attribute_parser: AttributeParser::new(
375 tcx.sess,
376 tcx.features(),
377 tcx.registered_attr_tools(()),
378 ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
379 ),
380 }
381 }
382
383 pub(crate) fn dcx(&self) -> DiagCtxtHandle<'hir> {
384 self.tcx.dcx()
385 }
386
387 fn allow_gen_future(&self) -> &Arc<[Symbol]> {
388 if self.tcx.features().async_fn_track_caller() {
389 &ALLOW_GEN_FUTURE_WITH_ASYNC_FN_TRACK_CALLER
390 } else {
391 &ALLOW_GEN_FUTURE
392 }
393 }
394}
395
396struct SpanLowerer {
397 is_incremental: bool,
398 def_id: LocalDefId,
399}
400
401impl SpanLowerer {
402 fn lower(&self, span: Span) -> Span {
403 if self.is_incremental {
404 span.with_parent(Some(self.def_id))
405 } else {
406 span
408 }
409 }
410}
411
412trait ResolverAstLoweringExt<'tcx> {
fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'tcx>)
-> Option<Vec<usize>>;
}
impl<'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_attr_ir::HasAttrs::get_attrs(def_id, &tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcLegacyConstGenerics {
fn_indexes, .. }) => {
break 'done Some(fn_indexes);
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.map(|fn_indexes|
fn_indexes.iter().map(|(num, _)| *num).collect())
}
}#[extension(trait ResolverAstLoweringExt<'tcx>)]
413impl<'tcx> ResolverAstLowering<'tcx> {
414 fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'tcx>) -> Option<Vec<usize>> {
415 let ExprKind::Path(None, path) = &expr.kind else {
416 return None;
417 };
418
419 if path.segments.last().unwrap().args.is_some() {
422 return None;
423 }
424
425 let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
429
430 if def_id.is_local() {
434 return None;
435 }
436
437 find_attr!(
439 tcx, def_id,
440 RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes
441 )
442 .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
443 }
444}
445
446#[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 {
Self::Allowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Allowed", &__self_0),
Self::Forbidden(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Forbidden", &__self_0),
}
}
}Debug)]
451enum RelaxedBoundPolicy<'a> {
452 Allowed(&'a mut FxIndexMap<DefId, Span>),
454 Forbidden(RelaxedBoundForbiddenReason),
455}
456impl RelaxedBoundPolicy<'_> {
457 fn reborrow(&mut self) -> RelaxedBoundPolicy<'_> {
458 match self {
459 RelaxedBoundPolicy::Allowed(m) => RelaxedBoundPolicy::Allowed(m),
460 RelaxedBoundPolicy::Forbidden(reason) => RelaxedBoundPolicy::Forbidden(*reason),
461 }
462 }
463}
464
465#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for RelaxedBoundForbiddenReason { }
#[automatically_derived]
impl ::core::clone::Clone for RelaxedBoundForbiddenReason {
#[inline]
fn clone(&self) -> Self { *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)]
466enum RelaxedBoundForbiddenReason {
467 TraitObjectTy,
468 SuperTrait,
469 TraitAlias,
470 AssocTyBounds,
471 WhereBound,
474}
475
476#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Universal =>
::core::fmt::Formatter::write_str(f, "Universal"),
Self::OpaqueTy { origin: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"OpaqueTy", "origin", &__self_0),
Self::InBinding =>
::core::fmt::Formatter::write_str(f, "InBinding"),
Self::FeatureGated(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FeatureGated", __self_0, &__self_1),
Self::Disallowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Disallowed", &__self_0),
Self::AlreadyErrored(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AlreadyErrored", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitContext { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ImplTraitContext { }
#[automatically_derived]
impl ::core::clone::Clone for ImplTraitContext {
#[inline]
fn clone(&self) -> Self {
let _:
::core::clone::AssertParamIsClone<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::clone::AssertParamIsClone<ImplTraitPosition>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
let _: ::core::clone::AssertParamIsClone<ErrorGuaranteed>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ImplTraitContext { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitContext {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::OpaqueTy { origin: __self_0 }, Self::OpaqueTy {
origin: __arg1_0 }) => __self_0 == __arg1_0,
(Self::FeatureGated(__self_0, __self_1),
Self::FeatureGated(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Disallowed(__self_0), Self::Disallowed(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::AlreadyErrored(__self_0),
Self::AlreadyErrored(__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>;
let _: ::core::cmp::AssertParamIsEq<ErrorGuaranteed>;
}
}Eq)]
479enum ImplTraitContext {
480 Universal,
486
487 OpaqueTy { origin: hir::OpaqueTyOrigin<LocalDefId> },
492
493 InBinding,
498
499 FeatureGated(ImplTraitPosition, Symbol),
501 Disallowed(ImplTraitPosition),
503
504 AlreadyErrored(ErrorGuaranteed),
506}
507
508#[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]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ImplTraitPosition { }
#[automatically_derived]
impl ::core::clone::Clone for ImplTraitPosition {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ImplTraitPosition { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitPosition {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitPosition { }Eq)]
510enum ImplTraitPosition {
511 Path,
512 Variable,
513 Trait,
514 Bound,
515 Generic,
516 ExternFnParam,
517 ClosureParam,
518 PointerParam,
519 FnTraitParam,
520 ExternFnReturn,
521 ClosureReturn,
522 PointerReturn,
523 FnTraitReturn,
524 GenericDefault,
525 ConstTy,
526 StaticTy,
527 AssocTy,
528 FieldTy,
529 Cast,
530 ImplSelf,
531 OffsetOf,
532}
533
534impl std::fmt::Display for ImplTraitPosition {
535 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
536 let name = match self {
537 ImplTraitPosition::Path => "paths",
538 ImplTraitPosition::Variable => "the type of variable bindings",
539 ImplTraitPosition::Trait => "traits",
540 ImplTraitPosition::Bound => "bounds",
541 ImplTraitPosition::Generic => "generics",
542 ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
543 ImplTraitPosition::ClosureParam => "closure parameters",
544 ImplTraitPosition::PointerParam => "`fn` pointer parameters",
545 ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
546 ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
547 ImplTraitPosition::ClosureReturn => "closure return types",
548 ImplTraitPosition::PointerReturn => "`fn` pointer return types",
549 ImplTraitPosition::FnTraitReturn => "the return type of `Fn` trait bounds",
550 ImplTraitPosition::GenericDefault => "generic parameter defaults",
551 ImplTraitPosition::ConstTy => "const types",
552 ImplTraitPosition::StaticTy => "static types",
553 ImplTraitPosition::AssocTy => "associated types",
554 ImplTraitPosition::FieldTy => "field types",
555 ImplTraitPosition::Cast => "cast expression types",
556 ImplTraitPosition::ImplSelf => "impl headers",
557 ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
558 };
559
560 f.write_fmt(format_args!("{0}", name))write!(f, "{name}")
561 }
562}
563
564#[derive(#[automatically_derived]
impl ::core::marker::Copy for FnDeclKind { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for FnDeclKind { }
#[automatically_derived]
impl ::core::clone::Clone for FnDeclKind {
#[inline]
fn clone(&self) -> Self { *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::marker::StructuralPartialEq for FnDeclKind { }
#[automatically_derived]
impl ::core::cmp::PartialEq for FnDeclKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for FnDeclKind { }Eq)]
565enum FnDeclKind {
566 Fn,
567 Inherent,
568 ExternFn,
569 Closure,
570 Pointer,
571 Trait,
572 Impl,
573}
574
575#[derive(#[automatically_derived]
impl ::core::marker::Copy for TryBlockScope { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for TryBlockScope { }
#[automatically_derived]
impl ::core::clone::Clone for TryBlockScope {
#[inline]
fn clone(&self) -> Self {
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 {
Self::Function =>
::core::fmt::Formatter::write_str(f, "Function"),
Self::Homogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Homogeneous", &__self_0),
Self::Heterogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Heterogeneous", &__self_0),
}
}
}Debug)]
576enum TryBlockScope {
577 Function,
579 Homogeneous(HirId),
582 Heterogeneous(HirId),
585}
586
587fn index_ast<'tcx>(
588 tcx: TyCtxt<'tcx>,
589 (): (),
590) -> &'tcx IndexSlice<LocalDefId, Steal<(Arc<ResolverAstLowering<'tcx>>, AstOwner)>> {
591 tcx.ensure_done().output_filenames(());
593 tcx.ensure_done().early_lint_checks(());
594 tcx.ensure_done().get_lang_items(());
595 tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
596
597 let (resolver, krate) = tcx.resolver_for_lowering();
598 let mut resolver = resolver.steal();
599 let mut krate = krate.steal();
600
601 let mut indexer = Indexer {
602 owners: &resolver.owners,
603 index: IndexVec::new(),
604 next_node_id: resolver.next_node_id,
605 };
606 indexer.visit_crate(&mut krate);
607 indexer.insert(CRATE_NODE_ID, AstOwner::Crate(Box::new(krate)));
608 resolver.next_node_id = indexer.next_node_id;
609
610 let index = indexer.index;
611 let resolver = Arc::new(resolver);
612 return tcx.arena.alloc_index_slice_from_iter::<LocalDefId, _, _>(
613 index.into_iter().map(|owner| Steal::new((Arc::clone(&resolver), owner))),
614 );
615
616 struct Indexer<'s, 'hir> {
617 owners: &'s NodeMap<PerOwnerResolverData<'hir>>,
618 index: IndexVec<LocalDefId, AstOwner>,
619 next_node_id: NodeId,
620 }
621
622 impl Indexer<'_, '_> {
623 fn insert(&mut self, id: NodeId, node: AstOwner) {
624 let def_id = self.owners[&id].def_id;
625 self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner);
626 self.index[def_id] = node;
627 }
628
629 fn make_dummy<K>(
630 &mut self,
631 id: NodeId,
632 span: Span,
633 dummy: impl FnOnce(Box<MacCall>) -> K,
634 ) -> Box<Item<K>> {
635 use rustc_ast::token::Delimiter;
636 use rustc_ast::tokenstream::{DelimSpan, TokenStream};
637 use thin_vec::thin_vec;
638
639 Box::new(Item {
640 attrs: AttrVec::default(),
641 id,
642 span,
643 vis: Visibility { kind: VisibilityKind::Public, span },
644 kind: dummy(Box::new(MacCall {
647 path: Path { span, segments: ::thin_vec::ThinVec::new()thin_vec![] },
648 args: Box::new(DelimArgs {
649 dspan: DelimSpan::from_single(span),
650 delim: Delimiter::Parenthesis,
651 tokens: TokenStream::new(Vec::new()),
652 }),
653 })),
654 tokens: None,
655 })
656 }
657
658 fn replace_with_dummy<K>(
659 &mut self,
660 item: &mut ast::Item<K>,
661 dummy: impl FnOnce(Box<MacCall>) -> K,
662 node: impl FnOnce(Box<Item<K>>) -> AstOwner,
663 ) {
664 let dummy = self.make_dummy(item.id, item.span, dummy);
665 let item = mem::replace(item, *dummy);
666 self.insert(item.id, node(Box::new(item)));
667 }
668 }
669
670 impl MutVisitor for Indexer<'_, '_> {
671 fn visit_attribute(&mut self, _: &mut Attribute) {
672 }
675
676 fn flat_map_item(&mut self, mut item: Box<Item>) -> SmallVec<[Box<Item>; 1]> {
677 mut_visit::walk_item(self, &mut *item);
678 let dummy = self.make_dummy(item.id, item.span, ItemKind::MacCall);
679 let 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];
680 self.insert(item.id, AstOwner::Item(item));
681 items
682 }
683
684 fn visit_assoc_item(&mut self, item: &mut AssocItem, ctxt: visit::AssocCtxt) {
685 mut_visit::walk_assoc_item(self, item, ctxt);
686 match ctxt {
687 visit::AssocCtxt::Trait => {
688 self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::TraitItem)
689 }
690 visit::AssocCtxt::Impl { .. } => {
691 self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::ImplItem)
692 }
693 }
694 }
695
696 fn visit_foreign_item(&mut self, item: &mut ForeignItem) {
697 mut_visit::walk_item(self, item);
698 self.replace_with_dummy(item, ForeignItemKind::MacCall, AstOwner::ForeignItem);
699 }
700 }
701}
702
703{}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(703u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::MaybeOwner<'_> = loop {};
return __tracing_attr_fake_return;
}
{
tcx.ensure_done().resolve_type_relative_delegations(());
let ast_index = tcx.index_ast(());
let resolver_and_node = ast_index.get(def_id).map(Steal::steal);
let fallback_to_ancestor =
||
{
let parent_id = tcx.local_parent(def_id);
let mut parent_info = tcx.lower_to_hir(parent_id);
while 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(||
{
::rustc_span::macros::bug_impl(Some(tcx.source_span(def_id)),
format_args!("{0:?} does not appear in children of {1:?}",
def_id, parent_info.nodes.node().def_id()),
Location::caller())
})
};
let Some((resolver, node)) =
resolver_and_node else { return fallback_to_ancestor(); };
fn with_lctx<'hir>(tcx: TyCtxt<'hir>,
resolver: &ResolverAstLowering<'hir>, owner: NodeId,
f:
impl FnOnce(&mut LoweringContext<'_, 'hir>)
-> hir::OwnerNode<'hir>) -> hir::MaybeOwner<'hir> {
let mut lctx = LoweringContext::new(tcx, resolver, owner);
let item = f(&mut lctx);
hir::MaybeOwner::Owner(lctx.curr_owner.into_owner_info(tcx,
item))
}
let item =
match &node {
AstOwner::Crate(c) =>
with_lctx(tcx, &*resolver, CRATE_NODE_ID,
|lctx|
{
if true {
{
match (&lctx.curr_owner.owner_id(), &CRATE_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);
}
}
}
};
};
let module = lctx.lower_mod(&c.items, &c.spans);
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs,
c.spans.inner_span, Target::Crate);
hir::OwnerNode::Crate(module)
}),
AstOwner::Item(item) => {
with_lctx(tcx, &*resolver, item.id,
|lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
}
AstOwner::TraitItem(item) =>
with_lctx(tcx, &*resolver, item.id,
|lctx|
{ hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)) }),
AstOwner::ImplItem(item) =>
with_lctx(tcx, &*resolver, item.id,
|lctx|
{ hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)) }),
AstOwner::ForeignItem(item) =>
with_lctx(tcx, &*resolver, item.id,
|lctx|
{
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
}),
AstOwner::NonOwner => fallback_to_ancestor(),
};
tcx.sess.time("drop_ast", || mem::drop(node));
item
}
}
}#[instrument(level = "trace", skip(tcx))]
704fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> {
705 tcx.ensure_done().resolve_type_relative_delegations(());
706
707 let ast_index = tcx.index_ast(());
708 let resolver_and_node = ast_index.get(def_id).map(Steal::steal);
709
710 let fallback_to_ancestor = || {
711 let parent_id = tcx.local_parent(def_id);
714 let mut parent_info = tcx.lower_to_hir(parent_id);
715 while let hir::MaybeOwner::NonOwner(hir_id) = parent_info {
716 parent_info = tcx.lower_to_hir(hir_id.owner);
722 }
723
724 let parent_info = parent_info.unwrap();
725 *parent_info.children.get(&def_id).unwrap_or_else(|| {
726 span_bug!(
727 tcx.source_span(def_id),
728 "{:?} does not appear in children of {:?}",
729 def_id,
730 parent_info.nodes.node().def_id()
731 )
732 })
733 };
734
735 let Some((resolver, node)) = resolver_and_node else {
736 return fallback_to_ancestor();
740 };
741
742 fn with_lctx<'hir>(
743 tcx: TyCtxt<'hir>,
744 resolver: &ResolverAstLowering<'hir>,
745 owner: NodeId,
746 f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
747 ) -> hir::MaybeOwner<'hir> {
748 let mut lctx = LoweringContext::new(tcx, resolver, owner);
749 let item = f(&mut lctx);
750 hir::MaybeOwner::Owner(lctx.curr_owner.into_owner_info(tcx, item))
751 }
752
753 let item = match &node {
754 AstOwner::Crate(c) => with_lctx(tcx, &*resolver, CRATE_NODE_ID, |lctx| {
756 debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
757 let module = lctx.lower_mod(&c.items, &c.spans);
758 lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, Target::Crate);
759 hir::OwnerNode::Crate(module)
760 }),
761 AstOwner::Item(item) => {
762 with_lctx(tcx, &*resolver, item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
763 }
764 AstOwner::TraitItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
765 hir::OwnerNode::TraitItem(lctx.lower_trait_item(item))
766 }),
767 AstOwner::ImplItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
768 hir::OwnerNode::ImplItem(lctx.lower_impl_item(item))
769 }),
770 AstOwner::ForeignItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
771 hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
772 }),
773 AstOwner::NonOwner => fallback_to_ancestor(),
776 };
777
778 tcx.sess.time("drop_ast", || mem::drop(node));
779
780 item
781}
782
783#[derive(#[automatically_derived]
impl ::core::marker::Copy for ParamMode { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ParamMode { }
#[automatically_derived]
impl ::core::clone::Clone for ParamMode {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ParamMode { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ParamMode {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}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)]
784enum ParamMode {
785 Explicit,
787 Optional,
789}
790
791#[derive(#[automatically_derived]
impl ::core::marker::Copy for AllowReturnTypeNotation { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AllowReturnTypeNotation { }
#[automatically_derived]
impl ::core::clone::Clone for AllowReturnTypeNotation {
#[inline]
fn clone(&self) -> Self { *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)]
792enum AllowReturnTypeNotation {
793 Yes,
795 No,
797}
798
799enum GenericArgsMode {
800 ParenSugar,
802 ReturnTypeNotation,
804 Err,
806 Silence,
808}
809
810impl<'hir> LoweringContext<'_, 'hir> {
811 fn create_def(
812 &mut self,
813 node_id: NodeId,
814 name: Option<Symbol>,
815 def_kind: DefKind,
816 span: Span,
817 ) -> LocalDefId {
818 let parent = self.curr_owner.owner_id().def_id;
819 {
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);
820 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!(
821 self.opt_local_def_id(node_id).is_none(),
822 "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
823 node_id,
824 def_kind,
825 self.tcx.hir_def_key(self.local_def_id(node_id)),
826 );
827
828 let def_id = self
829 .tcx
830 .at(span)
831 .create_def(parent, name, def_kind, None, &mut self.curr_owner.disambiguator)
832 .def_id();
833
834 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:834",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(834u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("create_def: def_id_to_node_id[{0:?}] <-> {1:?}",
def_id, node_id) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
835 self.node_id_to_def_id.insert(node_id, def_id);
836
837 def_id
838 }
839
840 fn next_node_id(&mut self) -> NodeId {
841 let start = self.next_node_id;
842 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
843 self.next_node_id = NodeId::from_u32(next);
844 start
845 }
846
847 {}
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("opt_local_def_id",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(849u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("node")
}> =
::tracing::__macro_support::FieldName::new("node");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: Option<LocalDefId> =
loop {};
return __tracing_attr_fake_return;
}
{
self.node_id_to_def_id.get(&node).or_else(||
self.curr_owner.owner.node_id_to_def_id.get(&node)).copied()
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:849",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(849u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "trace", skip(self), ret)]
850 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
851 self.node_id_to_def_id
852 .get(&node)
853 .or_else(|| self.curr_owner.owner.node_id_to_def_id.get(&node))
854 .copied()
855 }
856
857 fn local_def_id(&self, node: NodeId) -> LocalDefId {
858 self.opt_local_def_id(node).unwrap_or_else(|| {
859 self.resolver.owners.items().any(|(id, items)| {
860 items.node_id_to_def_id.items().any(|(node_id, def_id)| {
861 if *node_id == node {
862 let actual_owner = items.node_id_to_def_id.get(id);
863 {
::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})",)
864 }
865 false
866 })
867 });
868 {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
};panic!("no entry for node id: `{node:?}`");
869 })
870 }
871
872 fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
873 match self.partial_res_overrides.get(&id) {
874 Some(self_param_id) => Some(PartialRes::new(Res::Local(*self_param_id))),
875 None => self.resolver.partial_res_map.get(&id).copied(),
876 }
877 }
878
879 fn owner_id(&self, node: NodeId) -> hir::OwnerId {
881 hir::OwnerId { def_id: self.resolver.owners[&node].def_id }
882 }
883
884 {}
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_node_id",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(889u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ast_node_id")
}> =
::tracing::__macro_support::FieldName::new("ast_node_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ast_node_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: HirId = loop {};
return __tracing_attr_fake_return;
}
{
{
match (&ast_node_id, &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);
}
}
}
};
let owner = self.curr_owner.owner_id();
let local_id = self.curr_owner.item_local_id_counter;
{
match (&local_id, &hir::ItemLocalId::ZERO) {
(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);
}
}
}
};
self.curr_owner.item_local_id_counter.increment_by(1);
let hir_id = HirId { owner, local_id };
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
self.curr_owner.children.insert(def_id,
hir::MaybeOwner::NonOwner(hir_id));
}
if let Some(traits) =
self.curr_owner.owner.trait_map.get(&ast_node_id) {
self.curr_owner.trait_map.insert(hir_id.local_id, *traits);
}
self.curr_owner.relowering_checker.assert_node_is_not_relowered(ast_node_id,
local_id);
hir_id
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:889",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(889u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
890 fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
891 assert_ne!(ast_node_id, DUMMY_NODE_ID);
892
893 let owner = self.curr_owner.owner_id();
894 let local_id = self.curr_owner.item_local_id_counter;
895 assert_ne!(local_id, hir::ItemLocalId::ZERO);
896 self.curr_owner.item_local_id_counter.increment_by(1);
897 let hir_id = HirId { owner, local_id };
898
899 if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
900 self.curr_owner.children.insert(def_id, hir::MaybeOwner::NonOwner(hir_id));
901 }
902
903 if let Some(traits) = self.curr_owner.owner.trait_map.get(&ast_node_id) {
904 self.curr_owner.trait_map.insert(hir_id.local_id, *traits);
905 }
906
907 #[cfg(debug_assertions)]
909 self.curr_owner.relowering_checker.assert_node_is_not_relowered(ast_node_id, local_id);
910
911 hir_id
912 }
913
914 {}
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("next_id",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(915u32),
::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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: HirId = loop {};
return __tracing_attr_fake_return;
}
{
let owner = self.curr_owner.owner_id();
let local_id = self.curr_owner.item_local_id_counter;
{
match (&local_id, &hir::ItemLocalId::ZERO) {
(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);
}
}
}
};
self.curr_owner.item_local_id_counter.increment_by(1);
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 /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:915",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(915u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
916 fn next_id(&mut self) -> HirId {
917 let owner = self.curr_owner.owner_id();
918 let local_id = self.curr_owner.item_local_id_counter;
919 assert_ne!(local_id, hir::ItemLocalId::ZERO);
920 self.curr_owner.item_local_id_counter.increment_by(1);
921 HirId { owner, local_id }
922 }
923
924 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(924u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Res = loop {};
return __tracing_attr_fake_return;
}
{
let res: Result<Res, ()> =
res.apply_id(|id|
{
let owner = self.curr_owner.owner_id();
let local_id =
self.curr_owner.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 /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:932",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(932u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
res.unwrap_or(Res::Err)
}
}
}#[instrument(level = "trace", skip(self))]
925 fn lower_res(&self, res: Res<NodeId>) -> Res {
926 let res: Result<Res, ()> = res.apply_id(|id| {
927 let owner = self.curr_owner.owner_id();
928 let local_id =
929 self.curr_owner.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
930 Ok(HirId { owner, local_id })
931 });
932 trace!(?res);
933
934 res.unwrap_or(Res::Err)
940 }
941
942 fn expect_full_res(&self, id: NodeId) -> Res<NodeId> {
943 self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
944 }
945
946 fn lower_import_res(&self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
947 let per_ns = self
948 .curr_owner
949 .owner
950 .import_res
951 .get(&id)
952 .unwrap_or_else(|| {
953 let sp = self.tcx.source_span(self.curr_owner.owner.def_id);
954 self.tcx.dcx().span_delayed_bug(
955 sp,
956 "no import_res entry for import, \
957 this should only happen if it already errored in resolve",
958 );
959 &PerNS { value_ns: None, type_ns: None, macro_ns: None }
960 })
961 .map(|res| res.map(|res| self.lower_res(res)));
962
963 if per_ns.is_empty() {
964 self.dcx().span_delayed_bug(span, "no resolution for an import");
966 let err = Some(Res::Err);
967 return PerNS { type_ns: err, value_ns: err, macro_ns: err };
968 }
969 per_ns
970 }
971
972 fn make_lang_item_qpath(
973 &mut self,
974 lang_item: LangItem,
975 span: Span,
976 args: Option<&'hir hir::GenericArgs<'hir>>,
977 ) -> hir::QPath<'hir> {
978 hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
979 }
980
981 fn make_lang_item_path(
982 &mut self,
983 lang_item: LangItem,
984 span: Span,
985 args: Option<&'hir hir::GenericArgs<'hir>>,
986 ) -> &'hir hir::Path<'hir> {
987 let def_id = self.tcx.require_lang_item(lang_item, span);
988 let def_kind = self.tcx.def_kind(def_id);
989 let res = Res::Def(def_kind, def_id);
990 self.arena.alloc(hir::Path {
991 span,
992 res,
993 segments: self.arena.alloc_from_iter([hir::PathSegment {
994 ident: Ident::new(lang_item.name(), span),
995 hir_id: self.next_id(),
996 res,
997 args,
998 infer_args: args.is_none(),
999 delegation_child_segment: false,
1000 }]),
1001 })
1002 }
1003
1004 fn mark_span_with_reason(
1007 &self,
1008 reason: DesugaringKind,
1009 span: Span,
1010 allow_internal_unstable: Option<Arc<[Symbol]>>,
1011 ) -> Span {
1012 self.tcx.with_stable_hashing_context(|hcx| {
1013 span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
1014 })
1015 }
1016
1017 fn span_lowerer(&self) -> SpanLowerer {
1018 SpanLowerer {
1019 is_incremental: self.tcx.sess.opts.incremental.is_some(),
1020 def_id: self.curr_owner.owner_id().def_id,
1021 }
1022 }
1023
1024 fn lower_span(&self, span: Span) -> Span {
1027 self.span_lowerer().lower(span)
1028 }
1029
1030 fn lower_ident(&self, ident: Ident) -> Ident {
1031 Ident::new(ident.name, self.lower_span(ident.span))
1032 }
1033
1034 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1035u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ident")
}> =
::tracing::__macro_support::FieldName::new("ident");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("node_id")
}> =
::tracing::__macro_support::FieldName::new("node_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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 /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:1050",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1050u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("_def_id")
}> =
::tracing::__macro_support::FieldName::new("_def_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&_def_id)
as &dyn ::tracing::field::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))]
1036 fn lifetime_res_to_generic_param(
1037 &mut self,
1038 ident: Ident,
1039 node_id: NodeId,
1040 kind: MissingLifetimeKind,
1041 source: hir::GenericParamSource,
1042 ) -> hir::GenericParam<'hir> {
1043 let _def_id = self.create_def(
1045 node_id,
1046 Some(kw::UnderscoreLifetime),
1047 DefKind::LifetimeParam,
1048 ident.span,
1049 );
1050 debug!(?_def_id);
1051
1052 let hir_id = self.lower_node_id(node_id);
1053 let def_id = self.local_def_id(node_id);
1054 hir::GenericParam {
1055 hir_id,
1056 def_id,
1057 name: hir::ParamName::Fresh,
1058 span: self.lower_span(ident.span),
1059 pure_wrt_drop: false,
1060 kind: hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided(kind) },
1061 colon_span: None,
1062 source,
1063 }
1064 }
1065
1066 {}
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_lifetime_binder",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1071u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("binder")
}> =
::tracing::__macro_support::FieldName::new("binder");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("generic_params")
}> =
::tracing::__macro_support::FieldName::new("generic_params");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&binder)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generic_params)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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::GenericParam<'hir>] = loop {};
return __tracing_attr_fake_return;
}
{
let extra_lifetimes =
self.curr_owner.owner.extra_lifetime_params(binder);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:1081",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1081u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("extra_lifetimes")
}> =
::tracing::__macro_support::FieldName::new("extra_lifetimes");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&extra_lifetimes)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let extra_lifetimes: Vec<_> =
extra_lifetimes.iter().map(|&(ident, node_id, res)|
{
self.lifetime_res_to_generic_param(ident, node_id, res,
hir::GenericParamSource::Binder)
}).collect();
let arena = self.arena;
let explicit_generic_params =
self.lower_generic_params_mut(generic_params,
hir::GenericParamSource::Binder);
arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:1071",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1071u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
1072 #[inline]
1073 fn lower_lifetime_binder(
1074 &mut self,
1075 binder: NodeId,
1076 generic_params: &[GenericParam],
1077 ) -> &'hir [hir::GenericParam<'hir>] {
1078 let extra_lifetimes = self.curr_owner.owner.extra_lifetime_params(binder);
1081 debug!(?extra_lifetimes);
1082 let extra_lifetimes: Vec<_> = extra_lifetimes
1083 .iter()
1084 .map(|&(ident, node_id, res)| {
1085 self.lifetime_res_to_generic_param(
1086 ident,
1087 node_id,
1088 res,
1089 hir::GenericParamSource::Binder,
1090 )
1091 })
1092 .collect();
1093 let arena = self.arena;
1094 let explicit_generic_params =
1095 self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
1096 arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
1097 }
1098
1099 fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
1100 let was_in_dyn_type = self.is_in_dyn_type;
1101 self.is_in_dyn_type = in_scope;
1102
1103 let result = f(self);
1104
1105 self.is_in_dyn_type = was_in_dyn_type;
1106
1107 result
1108 }
1109
1110 fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
1111 let current_item_span = self.current_item_span;
1112 self.current_item_span = Some(scope_span);
1113
1114 let was_in_loop_condition = self.is_in_loop_condition;
1115 self.is_in_loop_condition = false;
1116
1117 let old_contract = self.contract_ensures.take();
1118
1119 let try_block_scope = mem::replace(&mut self.try_block_scope, TryBlockScope::Function);
1120 let loop_scope = self.loop_scope.take();
1121 let ret = f(self);
1122 self.try_block_scope = try_block_scope;
1123 self.loop_scope = loop_scope;
1124
1125 self.contract_ensures = old_contract;
1126
1127 self.is_in_loop_condition = was_in_loop_condition;
1128
1129 self.current_item_span = current_item_span;
1130
1131 ret
1132 }
1133
1134 fn lower_attrs(
1135 &mut self,
1136 id: HirId,
1137 attrs: &[Attribute],
1138 target_span: Span,
1139 target: Target,
1140 ) -> &'hir [rustc_attr_ir::Attribute] {
1141 self.lower_attrs_with_extra(id, attrs, target_span, target, None, &[])
1142 }
1143
1144 fn lower_attrs_with_extra(
1145 &mut self,
1146 id: HirId,
1147 attrs: &[Attribute],
1148 target_span: Span,
1149 target: Target,
1150 target_item: Option<&ast::Item>,
1151 extra_hir_attributes: &[rustc_attr_ir::Attribute],
1152 ) -> &'hir [rustc_attr_ir::Attribute] {
1153 if attrs.is_empty() && extra_hir_attributes.is_empty() {
1154 &[]
1155 } else {
1156 let mut lowered_attrs =
1157 self.lower_attrs_vec(attrs, self.lower_span(target_span), id, target, target_item);
1158 lowered_attrs.extend(extra_hir_attributes.iter().cloned());
1159
1160 {
match (&id.owner, &self.curr_owner.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);
}
}
}
};assert_eq!(id.owner, self.curr_owner.owner_id());
1161 let ret = self.arena.alloc_from_iter(lowered_attrs);
1162
1163 if ret.is_empty() {
1170 &[]
1171 } else {
1172 self.curr_owner.attrs.insert(id.local_id, ret);
1173 ret
1174 }
1175 }
1176 }
1177
1178 fn lower_attrs_vec(
1179 &mut self,
1180 attrs: &[Attribute],
1181 target_span: Span,
1182 target_hir_id: HirId,
1183 target: Target,
1184 target_item: Option<&ast::Item>,
1185 ) -> Vec<rustc_attr_ir::Attribute> {
1186 let l = self.span_lowerer();
1187 self.attribute_parser.parse_attribute_list(
1188 attrs,
1189 target_span,
1190 target,
1191 target_item,
1192 |s| l.lower(s),
1193 |lint_id, span, kind| {
1194 self.curr_owner.delayed_lints.push(DelayedLint {
1195 lint_id,
1196 id: target_hir_id,
1197 span,
1198 callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
1199 let sess = sess
1200 .downcast_ref::<rustc_session::Session>()
1201 .expect("expected `Session`");
1202 (kind.0)(dcx, level, sess)
1203 }),
1204 });
1205 },
1206 )
1207 }
1208
1209 fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
1210 {
match (&id.owner, &self.curr_owner.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);
}
}
}
};assert_eq!(id.owner, self.curr_owner.owner_id());
1211 {
match (&target_id.owner, &self.curr_owner.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);
}
}
}
};assert_eq!(target_id.owner, self.curr_owner.owner_id());
1212 if let Some(&a) = self.curr_owner.attrs.get(&target_id.local_id) {
1213 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
1214 self.curr_owner.attrs.insert(id.local_id, a);
1215 }
1216 }
1217
1218 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1219u32),
::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_all(&[]) })
} 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 /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:1225",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1225u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("constraint")
}> =
::tracing::__macro_support::FieldName::new("constraint");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constraint)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::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 {
let guar =
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
self.lower_angle_bracketed_parameter_data(&data.as_angle_bracketed_args(),
ParamMode::Explicit,
ImplTraitContext::AlreadyErrored(guar)).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)]
1220 fn lower_assoc_item_constraint(
1221 &mut self,
1222 constraint: &AssocItemConstraint,
1223 itctx: ImplTraitContext,
1224 ) -> hir::AssocItemConstraint<'hir> {
1225 debug!(?constraint, ?itctx);
1226 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1228 let gen_args_ctor = match gen_args {
1229 GenericArgs::AngleBracketed(data) => {
1230 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1231 }
1232 GenericArgs::Parenthesized(data) => {
1233 if let Some(first_char) = constraint.ident.as_str().chars().next()
1234 && first_char.is_ascii_lowercase()
1235 {
1236 let err = match (&data.inputs[..], &data.output) {
1237 ([_, ..], FnRetTy::Default(_)) => {
1238 diagnostics::BadReturnTypeNotation::Inputs {
1239 span: data.inputs_span,
1240 }
1241 }
1242 ([], FnRetTy::Default(_)) => {
1243 diagnostics::BadReturnTypeNotation::NeedsDots {
1244 span: data.inputs_span,
1245 }
1246 }
1247 (_, FnRetTy::Ty(ty)) => {
1249 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1250 diagnostics::BadReturnTypeNotation::Output {
1251 span,
1252 suggestion: diagnostics::RTNSuggestion {
1253 output: span,
1254 input: data.inputs_span,
1255 },
1256 }
1257 }
1258 };
1259 let mut err = self.dcx().create_err(err);
1260 if !self.tcx.features().return_type_notation()
1261 && self.tcx.sess.is_nightly_build()
1262 {
1263 add_feature_diagnostics(
1264 &mut err,
1265 &self.tcx.sess,
1266 sym::return_type_notation,
1267 );
1268 }
1269 err.emit();
1270 GenericArgsCtor {
1271 args: Default::default(),
1272 constraints: &[],
1273 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1274 span: data.span,
1275 }
1276 } else {
1277 let guar = self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1278 self.lower_angle_bracketed_parameter_data(
1279 &data.as_angle_bracketed_args(),
1280 ParamMode::Explicit,
1281 ImplTraitContext::AlreadyErrored(guar),
1282 )
1283 .0
1284 }
1285 }
1286 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1287 args: Default::default(),
1288 constraints: &[],
1289 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1290 span: *span,
1291 },
1292 };
1293 gen_args_ctor.into_generic_args(self)
1294 } else {
1295 hir::GenericArgs::NONE
1296 };
1297 let kind = match &constraint.kind {
1298 AssocItemConstraintKind::Equality { term } => {
1299 let term = match term {
1300 Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
1301 Term::Const(c) => self.lower_anon_const_to_const_arg_and_alloc(c).into(),
1302 };
1303 hir::AssocItemConstraintKind::Equality { term }
1304 }
1305 AssocItemConstraintKind::Bound { bounds } => {
1306 if self.is_in_dyn_type {
1308 let suggestion = match itctx {
1309 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1310 let bound_end_span = constraint
1311 .gen_args
1312 .as_ref()
1313 .map_or(constraint.ident.span, |args| args.span());
1314 if bound_end_span.eq_ctxt(constraint.span) {
1315 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1316 } else {
1317 None
1318 }
1319 }
1320 _ => None,
1321 };
1322
1323 let guar = self.dcx().emit_err(diagnostics::MisplacedAssocTyBinding {
1324 span: constraint.span,
1325 suggestion,
1326 });
1327 let err_ty =
1328 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1329 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1330 } else {
1331 let bounds = self.lower_param_bounds(
1332 bounds,
1333 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1334 itctx,
1335 );
1336 hir::AssocItemConstraintKind::Bound { bounds }
1337 }
1338 }
1339 };
1340
1341 hir::AssocItemConstraint {
1342 hir_id: self.lower_node_id(constraint.id),
1343 ident: self.lower_ident(constraint.ident),
1344 gen_args,
1345 kind,
1346 span: self.lower_span(constraint.span),
1347 }
1348 }
1349
1350 fn emit_bad_parenthesized_trait_in_assoc_ty(
1351 &self,
1352 data: &ParenthesizedArgs,
1353 ) -> ErrorGuaranteed {
1354 let sub = if data.inputs.is_empty() {
1356 let parentheses_span =
1357 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1358 AssocTyParenthesesSub::Empty { parentheses_span }
1359 }
1360 else {
1362 let open_param = data.inputs_span.shrink_to_lo().to(data
1364 .inputs
1365 .first()
1366 .unwrap()
1367 .span
1368 .shrink_to_lo());
1369 let close_param =
1371 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1372 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1373 };
1374 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub })
1375 }
1376
1377 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1377u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("arg")
}> =
::tracing::__macro_support::FieldName::new("arg");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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(self.arena.alloc(hir::InferArg {
hir_id: self.lower_node_id(ty.id),
span: self.lower_span(ty.span),
kind: hir::InferArgKind::TypeOrConst,
}));
}
match &ty.kind {
TyKind::Path(None, path) if
path.is_single_argless_ident() &&
let Some(res) =
self.get_partial_res(ty.id).and_then(|partial_res|
partial_res.full_res()) &&
!res.matches_ns(Namespace::TypeNS) => {
let ct =
self.lower_const_path_to_const_arg(&None, path, res, ty.id,
ty.span);
let ct = self.arena.alloc(ct);
return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
}
TyKind::GcaMacro(expr) if
self.tcx.features().gca_min_const_items() => {
let ct =
match self.can_lower_expr_to_const_arg_direct(expr,
DirectConstArgContext::MacrolessMinGenericConstArgs) {
Ok(()) => self.lower_expr_to_const_arg_direct(expr, None),
Err(e) => e.emit(self),
};
let ct = self.arena.alloc(ct);
return match ct.try_as_ambig_ct() {
Some(ct) => GenericArg::Const(ct),
None =>
GenericArg::Infer(self.arena.alloc(hir::InferArg {
hir_id: ct.hir_id,
span: ct.span,
kind: hir::InferArgKind::Const,
})),
};
}
_ => {}
}
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(self.arena.alloc(hir::InferArg {
hir_id: ct.hir_id,
span: ct.span,
kind: hir::InferArgKind::Const,
})),
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1378 fn lower_generic_arg(
1379 &mut self,
1380 arg: &ast::GenericArg,
1381 itctx: ImplTraitContext,
1382 ) -> hir::GenericArg<'hir> {
1383 match arg {
1384 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1385 lt,
1386 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1387 lt.ident.into(),
1388 )),
1389 ast::GenericArg::Type(ty) => {
1390 if ty.is_maybe_parenthesised_infer() {
1393 return GenericArg::Infer(self.arena.alloc(hir::InferArg {
1394 hir_id: self.lower_node_id(ty.id),
1395 span: self.lower_span(ty.span),
1396 kind: hir::InferArgKind::TypeOrConst,
1397 }));
1398 }
1399
1400 match &ty.kind {
1401 TyKind::Path(None, path)
1412 if path.is_single_argless_ident()
1413 && let Some(res) = self
1414 .get_partial_res(ty.id)
1415 .and_then(|partial_res| partial_res.full_res())
1416 && !res.matches_ns(Namespace::TypeNS) =>
1417 {
1418 let ct =
1419 self.lower_const_path_to_const_arg(&None, path, res, ty.id, ty.span);
1420 let ct = self.arena.alloc(ct);
1421 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1422 }
1423 TyKind::GcaMacro(expr) if self.tcx.features().gca_min_const_items() => {
1424 let ct = match self.can_lower_expr_to_const_arg_direct(
1425 expr,
1426 DirectConstArgContext::MacrolessMinGenericConstArgs,
1427 ) {
1428 Ok(()) => self.lower_expr_to_const_arg_direct(expr, None),
1429 Err(e) => e.emit(self),
1430 };
1431 let ct = self.arena.alloc(ct);
1432 return match ct.try_as_ambig_ct() {
1433 Some(ct) => GenericArg::Const(ct),
1434 None => GenericArg::Infer(self.arena.alloc(hir::InferArg {
1435 hir_id: ct.hir_id,
1436 span: ct.span,
1437 kind: hir::InferArgKind::Const,
1438 })),
1439 };
1440 }
1441 _ => {}
1442 }
1443 GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
1444 }
1445 ast::GenericArg::Const(ct) => {
1446 let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1447 match ct.try_as_ambig_ct() {
1448 Some(ct) => GenericArg::Const(ct),
1449 None => GenericArg::Infer(self.arena.alloc(hir::InferArg {
1450 hir_id: ct.hir_id,
1451 span: ct.span,
1452 kind: hir::InferArgKind::Const,
1453 })),
1454 }
1455 }
1456 }
1457 }
1458
1459 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1459u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("t")
}> =
::tracing::__macro_support::FieldName::new("t");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&t)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::Ty<'hir> = loop {};
return __tracing_attr_fake_return;
}
{ self.arena.alloc(self.lower_ty(t, itctx)) }
}
}#[instrument(level = "debug", skip(self))]
1460 fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1461 self.arena.alloc(self.lower_ty(t, itctx))
1462 }
1463
1464 fn lower_path_ty(
1465 &mut self,
1466 t: &Ty,
1467 qself: &Option<Box<QSelf>>,
1468 path: &Path,
1469 param_mode: ParamMode,
1470 itctx: ImplTraitContext,
1471 ) -> hir::Ty<'hir> {
1472 if qself.is_none()
1478 && let Some(partial_res) = self.get_partial_res(t.id)
1479 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1480 {
1481 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1482 let bound = this.lower_poly_trait_ref(
1483 &PolyTraitRef {
1484 bound_generic_params: ThinVec::new(),
1485 modifiers: TraitBoundModifiers::NONE,
1486 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1487 span: t.span,
1488 parens: ast::Parens::No,
1489 },
1490 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1491 itctx,
1492 );
1493 let bounds = this.arena.alloc_from_iter([bound]);
1494 let lifetime_bound = this.elided_dyn_bound(t.span);
1495 (bounds, lifetime_bound)
1496 });
1497 let kind = hir::TyKind::TraitObject(
1498 bounds,
1499 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1500 );
1501 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1502 }
1503
1504 let id = self.lower_node_id(t.id);
1505 let qpath = self.lower_qpath(
1506 t.id,
1507 qself,
1508 path,
1509 param_mode,
1510 AllowReturnTypeNotation::Yes,
1511 itctx,
1512 None,
1513 );
1514 self.ty_path(id, t.span, qpath)
1515 }
1516
1517 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1518 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1519 }
1520
1521 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1522 self.ty(span, hir::TyKind::Tup(tys))
1523 }
1524
1525 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1526 let kind = match &t.kind {
1527 TyKind::Infer => hir::TyKind::Infer(()),
1528 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1529 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
1530 TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
1531 TyKind::Ref(region, mt) => {
1532 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1533 hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
1534 }
1535 TyKind::PinnedRef(region, mt) => {
1536 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1537 let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1538 let span = self.lower_span(t.span);
1539 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1540 let args = self.arena.alloc(hir::GenericArgs {
1541 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1542 constraints: &[],
1543 parenthesized: hir::GenericArgsParentheses::No,
1544 span_ext: span,
1545 });
1546 let path = self.make_lang_item_qpath(LangItem::Pin, span, Some(args));
1547 hir::TyKind::Path(path)
1548 }
1549 TyKind::FnPtr(f) => {
1550 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1551 hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1552 generic_params,
1553 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1554 abi: self.lower_extern(f.ext),
1555 decl: self.lower_fn_decl(&f.decl, t.id, FnDeclKind::Pointer, None),
1556 param_idents: self.lower_fn_params_to_idents(&f.decl),
1557 }))
1558 }
1559 TyKind::UnsafeBinder(f) => {
1560 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1561 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1562 generic_params,
1563 inner_ty: self.lower_ty_alloc(&f.inner_ty, itctx),
1564 }))
1565 }
1566 TyKind::Never => hir::TyKind::Never,
1567 TyKind::Tup(tys) => hir::TyKind::Tup(
1568 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty(ty, itctx))),
1569 ),
1570 TyKind::Paren(ty) => {
1571 return self.lower_ty(ty, itctx);
1572 }
1573 TyKind::Path(qself, path) => {
1574 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1575 }
1576 TyKind::ImplicitSelf => {
1577 let hir_id = self.next_id();
1578 let res = self.expect_full_res(t.id);
1579 let res = self.lower_res(res);
1580 hir::TyKind::Path(hir::QPath::Resolved(
1581 None,
1582 self.arena.alloc(hir::Path {
1583 res,
1584 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1585 Ident::with_dummy_span(kw::SelfUpper),
1586 hir_id,
1587 res
1588 )],
1589 span: self.lower_span(t.span),
1590 }),
1591 ))
1592 }
1593 TyKind::Array(ty, length) => hir::TyKind::Array(
1594 self.lower_ty_alloc(ty, itctx),
1595 self.lower_array_length_to_const_arg(length),
1596 ),
1597 TyKind::TraitObject(bounds, kind) => {
1598 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1599 let mut lifetime_bound = None;
1600 let bounds =
1601 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1602 GenericBound::Trait(ty) => {
1606 let trait_ref = this.lower_poly_trait_ref(
1607 ty,
1608 RelaxedBoundPolicy::Forbidden(
1609 RelaxedBoundForbiddenReason::TraitObjectTy,
1610 ),
1611 itctx,
1612 );
1613 Some(trait_ref)
1614 }
1615 GenericBound::Outlives(lifetime) => {
1616 if lifetime_bound.is_none() {
1617 lifetime_bound = Some(this.lower_lifetime(
1618 lifetime,
1619 LifetimeSource::Other,
1620 lifetime.ident.into(),
1621 ));
1622 }
1623 None
1624 }
1625 GenericBound::Use(_, span) => {
1627 this.dcx()
1628 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1629 None
1630 }
1631 }));
1632 (bounds, lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span)))
1633 });
1634 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1635 }
1636 TyKind::ImplTrait(def_node_id, bounds) => {
1637 let span = t.span;
1638 match itctx {
1639 ImplTraitContext::OpaqueTy { origin } => {
1640 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1641 }
1642 ImplTraitContext::Universal => {
1643 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1644 ast::GenericBound::Use(_, span) => Some(span),
1645 _ => None,
1646 }) {
1647 self.tcx.dcx().emit_err(diagnostics::NoPreciseCapturesOnApit { span });
1648 }
1649
1650 let def_id = self.local_def_id(*def_node_id);
1651 let name = self.tcx.item_name(def_id.to_def_id());
1652 let ident = Ident::new(name, span);
1653 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1654 *def_node_id,
1655 span,
1656 ident,
1657 bounds,
1658 );
1659 self.curr_owner.impl_trait_defs.push(param);
1660 if let Some(bounds) = bounds {
1661 self.curr_owner.impl_trait_bounds.push(bounds);
1662 }
1663 path
1664 }
1665 ImplTraitContext::InBinding => {
1666 hir::TyKind::TraitAscription(self.lower_param_bounds(
1667 bounds,
1668 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1669 itctx,
1670 ))
1671 }
1672 ImplTraitContext::FeatureGated(position, feature) => {
1673 let guar = self
1674 .tcx
1675 .sess
1676 .create_feature_err(
1677 MisplacedImplTrait {
1678 span: t.span,
1679 position: DiagArgFromDisplay(&position),
1680 },
1681 feature,
1682 )
1683 .emit_err();
1684 hir::TyKind::Err(guar)
1685 }
1686 ImplTraitContext::Disallowed(position) => {
1687 let guar = self.dcx().emit_err(MisplacedImplTrait {
1688 span: t.span,
1689 position: DiagArgFromDisplay(&position),
1690 });
1691 hir::TyKind::Err(guar)
1692 }
1693 ImplTraitContext::AlreadyErrored(guar) => {
1694 hir::TyKind::Err(guar)
1701 }
1702 }
1703 }
1704 TyKind::Pat(ty, pat) => {
1705 hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
1706 }
1707 TyKind::FieldOf(ty, variant, field) => hir::TyKind::FieldOf(
1708 self.lower_ty_alloc(ty, itctx),
1709 self.arena.alloc(hir::TyFieldPath {
1710 variant: variant.map(|variant| self.lower_ident(variant)),
1711 field: self.lower_ident(*field),
1712 }),
1713 ),
1714 TyKind::MacCall(_) => {
1715 ::rustc_span::macros::bug_impl(Some(t.span),
format_args!("`TyKind::MacCall` should have been expanded by now"),
Location::caller())span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
1716 }
1717 TyKind::CVarArgs => {
1718 let guar = self.dcx().span_delayed_bug(
1719 t.span,
1720 "`TyKind::CVarArgs` should have been handled elsewhere",
1721 );
1722 hir::TyKind::Err(guar)
1723 }
1724 TyKind::View(ty, fields) => {
1725 let ty = self.lower_ty_alloc(ty, itctx);
1726 let fields = self.arena.alloc_slice(fields);
1727 hir::TyKind::View(ty, fields)
1728 }
1729 TyKind::GcaMacro(expr) => {
1730 let e = self.emit_bad_gca_macro(t.span, expr, "type");
1731 hir::TyKind::Err(e)
1732 }
1733 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1734 };
1735
1736 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1737 }
1738
1739 pub(crate) fn emit_bad_gca_macro(
1740 &mut self,
1741 span: Span,
1742 expr: &Expr,
1743 expected: &'static str,
1744 ) -> ErrorGuaranteed {
1745 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected {0}, found `gca!()` constant",
expected))
})format!("expected {expected}, found `gca!()` constant");
1746 if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
1747 self.dcx().span_fatal(span, msg)
1750 } else {
1751 self.dcx().span_err(span, msg)
1752 }
1753 }
1754
1755 fn lower_ty_direct_lifetime(
1756 &mut self,
1757 t: &Ty,
1758 region: Option<Lifetime>,
1759 ) -> &'hir hir::Lifetime {
1760 let (region, syntax) = match region {
1761 Some(region) => (region, region.ident.into()),
1762
1763 None => {
1764 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1765 self.curr_owner.owner.get_lifetime_res(t.id)
1766 {
1767 {
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);
1768 start
1769 } else {
1770 self.next_node_id()
1771 };
1772 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1773 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1774 (region, LifetimeSyntax::Implicit)
1775 }
1776 };
1777 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1778 }
1779
1780 {}
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_opaque_impl_trait",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1811u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("origin")
}> =
::tracing::__macro_support::FieldName::new("origin");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("opaque_ty_node_id")
}> =
::tracing::__macro_support::FieldName::new("opaque_ty_node_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bounds")
}> =
::tracing::__macro_support::FieldName::new("bounds");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&origin)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opaque_ty_node_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bounds)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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::TyKind<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let opaque_ty_span =
self.mark_span_with_reason(DesugaringKind::OpaqueTy, span,
None);
self.lower_opaque_inner(opaque_ty_node_id, origin,
opaque_ty_span,
|this|
{
this.lower_param_bounds(bounds,
RelaxedBoundPolicy::Allowed(&mut Default::default()), itctx)
})
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:1811",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1811u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
1812 fn lower_opaque_impl_trait(
1813 &mut self,
1814 span: Span,
1815 origin: hir::OpaqueTyOrigin<LocalDefId>,
1816 opaque_ty_node_id: NodeId,
1817 bounds: &GenericBounds,
1818 itctx: ImplTraitContext,
1819 ) -> hir::TyKind<'hir> {
1820 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1826
1827 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1828 this.lower_param_bounds(
1829 bounds,
1830 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1831 itctx,
1832 )
1833 })
1834 }
1835
1836 fn lower_opaque_inner(
1837 &mut self,
1838 opaque_ty_node_id: NodeId,
1839 origin: hir::OpaqueTyOrigin<LocalDefId>,
1840 opaque_ty_span: Span,
1841 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1842 ) -> hir::TyKind<'hir> {
1843 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1844 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1845 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:1845",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1845u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("opaque_ty_def_id")
}> =
::tracing::__macro_support::FieldName::new("opaque_ty_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("opaque_ty_hir_id")
}> =
::tracing::__macro_support::FieldName::new("opaque_ty_hir_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opaque_ty_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opaque_ty_hir_id)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
1846
1847 let bounds = lower_item_bounds(self);
1848 let opaque_ty_def = hir::OpaqueTy {
1849 hir_id: opaque_ty_hir_id,
1850 def_id: opaque_ty_def_id,
1851 bounds,
1852 origin,
1853 span: self.lower_span(opaque_ty_span),
1854 };
1855 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1856
1857 hir::TyKind::OpaqueDef(opaque_ty_def)
1858 }
1859
1860 fn lower_precise_capturing_args(
1861 &mut self,
1862 precise_capturing_args: &[PreciseCapturingArg],
1863 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1864 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1865 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1866 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1867 ),
1868 PreciseCapturingArg::Arg(path, id) => {
1869 let [segment] = path.segments.as_slice() else {
1870 ::core::panicking::panic("explicit panic");panic!();
1871 };
1872 let res = self.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1873 partial_res.full_res().expect("no partial res expected for precise capture arg")
1874 });
1875 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1876 hir_id: self.lower_node_id(*id),
1877 ident: self.lower_ident(segment.ident),
1878 res: self.lower_res(res),
1879 })
1880 }
1881 }))
1882 }
1883
1884 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1885 self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1886 PatKind::Missing => None,
1887 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1888 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1889 _ => {
1890 self.dcx().span_delayed_bug(
1891 param.pat.span,
1892 "non-missing/ident/wild param pat must trigger an error",
1893 );
1894 None
1895 }
1896 }))
1897 }
1898
1899 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1908u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("decl")
}> =
::tracing::__macro_support::FieldName::new("decl");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_node_id")
}> =
::tracing::__macro_support::FieldName::new("fn_node_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("coro")
}> =
::tracing::__macro_support::FieldName::new("coro");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_node_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'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.curr_owner.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.curr_owner.owner.def_id,
in_trait_or_impl: None,
},
},
FnDeclKind::Trait =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.curr_owner.owner.def_id,
in_trait_or_impl: Some(hir::RpitContext::Trait),
},
},
FnDeclKind::Impl =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.curr_owner.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.curr_owner.owner.id ==
fn_node_id &&
self.curr_owner.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))]
1909 fn lower_fn_decl(
1910 &mut self,
1911 decl: &FnDecl,
1912 fn_node_id: NodeId,
1913 kind: FnDeclKind,
1914 coro: Option<CoroutineMarker>,
1915 ) -> &'hir hir::FnDecl<'hir> {
1916 let c_variadic = decl.c_variadic();
1917 let mut splatted = decl.splatted();
1918
1919 let mut inputs = &decl.inputs[..];
1923 if decl.c_variadic() {
1924 splatted = None;
1926 inputs = &inputs[..inputs.len() - 1];
1927 }
1928 let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
1929 let itctx = match kind {
1930 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
1931 ImplTraitContext::Universal
1932 }
1933 FnDeclKind::ExternFn => {
1934 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
1935 }
1936 FnDeclKind::Closure => {
1937 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
1938 }
1939 FnDeclKind::Pointer => {
1940 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
1941 }
1942 };
1943 self.lower_ty(¶m.ty, itctx)
1944 }));
1945
1946 let output = match coro {
1947 Some(coro) => {
1948 let fn_def_id = self.curr_owner.owner.def_id;
1949 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
1950 }
1951 None => match &decl.output {
1952 FnRetTy::Ty(ty) => {
1953 let itctx = match kind {
1954 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
1955 origin: hir::OpaqueTyOrigin::FnReturn {
1956 parent: self.curr_owner.owner.def_id,
1957 in_trait_or_impl: None,
1958 },
1959 },
1960 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
1961 origin: hir::OpaqueTyOrigin::FnReturn {
1962 parent: self.curr_owner.owner.def_id,
1963 in_trait_or_impl: Some(hir::RpitContext::Trait),
1964 },
1965 },
1966 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1967 origin: hir::OpaqueTyOrigin::FnReturn {
1968 parent: self.curr_owner.owner.def_id,
1969 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
1970 },
1971 },
1972 FnDeclKind::ExternFn => {
1973 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
1974 }
1975 FnDeclKind::Closure => {
1976 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
1977 }
1978 FnDeclKind::Pointer => {
1979 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
1980 }
1981 };
1982 hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
1983 }
1984 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
1985 },
1986 };
1987
1988 let fn_decl_kind = hir::FnDeclFlags::default()
1989 .set_implicit_self(decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
1990 let is_mutable_pat = matches!(
1991 arg.pat.kind,
1992 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
1993 );
1994
1995 match &arg.ty.kind {
1996 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
1997 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
1998 TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
2002 if mt.ty.kind.is_implicit_self() =>
2003 {
2004 match mt.mutbl {
2005 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
2006 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
2007 }
2008 }
2009 _ => hir::ImplicitSelfKind::None,
2010 }
2011 }))
2012 .set_lifetime_elision_allowed(
2013 self.curr_owner.owner.id == fn_node_id
2014 && self.curr_owner.owner.lifetime_elision_allowed,
2015 )
2016 .set_c_variadic(c_variadic)
2017 .set_splatted(splatted, inputs.len())
2018 .unwrap();
2019
2020 self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
2021 }
2022
2023 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2031u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("output")
}> =
::tracing::__macro_support::FieldName::new("output");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_def_id")
}> =
::tracing::__macro_support::FieldName::new("fn_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("coro")
}> =
::tracing::__macro_support::FieldName::new("coro");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_kind")
}> =
::tracing::__macro_support::FieldName::new("fn_kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_kind)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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.kind {
CoroutineKind::Async | CoroutineKind::Gen =>
(coro.return_impl_trait_id, None),
CoroutineKind::AsyncGen => {
(coro.return_impl_trait_id,
Some(Arc::clone(&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))]
2032 fn lower_coroutine_fn_ret_ty(
2033 &mut self,
2034 output: &FnRetTy,
2035 fn_def_id: LocalDefId,
2036 coro: CoroutineMarker,
2037 fn_kind: FnDeclKind,
2038 ) -> hir::FnRetTy<'hir> {
2039 let span = self.lower_span(output.span());
2040
2041 let (opaque_ty_node_id, allowed_features) = match coro.kind {
2042 CoroutineKind::Async | CoroutineKind::Gen => (coro.return_impl_trait_id, None),
2043 CoroutineKind::AsyncGen => {
2044 (coro.return_impl_trait_id, Some(Arc::clone(&ALLOW_ASYNC_ITERATOR)))
2045 }
2046 };
2047
2048 let opaque_ty_span =
2049 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
2050
2051 let in_trait_or_impl = match fn_kind {
2052 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
2053 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
2054 FnDeclKind::Fn | FnDeclKind::Inherent => None,
2055 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
2056 };
2057
2058 let opaque_ty_ref = self.lower_opaque_inner(
2059 opaque_ty_node_id,
2060 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
2061 opaque_ty_span,
2062 |this| {
2063 let bound = this.lower_coroutine_fn_output_type_to_bound(
2064 output,
2065 coro,
2066 opaque_ty_span,
2067 ImplTraitContext::OpaqueTy {
2068 origin: hir::OpaqueTyOrigin::FnReturn {
2069 parent: fn_def_id,
2070 in_trait_or_impl,
2071 },
2072 },
2073 );
2074 arena_vec![this; bound]
2075 },
2076 );
2077
2078 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
2079 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
2080 }
2081
2082 fn lower_coroutine_fn_output_type_to_bound(
2084 &mut self,
2085 output: &FnRetTy,
2086 coro: CoroutineMarker,
2087 opaque_ty_span: Span,
2088 itctx: ImplTraitContext,
2089 ) -> hir::GenericBound<'hir> {
2090 let output_ty = match output {
2092 FnRetTy::Ty(ty) => {
2093 self.lower_ty_alloc(ty, itctx)
2097 }
2098 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
2099 };
2100
2101 let (assoc_ty_name, trait_lang_item) = match coro.kind {
2103 CoroutineKind::Async => (sym::Output, LangItem::Future),
2104 CoroutineKind::Gen => (sym::Item, LangItem::Iterator),
2105 CoroutineKind::AsyncGen => (sym::Item, LangItem::AsyncIterator),
2106 };
2107
2108 let bound_args = self.arena.alloc(hir::GenericArgs {
2109 args: &[],
2110 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)],
2111 parenthesized: hir::GenericArgsParentheses::No,
2112 span_ext: DUMMY_SP,
2113 });
2114
2115 hir::GenericBound::Trait(hir::PolyTraitRef {
2116 bound_generic_params: &[],
2117 modifiers: hir::TraitBoundModifiers::NONE,
2118 trait_ref: hir::TraitRef {
2119 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
2120 hir_ref_id: self.next_id(),
2121 },
2122 span: opaque_ty_span,
2123 })
2124 }
2125
2126 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2126u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("tpb")
}> =
::tracing::__macro_support::FieldName::new("tpb");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rbp")
}> =
::tracing::__macro_support::FieldName::new("rbp");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&tpb)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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))]
2127 fn lower_param_bound(
2128 &mut self,
2129 tpb: &GenericBound,
2130 rbp: RelaxedBoundPolicy<'_>,
2131 itctx: ImplTraitContext,
2132 ) -> hir::GenericBound<'hir> {
2133 match tpb {
2134 GenericBound::Trait(p) => {
2135 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
2136 }
2137 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
2138 lifetime,
2139 LifetimeSource::OutlivesBound,
2140 lifetime.ident.into(),
2141 )),
2142 GenericBound::Use(args, span) => hir::GenericBound::Use(
2143 self.lower_precise_capturing_args(args),
2144 self.lower_span(*span),
2145 ),
2146 }
2147 }
2148
2149 fn lower_lifetime(
2150 &mut self,
2151 l: &Lifetime,
2152 source: LifetimeSource,
2153 syntax: LifetimeSyntax,
2154 ) -> &'hir hir::Lifetime {
2155 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
2156 }
2157
2158 fn lower_lifetime_hidden_in_path(
2159 &mut self,
2160 id: NodeId,
2161 span: Span,
2162 angle_brackets: AngleBrackets,
2163 ) -> &'hir hir::Lifetime {
2164 self.new_named_lifetime(
2165 id,
2166 id,
2167 Ident::new(kw::UnderscoreLifetime, span),
2168 LifetimeSource::Path { angle_brackets },
2169 LifetimeSyntax::Implicit,
2170 )
2171 }
2172
2173 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2173u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("new_id")
}> =
::tracing::__macro_support::FieldName::new("new_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ident")
}> =
::tracing::__macro_support::FieldName::new("ident");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("syntax")
}> =
::tracing::__macro_support::FieldName::new("syntax");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&new_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&syntax)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::Lifetime = loop {};
return __tracing_attr_fake_return;
}
{
let res =
if let Some(res) = self.curr_owner.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 /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:2207",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2207u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::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))]
2174 fn new_named_lifetime(
2175 &mut self,
2176 id: NodeId,
2177 new_id: NodeId,
2178 ident: Ident,
2179 source: LifetimeSource,
2180 syntax: LifetimeSyntax,
2181 ) -> &'hir hir::Lifetime {
2182 let res = if let Some(res) = self.curr_owner.owner.get_lifetime_res(id) {
2183 match res {
2184 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
2185 LifetimeRes::Fresh { param, .. } => {
2186 assert_eq!(ident.name, kw::UnderscoreLifetime);
2187 let param = self.local_def_id(param);
2188 hir::LifetimeKind::Param(param)
2189 }
2190 LifetimeRes::Infer => {
2191 assert_eq!(ident.name, kw::UnderscoreLifetime);
2192 hir::LifetimeKind::Infer
2193 }
2194 LifetimeRes::Static { .. } => {
2195 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
2196 hir::LifetimeKind::Static
2197 }
2198 LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
2199 LifetimeRes::ElidedAnchor { .. } => {
2200 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
2201 }
2202 }
2203 } else {
2204 hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
2205 };
2206
2207 debug!(?res);
2208 self.arena.alloc(hir::Lifetime::new(
2209 self.lower_node_id(new_id),
2210 self.lower_ident(ident),
2211 res,
2212 source,
2213 syntax,
2214 ))
2215 }
2216
2217 fn lower_generic_params_mut(
2218 &mut self,
2219 params: &[GenericParam],
2220 source: hir::GenericParamSource,
2221 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
2222 params.iter().map(move |param| self.lower_generic_param(param, source))
2223 }
2224
2225 fn lower_generic_params(
2226 &mut self,
2227 params: &[GenericParam],
2228 source: hir::GenericParamSource,
2229 ) -> &'hir [hir::GenericParam<'hir>] {
2230 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
2231 }
2232
2233 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2233u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("param")
}> =
::tracing::__macro_support::FieldName::new("param");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("source")
}> =
::tracing::__macro_support::FieldName::new("source");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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(¶m));
param
}
}
}#[instrument(level = "trace", skip(self))]
2234 fn lower_generic_param(
2235 &mut self,
2236 param: &GenericParam,
2237 source: hir::GenericParamSource,
2238 ) -> hir::GenericParam<'hir> {
2239 let (name, kind) = self.lower_generic_param_kind(param, source);
2240
2241 let hir_id = self.lower_node_id(param.id);
2242 let param_attrs = ¶m.attrs;
2243 let param_span = param.span();
2244 let param = hir::GenericParam {
2245 hir_id,
2246 def_id: self.local_def_id(param.id),
2247 name,
2248 span: self.lower_span(param.span()),
2249 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
2250 kind,
2251 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2252 source,
2253 };
2254 self.lower_attrs(hir_id, param_attrs, param_span, Target::from(¶m));
2255 param
2256 }
2257
2258 fn lower_generic_param_kind(
2259 &mut self,
2260 param: &GenericParam,
2261 source: hir::GenericParamSource,
2262 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2263 match ¶m.kind {
2264 GenericParamKind::Lifetime => {
2265 let ident = self.lower_ident(param.ident);
2268 let param_name = if let Some(LifetimeRes::Error(..)) =
2269 self.curr_owner.owner.get_lifetime_res(param.id)
2270 {
2271 ParamName::Error(ident)
2272 } else {
2273 ParamName::Plain(ident)
2274 };
2275 let kind =
2276 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2277
2278 (param_name, kind)
2279 }
2280 GenericParamKind::Type { default, .. } => {
2281 let default = default
2284 .as_ref()
2285 .filter(|_| match source {
2286 hir::GenericParamSource::Generics => true,
2287 hir::GenericParamSource::Binder => {
2288 self.dcx().emit_err(diagnostics::GenericParamDefaultInBinder {
2289 span: param.span(),
2290 });
2291
2292 false
2293 }
2294 })
2295 .map(|def| {
2296 self.lower_ty_alloc(
2297 def,
2298 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2299 )
2300 });
2301
2302 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2303
2304 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2305 }
2306 GenericParamKind::Const { ty, span: _, default } => {
2307 let ty = self.lower_ty_alloc(
2308 ty,
2309 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2310 );
2311
2312 let default = default
2315 .as_ref()
2316 .filter(|anon_const| match source {
2317 hir::GenericParamSource::Generics => true,
2318 hir::GenericParamSource::Binder => {
2319 let err =
2320 diagnostics::GenericParamDefaultInBinder { span: param.span() };
2321 if expr::WillCreateDefIdsVisitor
2322 .visit_expr(&anon_const.value)
2323 .is_break()
2324 {
2325 self.dcx().emit_fatal(err)
2329 } else {
2330 self.dcx().emit_err(err);
2331 false
2332 }
2333 }
2334 })
2335 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2336
2337 (
2338 hir::ParamName::Plain(self.lower_ident(param.ident)),
2339 hir::GenericParamKind::Const { ty, default },
2340 )
2341 }
2342 }
2343 }
2344
2345 fn lower_trait_ref(
2346 &mut self,
2347 modifiers: ast::TraitBoundModifiers,
2348 p: &TraitRef,
2349 itctx: ImplTraitContext,
2350 ) -> hir::TraitRef<'hir> {
2351 let path = match self.lower_qpath(
2352 p.ref_id,
2353 &None,
2354 &p.path,
2355 ParamMode::Explicit,
2356 AllowReturnTypeNotation::No,
2357 itctx,
2358 Some(modifiers),
2359 ) {
2360 hir::QPath::Resolved(None, path) => path,
2361 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2362 };
2363 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2364 }
2365
2366 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2366u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bound_generic_params")
}> =
::tracing::__macro_support::FieldName::new("bound_generic_params");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("modifiers")
}> =
::tracing::__macro_support::FieldName::new("modifiers");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rbp")
}> =
::tracing::__macro_support::FieldName::new("rbp");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_generic_params)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&modifiers)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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))]
2367 fn lower_poly_trait_ref(
2368 &mut self,
2369 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2370 rbp: RelaxedBoundPolicy<'_>,
2371 itctx: ImplTraitContext,
2372 ) -> hir::PolyTraitRef<'hir> {
2373 let bound_generic_params =
2374 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2375 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2376 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2377
2378 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2379 self.validate_relaxed_bound(trait_ref, *span, rbp);
2380 }
2381
2382 hir::PolyTraitRef {
2383 bound_generic_params,
2384 modifiers,
2385 trait_ref,
2386 span: self.lower_span(*span),
2387 }
2388 }
2389
2390 fn validate_relaxed_bound(
2391 &self,
2392 trait_ref: hir::TraitRef<'_>,
2393 span: Span,
2394 rbp: RelaxedBoundPolicy<'_>,
2395 ) {
2396 match rbp {
2406 RelaxedBoundPolicy::Allowed(dedup_map) => {
2407 let Some(trait_def_id) = trait_ref.trait_def_id() else { return };
2409 let tcx = self.tcx;
2410 let err = |s| {
2411 let name = tcx.item_name(trait_def_id);
2412 tcx.dcx()
2413 .struct_span_err(
2414 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[span, s]))vec![span, s],
2415 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("duplicate relaxed `{0}` bounds",
name))
})format!("duplicate relaxed `{name}` bounds"),
2416 )
2417 .with_code(E0203)
2418 .emit();
2419 };
2420 dedup_map.entry(trait_def_id).and_modify(|&mut s| err(s)).or_insert(span);
2421 return;
2422 }
2423 RelaxedBoundPolicy::Forbidden(reason) => {
2424 let gate = |context, subject| {
2425 let extended = self.tcx.features().more_maybe_bounds();
2426 let is_sized = trait_ref
2427 .trait_def_id()
2428 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, LangItem::Sized));
2429
2430 if extended && !is_sized {
2431 return;
2432 }
2433
2434 let prefix = if extended { "`Sized` " } else { "" };
2435 let mut diag = self.dcx().struct_span_err(
2436 span,
2437 ::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}"),
2438 );
2439 if is_sized {
2440 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!(
2441 "{subject} are not implicitly bounded by `Sized`, \
2442 so there is nothing to relax"
2443 ));
2444 }
2445 diag.emit();
2446 };
2447
2448 match reason {
2449 RelaxedBoundForbiddenReason::TraitObjectTy => {
2450 gate("trait object types", "trait object types");
2451 return;
2452 }
2453 RelaxedBoundForbiddenReason::SuperTrait => {
2454 gate("supertrait bounds", "traits");
2455 return;
2456 }
2457 RelaxedBoundForbiddenReason::TraitAlias => {
2458 gate("trait alias bounds", "trait aliases");
2459 return;
2460 }
2461 RelaxedBoundForbiddenReason::AssocTyBounds
2462 | RelaxedBoundForbiddenReason::WhereBound => {}
2463 };
2464 }
2465 }
2466
2467 self.dcx()
2468 .struct_span_err(span, "this relaxed bound is not permitted here")
2469 .with_note(
2470 "in this context, relaxed bounds are only allowed on \
2471 type parameters defined on the closest item",
2472 )
2473 .emit();
2474 }
2475
2476 fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
2477 hir::MutTy { ty: self.lower_ty_alloc(&mt.ty, itctx), mutbl: mt.mutbl }
2478 }
2479
2480 {}
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_param_bounds",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2480u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bounds")
}> =
::tracing::__macro_support::FieldName::new("bounds");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("rbp")
}> =
::tracing::__macro_support::FieldName::new("rbp");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("itctx")
}> =
::tracing::__macro_support::FieldName::new("itctx");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bounds)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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::GenericBounds<'hir> =
loop {};
return __tracing_attr_fake_return;
}
{
self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds,
rbp, itctx))
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:2480",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2480u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2481 fn lower_param_bounds(
2482 &mut self,
2483 bounds: &[GenericBound],
2484 rbp: RelaxedBoundPolicy<'_>,
2485 itctx: ImplTraitContext,
2486 ) -> hir::GenericBounds<'hir> {
2487 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2488 }
2489
2490 fn lower_param_bounds_mut(
2491 &mut self,
2492 bounds: &[GenericBound],
2493 mut rbp: RelaxedBoundPolicy<'_>,
2494 itctx: ImplTraitContext,
2495 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2496 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp.reborrow(), itctx))
2497 }
2498
2499 {}
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_universal_param_and_bounds",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2499u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("node_id")
}> =
::tracing::__macro_support::FieldName::new("node_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ident")
}> =
::tracing::__macro_support::FieldName::new("ident");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bounds")
}> =
::tracing::__macro_support::FieldName::new("bounds");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bounds)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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>, Option<hir::WherePredicate<'hir>>,
hir::TyKind<'hir>) = loop {};
return __tracing_attr_fake_return;
}
{
let def_id = self.local_def_id(node_id);
let span = self.lower_span(span);
let param =
hir::GenericParam {
hir_id: self.lower_node_id(node_id),
def_id,
name: ParamName::Plain(self.lower_ident(ident)),
pure_wrt_drop: false,
span,
kind: hir::GenericParamKind::Type {
default: None,
synthetic: true,
},
colon_span: None,
source: hir::GenericParamSource::Generics,
};
let preds =
self.lower_generic_bound_predicate(ident, node_id,
&GenericParamKind::Type { default: None }, bounds, None,
span, RelaxedBoundPolicy::Allowed(&mut Default::default()),
ImplTraitContext::Universal,
hir::PredicateOrigin::ImplTrait);
let hir_id = self.next_id();
let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
let ty =
hir::TyKind::Path(hir::QPath::Resolved(None,
self.arena.alloc(hir::Path {
span,
res,
segments: self.arena.alloc_from_iter([hir::PathSegment::new(self.lower_ident(ident),
hir_id, res)]),
})));
(param, preds, ty)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:2499",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2499u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2500 fn lower_universal_param_and_bounds(
2501 &mut self,
2502 node_id: NodeId,
2503 span: Span,
2504 ident: Ident,
2505 bounds: &[GenericBound],
2506 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2507 let def_id = self.local_def_id(node_id);
2509 let span = self.lower_span(span);
2510
2511 let param = hir::GenericParam {
2513 hir_id: self.lower_node_id(node_id),
2514 def_id,
2515 name: ParamName::Plain(self.lower_ident(ident)),
2516 pure_wrt_drop: false,
2517 span,
2518 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2519 colon_span: None,
2520 source: hir::GenericParamSource::Generics,
2521 };
2522
2523 let preds = self.lower_generic_bound_predicate(
2524 ident,
2525 node_id,
2526 &GenericParamKind::Type { default: None },
2527 bounds,
2528 None,
2529 span,
2530 RelaxedBoundPolicy::Allowed(&mut Default::default()),
2531 ImplTraitContext::Universal,
2532 hir::PredicateOrigin::ImplTrait,
2533 );
2534
2535 let hir_id = self.next_id();
2536 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2537 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2538 None,
2539 self.arena.alloc(hir::Path {
2540 span,
2541 res,
2542 segments:
2543 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2544 }),
2545 ));
2546
2547 (param, preds, ty)
2548 }
2549
2550 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2553 let block = self.lower_block(b, false);
2554 self.expr_block(block)
2555 }
2556
2557 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2558 match c.value.peel_parens().kind {
2565 ExprKind::Underscore => {
2566 let ct_kind = hir::ConstArgKind::Infer(());
2567 self.arena.alloc(hir::ConstArg {
2568 hir_id: self.lower_node_id(c.id),
2569 kind: ct_kind,
2570 span: self.lower_span(c.value.span),
2571 })
2572 }
2573 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2574 }
2575 }
2576
2577 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2580u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("qself")
}> =
::tracing::__macro_support::FieldName::new("qself");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("res")
}> =
::tracing::__macro_support::FieldName::new("res");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&qself)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::ConstArg<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let context = self.ambient_direct_const_arg_context();
if self.can_lower_path_to_const_arg_direct(qself, path, span,
Some(res), context).is_ok() {
let span = self.lower_span(span);
self.lower_path_to_const_arg_direct(id, None, qself, path,
span)
} 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,
kind: ExprKind::Path(qself.clone(), 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::ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(ct),
span: self.lower_span(span),
}
}
}
}
}#[instrument(level = "debug", skip(self))]
2581 fn lower_const_path_to_const_arg(
2582 &mut self,
2583 qself: &Option<Box<QSelf>>,
2584 path: &Path,
2585 res: Res<NodeId>,
2586 id: NodeId,
2587 span: Span,
2588 ) -> hir::ConstArg<'hir> {
2589 let context = self.ambient_direct_const_arg_context();
2590 if self.can_lower_path_to_const_arg_direct(qself, path, span, Some(res), context).is_ok() {
2591 let span = self.lower_span(span);
2592 self.lower_path_to_const_arg_direct(id, None, qself, path, span)
2593 } else {
2594 let node_id = self.next_node_id();
2596 let span = self.lower_span(span);
2597
2598 let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2603 let hir_id = self.lower_node_id(node_id);
2604
2605 let path_expr = Expr {
2606 id,
2607 kind: ExprKind::Path(qself.clone(), path.clone()),
2608 span,
2609 attrs: AttrVec::new(),
2610 tokens: None,
2611 };
2612
2613 let ct = self.with_new_scopes(span, |this| {
2614 self.arena.alloc(hir::AnonConst {
2615 def_id,
2616 hir_id,
2617 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2618 span,
2619 })
2620 });
2621 hir::ConstArg {
2622 hir_id: self.next_id(),
2623 kind: hir::ConstArgKind::Anon(ct),
2624 span: self.lower_span(span),
2625 }
2626 }
2627 }
2628
2629 fn lower_const_item_rhs(
2630 &mut self,
2631 body: &Option<Box<Expr>>,
2632 span: Span,
2633 ) -> hir::ConstItemRhs<'hir> {
2634 let is_direct = |body| {
2635 if self.tcx.features().gca_macroless_items() {
2636 self.can_lower_expr_to_const_arg_direct(
2637 body,
2638 DirectConstArgContext::MacrolessMinGenericConstArgs,
2639 )
2640 .is_ok()
2641 } else {
2642 #[allow(non_exhaustive_omitted_patterns)] match body {
Expr { kind: ExprKind::GcaMacro(_), .. } => true,
_ => false,
}matches!(body, Expr { kind: ExprKind::GcaMacro(_), .. })
2646 }
2647 };
2648 if self.tcx.features().gca_min_const_items()
2649 && let Some(body) = body
2650 && is_direct(body)
2651 {
2652 hir::ConstItemRhs::Direct(
2653 self.arena.alloc(self.lower_expr_to_const_arg_direct(&body, None)),
2654 )
2655 } else {
2656 hir::ConstItemRhs::Body(self.lower_const_body(span, body.as_deref()))
2657 }
2658 }
2659
2660 fn ambient_direct_const_arg_context(&self) -> DirectConstArgContext {
2661 if self.tcx.features().gca_macroless_args() {
2662 DirectConstArgContext::MacrolessMinGenericConstArgs
2663 } else if self.tcx.features().gca_min_const_items() {
2664 DirectConstArgContext::MinGenericConstArgs
2665 } else {
2666 DirectConstArgContext::Stable
2667 }
2668 }
2669
2670 fn can_lower_path_to_const_arg_direct(
2671 &self,
2672 qself: &Option<Box<QSelf>>,
2673 path: &Path,
2674 span: Span,
2675 res: Option<Res<NodeId>>,
2676 context: DirectConstArgContext,
2677 ) -> Result<(), UnrepresentableConstArgError> {
2678 if let DirectConstArgContext::MacrolessMinGenericConstArgs = context {
2679 Ok(())
2680 } else if qself.is_none()
2681 && path.is_single_argless_ident()
2682 && #[allow(non_exhaustive_omitted_patterns)] match res {
Some(Res::Def(DefKind::ConstParam, _)) => true,
_ => false,
}matches!(res, Some(Res::Def(DefKind::ConstParam, _)))
2683 {
2684 Ok(())
2685 } else {
2686 Err(UnrepresentableConstArgError { span, will_create_def_ids: false })
2687 }
2688 }
2689
2690 {}
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("can_lower_expr_to_const_arg_direct",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2690u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("context")
}> =
::tracing::__macro_support::FieldName::new("context");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&context)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Result<(), UnrepresentableConstArgError> = loop {};
return __tracing_attr_fake_return;
}
{
use DirectConstArgContext::*;
match (&expr.kind, context) {
(ExprKind::Call(Expr { kind: ExprKind::Path(_, _), .. },
args), MacrolessMinGenericConstArgs) => {
for arg in args {
self.can_lower_expr_to_const_arg_direct(arg, context)?;
}
Ok(())
}
(ExprKind::Tup(exprs), MacrolessMinGenericConstArgs) => {
for expr in exprs {
self.can_lower_expr_to_const_arg_direct(expr, context)?;
}
Ok(())
}
(ExprKind::Path(qself, path), _) => {
let res =
self.get_partial_res(expr.id).and_then(|partial_res|
partial_res.full_res());
self.can_lower_path_to_const_arg_direct(qself, path,
expr.span, res, context)
}
(ExprKind::Struct(se), MacrolessMinGenericConstArgs) => {
for f in &se.fields {
self.can_lower_expr_to_const_arg_direct(&f.expr, context)?;
}
Ok(())
}
(ExprKind::Array(elements), MacrolessMinGenericConstArgs) =>
{
for element in elements {
self.can_lower_expr_to_const_arg_direct(element, context)?;
}
Ok(())
}
(ExprKind::Underscore, MacrolessMinGenericConstArgs) =>
Ok(()),
(ExprKind::Paren(expr), MacrolessMinGenericConstArgs) => {
self.can_lower_expr_to_const_arg_direct(expr, context)
}
(ExprKind::Block(block, _), MacrolessMinGenericConstArgs) if
let [stmt] = block.stmts.as_slice() &&
let StmtKind::Expr(expr) = &stmt.kind => {
self.can_lower_expr_to_const_arg_direct(expr, context)
}
(ExprKind::Lit(_), MacrolessMinGenericConstArgs) => Ok(()),
(ExprKind::Unary(UnOp::Neg, inner_expr),
MacrolessMinGenericConstArgs) if
let ExprKind::Lit(_) = &inner_expr.kind => {
Ok(())
}
(ExprKind::ConstBlock(_), MacrolessMinGenericConstArgs) =>
Ok(()),
(ExprKind::GcaMacro(_),
MacrolessMinGenericConstArgs | MinGenericConstArgs) => {
Ok(())
}
_ => Err(UnrepresentableConstArgError::new(expr)),
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:2690",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2690u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2691 fn can_lower_expr_to_const_arg_direct(
2692 &self,
2693 expr: &Expr,
2694 context: DirectConstArgContext,
2695 ) -> Result<(), UnrepresentableConstArgError> {
2696 use DirectConstArgContext::*;
2697 match (&expr.kind, context) {
2699 (
2700 ExprKind::Call(Expr { kind: ExprKind::Path(_, _), .. }, args),
2701 MacrolessMinGenericConstArgs,
2702 ) => {
2703 for arg in args {
2704 self.can_lower_expr_to_const_arg_direct(arg, context)?;
2705 }
2706 Ok(())
2707 }
2708 (ExprKind::Tup(exprs), MacrolessMinGenericConstArgs) => {
2709 for expr in exprs {
2710 self.can_lower_expr_to_const_arg_direct(expr, context)?;
2711 }
2712 Ok(())
2713 }
2714 (ExprKind::Path(qself, path), _) => {
2715 let res =
2716 self.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2717 self.can_lower_path_to_const_arg_direct(qself, path, expr.span, res, context)
2718 }
2719 (ExprKind::Struct(se), MacrolessMinGenericConstArgs) => {
2720 for f in &se.fields {
2721 self.can_lower_expr_to_const_arg_direct(&f.expr, context)?;
2722 }
2723 Ok(())
2724 }
2725 (ExprKind::Array(elements), MacrolessMinGenericConstArgs) => {
2726 for element in elements {
2727 self.can_lower_expr_to_const_arg_direct(element, context)?;
2728 }
2729 Ok(())
2730 }
2731 (ExprKind::Underscore, MacrolessMinGenericConstArgs) => Ok(()),
2732 (ExprKind::Paren(expr), MacrolessMinGenericConstArgs) => {
2733 self.can_lower_expr_to_const_arg_direct(expr, context)
2734 }
2735 (ExprKind::Block(block, _), MacrolessMinGenericConstArgs)
2736 if let [stmt] = block.stmts.as_slice()
2737 && let StmtKind::Expr(expr) = &stmt.kind =>
2738 {
2739 self.can_lower_expr_to_const_arg_direct(expr, context)
2740 }
2741 (ExprKind::Lit(_), MacrolessMinGenericConstArgs) => Ok(()),
2742 (ExprKind::Unary(UnOp::Neg, inner_expr), MacrolessMinGenericConstArgs)
2743 if let ExprKind::Lit(_) = &inner_expr.kind =>
2744 {
2745 Ok(())
2746 }
2747 (ExprKind::ConstBlock(_), MacrolessMinGenericConstArgs) => Ok(()),
2748 (ExprKind::GcaMacro(_), MacrolessMinGenericConstArgs | MinGenericConstArgs) => {
2749 Ok(())
2752 }
2753 _ => Err(UnrepresentableConstArgError::new(expr)),
2754 }
2755 }
2756
2757 fn lower_path_to_const_arg_direct(
2760 &mut self,
2761 id: NodeId,
2762 id_override: Option<NodeId>,
2763 qself: &Option<Box<QSelf>>,
2764 path: &Path,
2765 span: Span,
2766 ) -> hir::ConstArg<'hir> {
2767 let qpath = self.lower_qpath(
2768 id,
2769 qself,
2770 path,
2771 ParamMode::Explicit,
2772 AllowReturnTypeNotation::No,
2773 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2775 None,
2776 );
2777
2778 let node_id = id_override.unwrap_or(id);
2779 ConstArg { hir_id: self.lower_node_id(node_id), kind: hir::ConstArgKind::Path(qpath), span }
2780 }
2781
2782 {}
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_expr_to_const_arg_direct",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2784u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id_override")
}> =
::tracing::__macro_support::FieldName::new("id_override");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id_override)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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 span = self.lower_span(expr.span);
let node_id = id_override.unwrap_or(expr.id);
match &expr.kind {
ExprKind::Call(func, args) if
let ExprKind::Path(qself, path) = &func.kind => {
let qpath =
self.lower_qpath(func.id, qself, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
let lowered_args =
self.arena.alloc_from_iter(args.iter().map(|arg|
{
let const_arg =
self.lower_expr_to_const_arg_direct(arg, None);
&*self.arena.alloc(const_arg)
}));
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
span,
}
}
ExprKind::Tup(exprs) => {
let exprs =
self.arena.alloc_from_iter(exprs.iter().map(|expr|
{
let expr = self.lower_expr_to_const_arg_direct(expr, None);
&*self.arena.alloc(expr)
}));
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::Tup(exprs),
span,
}
}
ExprKind::Path(qself, path) => {
self.lower_path_to_const_arg_direct(expr.id, id_override,
qself, path, span)
}
ExprKind::Struct(se) => {
let path =
self.lower_qpath(expr.id, &se.qself, &se.path,
ParamMode::Explicit, AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
let fields =
self.arena.alloc_from_iter(se.fields.iter().map(|f|
{
let hir_id = self.lower_node_id(f.id);
self.lower_attrs(hir_id, &f.attrs, f.span,
Target::ExprField);
let expr =
self.lower_expr_to_const_arg_direct(&f.expr, None);
&*self.arena.alloc(hir::ConstArgExprField {
hir_id,
field: self.lower_ident(f.ident),
expr: self.arena.alloc(expr),
span: self.lower_span(f.span),
})
}));
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::Struct(path, fields),
span,
}
}
ExprKind::Array(elements) => {
let lowered_elems =
self.arena.alloc_from_iter(elements.iter().map(|element|
{
let const_arg =
self.lower_expr_to_const_arg_direct(element, None);
&*self.arena.alloc(const_arg)
}));
let array_expr =
self.arena.alloc(hir::ConstArgArrayExpr {
span: self.lower_span(expr.span),
elems: lowered_elems,
});
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::Array(array_expr),
span,
}
}
ExprKind::Underscore =>
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::Infer(()),
span,
},
ExprKind::Paren(expr) =>
self.lower_expr_to_const_arg_direct(expr, id_override),
ExprKind::Block(block, _) if
let [stmt] = block.stmts.as_slice() &&
let StmtKind::Expr(expr) = &stmt.kind => {
self.lower_expr_to_const_arg_direct(expr, id_override)
}
ExprKind::Lit(literal) => {
let span = self.lower_span(expr.span);
let literal = self.lower_lit(literal, span);
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::Literal {
lit: literal.node,
negated: false,
},
span,
}
}
ExprKind::Unary(UnOp::Neg, inner_expr) if
let ExprKind::Lit(literal) = &inner_expr.kind => {
let span = self.lower_span(expr.span);
let literal = self.lower_lit(literal, span);
let kind =
if !#[allow(non_exhaustive_omitted_patterns)] match literal.node
{
LitKind::Int(..) => true,
_ => false,
} {
let err =
self.dcx().span_err(expr.span,
"negated literal must be an integer");
hir::ConstArgKind::Error(err)
} else {
hir::ConstArgKind::Literal {
lit: literal.node,
negated: true,
}
};
ConstArg { hir_id: self.lower_node_id(node_id), kind, span }
}
ExprKind::ConstBlock(anon_const) => {
let def_id = self.local_def_id(anon_const.id);
{
match (&DefKind::AnonConst, &self.tcx.def_kind(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);
}
}
}
};
let lowered_anon =
self.lower_anon_const_to_anon_const(anon_const, span);
ConstArg {
hir_id: self.lower_node_id(node_id),
kind: hir::ConstArgKind::Anon(lowered_anon),
span,
}
}
ExprKind::GcaMacro(expr) => {
match self.can_lower_expr_to_const_arg_direct(expr,
DirectConstArgContext::MacrolessMinGenericConstArgs) {
Ok(()) =>
self.lower_expr_to_const_arg_direct(expr, id_override),
Err(err) => err.emit(self),
}
}
_ => {
::rustc_span::macros::bug_impl(Some(expr.span),
format_args!("lower_expr_to_const_arg_direct encountered an unlowerable expression, either can_lower_expr_to_const_arg_direct returned Ok() on something it shouldn\'t have, or you forgot to check can_lower_expr_to_const_arg_direct first"),
Location::caller());
}
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:2784",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2784u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2785 fn lower_expr_to_const_arg_direct(
2786 &mut self,
2787 expr: &Expr,
2788 id_override: Option<NodeId>,
2789 ) -> hir::ConstArg<'hir> {
2790 let span = self.lower_span(expr.span);
2791 let node_id = id_override.unwrap_or(expr.id);
2792 match &expr.kind {
2793 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2794 let qpath = self.lower_qpath(
2795 func.id,
2796 qself,
2797 path,
2798 ParamMode::Explicit,
2799 AllowReturnTypeNotation::No,
2800 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2801 None,
2802 );
2803
2804 let lowered_args = self.arena.alloc_from_iter(args.iter().map(|arg| {
2805 let const_arg = self.lower_expr_to_const_arg_direct(arg, None);
2806 &*self.arena.alloc(const_arg)
2807 }));
2808
2809 ConstArg {
2810 hir_id: self.lower_node_id(node_id),
2811 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2812 span,
2813 }
2814 }
2815 ExprKind::Tup(exprs) => {
2816 let exprs = self.arena.alloc_from_iter(exprs.iter().map(|expr| {
2817 let expr = self.lower_expr_to_const_arg_direct(expr, None);
2818 &*self.arena.alloc(expr)
2819 }));
2820
2821 ConstArg {
2822 hir_id: self.lower_node_id(node_id),
2823 kind: hir::ConstArgKind::Tup(exprs),
2824 span,
2825 }
2826 }
2827 ExprKind::Path(qself, path) => {
2828 self.lower_path_to_const_arg_direct(expr.id, id_override, qself, path, span)
2829 }
2830 ExprKind::Struct(se) => {
2831 let path = self.lower_qpath(
2832 expr.id,
2833 &se.qself,
2834 &se.path,
2835 ParamMode::Explicit,
2839 AllowReturnTypeNotation::No,
2840 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2841 None,
2842 );
2843
2844 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2845 let hir_id = self.lower_node_id(f.id);
2846 self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField);
2850 let expr = self.lower_expr_to_const_arg_direct(&f.expr, None);
2851
2852 &*self.arena.alloc(hir::ConstArgExprField {
2853 hir_id,
2854 field: self.lower_ident(f.ident),
2855 expr: self.arena.alloc(expr),
2856 span: self.lower_span(f.span),
2857 })
2858 }));
2859
2860 ConstArg {
2861 hir_id: self.lower_node_id(node_id),
2862 kind: hir::ConstArgKind::Struct(path, fields),
2863 span,
2864 }
2865 }
2866 ExprKind::Array(elements) => {
2867 let lowered_elems = self.arena.alloc_from_iter(elements.iter().map(|element| {
2868 let const_arg = self.lower_expr_to_const_arg_direct(element, None);
2869 &*self.arena.alloc(const_arg)
2870 }));
2871 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
2872 span: self.lower_span(expr.span),
2873 elems: lowered_elems,
2874 });
2875
2876 ConstArg {
2877 hir_id: self.lower_node_id(node_id),
2878 kind: hir::ConstArgKind::Array(array_expr),
2879 span,
2880 }
2881 }
2882 ExprKind::Underscore => ConstArg {
2883 hir_id: self.lower_node_id(node_id),
2884 kind: hir::ConstArgKind::Infer(()),
2885 span,
2886 },
2887 ExprKind::Paren(expr) => self.lower_expr_to_const_arg_direct(expr, id_override),
2888 ExprKind::Block(block, _)
2889 if let [stmt] = block.stmts.as_slice()
2890 && let StmtKind::Expr(expr) = &stmt.kind =>
2891 {
2892 self.lower_expr_to_const_arg_direct(expr, id_override)
2893 }
2894 ExprKind::Lit(literal) => {
2895 let span = self.lower_span(expr.span);
2896 let literal = self.lower_lit(literal, span);
2897
2898 ConstArg {
2899 hir_id: self.lower_node_id(node_id),
2900 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
2901 span,
2902 }
2903 }
2904 ExprKind::Unary(UnOp::Neg, inner_expr)
2905 if let ExprKind::Lit(literal) = &inner_expr.kind =>
2906 {
2907 let span = self.lower_span(expr.span);
2908 let literal = self.lower_lit(literal, span);
2909
2910 let kind = if !matches!(literal.node, LitKind::Int(..)) {
2911 let err = self.dcx().span_err(expr.span, "negated literal must be an integer");
2912 hir::ConstArgKind::Error(err)
2913 } else {
2914 hir::ConstArgKind::Literal { lit: literal.node, negated: true }
2915 };
2916 ConstArg { hir_id: self.lower_node_id(node_id), kind, span }
2917 }
2918 ExprKind::ConstBlock(anon_const) => {
2919 let def_id = self.local_def_id(anon_const.id);
2922 assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
2923 let lowered_anon = self.lower_anon_const_to_anon_const(anon_const, span);
2924 ConstArg {
2925 hir_id: self.lower_node_id(node_id),
2926 kind: hir::ConstArgKind::Anon(lowered_anon),
2927 span,
2928 }
2929 }
2930 ExprKind::GcaMacro(expr) => {
2931 match self.can_lower_expr_to_const_arg_direct(
2937 expr,
2938 DirectConstArgContext::MacrolessMinGenericConstArgs,
2939 ) {
2940 Ok(()) => self.lower_expr_to_const_arg_direct(expr, id_override),
2941 Err(err) => err.emit(self),
2942 }
2943 }
2944 _ => {
2945 span_bug!(
2946 expr.span,
2947 "lower_expr_to_const_arg_direct encountered an unlowerable expression, either \
2948 can_lower_expr_to_const_arg_direct returned Ok() on something it shouldn't \
2949 have, or you forgot to check can_lower_expr_to_const_arg_direct first"
2950 );
2951 }
2952 }
2953 }
2954
2955 fn lower_anon_const_to_const_arg_and_alloc(
2958 &mut self,
2959 anon: &AnonConst,
2960 ) -> &'hir hir::ConstArg<'hir> {
2961 self.arena.alloc(self.lower_anon_const_to_const_arg(anon))
2962 }
2963
2964 {}
#[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("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2964u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("anon")
}> =
::tracing::__macro_support::FieldName::new("anon");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&anon)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::ConstArg<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let expr =
if self.tcx.features().gca_macroless_args() {
&anon.value
} else { anon.value.maybe_unwrap_block() };
let context = self.ambient_direct_const_arg_context();
if self.can_lower_expr_to_const_arg_direct(expr, context).is_ok()
{
return self.lower_expr_to_const_arg_direct(expr,
Some(anon.id));
}
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(anon.value.span),
}
}
}
}#[instrument(level = "debug", skip(self))]
2965 fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
2966 let expr = if self.tcx.features().gca_macroless_args() {
2969 &anon.value
2970 } else {
2971 anon.value.maybe_unwrap_block()
2972 };
2973
2974 let context = self.ambient_direct_const_arg_context();
2975 if self.can_lower_expr_to_const_arg_direct(expr, context).is_ok() {
2976 return self.lower_expr_to_const_arg_direct(expr, Some(anon.id));
2977 }
2978
2979 let lowered_anon = self.lower_anon_const_to_anon_const(anon, anon.value.span);
2980 ConstArg {
2981 hir_id: self.next_id(),
2982 kind: hir::ConstArgKind::Anon(lowered_anon),
2983 span: self.lower_span(anon.value.span),
2984 }
2985 }
2986
2987 fn lower_anon_const_to_anon_const(
2990 &mut self,
2991 c: &AnonConst,
2992 span: Span,
2993 ) -> &'hir hir::AnonConst {
2994 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
2995 let def_id = this.local_def_id(c.id);
2996 let hir_id = this.lower_node_id(c.id);
2997 hir::AnonConst {
2998 def_id,
2999 hir_id,
3000 body: this.lower_const_body(c.value.span, Some(&c.value)),
3001 span: this.lower_span(span),
3002 }
3003 }))
3004 }
3005
3006 fn lower_unsafe_source(&self, u: UnsafeSource) -> hir::UnsafeSource {
3007 match u {
3008 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
3009 UserProvided => hir::UnsafeSource::UserProvided,
3010 }
3011 }
3012
3013 fn lower_trait_bound_modifiers(
3014 &self,
3015 modifiers: TraitBoundModifiers,
3016 ) -> hir::TraitBoundModifiers {
3017 let constness = match modifiers.constness {
3018 BoundConstness::Never => BoundConstness::Never,
3019 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
3020 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
3021 };
3022 let polarity = match modifiers.polarity {
3023 BoundPolarity::Positive => BoundPolarity::Positive,
3024 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
3025 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
3026 };
3027 hir::TraitBoundModifiers { constness, polarity }
3028 }
3029
3030 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
3033 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
3034 }
3035
3036 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
3037 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
3038 }
3039
3040 fn stmt_let_pat(
3041 &mut self,
3042 attrs: Option<&'hir [rustc_attr_ir::Attribute]>,
3043 span: Span,
3044 init: Option<&'hir hir::Expr<'hir>>,
3045 pat: &'hir hir::Pat<'hir>,
3046 source: hir::LocalSource,
3047 ) -> hir::Stmt<'hir> {
3048 let hir_id = self.next_id();
3049 if let Some(a) = attrs {
3050 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
3051 self.curr_owner.attrs.insert(hir_id.local_id, a);
3052 }
3053 let local = hir::LetStmt {
3054 super_: None,
3055 hir_id,
3056 init,
3057 pat,
3058 els: None,
3059 source,
3060 span: self.lower_span(span),
3061 ty: None,
3062 };
3063 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
3064 }
3065
3066 fn stmt_super_let_pat(
3067 &mut self,
3068 span: Span,
3069 pat: &'hir hir::Pat<'hir>,
3070 init: Option<&'hir hir::Expr<'hir>>,
3071 ) -> hir::Stmt<'hir> {
3072 let hir_id = self.next_id();
3073 let span = self.lower_span(span);
3074 let local = hir::LetStmt {
3075 super_: Some(span),
3076 hir_id,
3077 init,
3078 pat,
3079 els: None,
3080 source: hir::LocalSource::Normal,
3081 span,
3082 ty: None,
3083 };
3084 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
3085 }
3086
3087 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
3088 self.block_all(expr.span, &[], Some(expr))
3089 }
3090
3091 fn block_all(
3092 &mut self,
3093 span: Span,
3094 stmts: &'hir [hir::Stmt<'hir>],
3095 expr: Option<&'hir hir::Expr<'hir>>,
3096 ) -> &'hir hir::Block<'hir> {
3097 let blk = hir::Block {
3098 stmts,
3099 expr,
3100 hir_id: self.next_id(),
3101 rules: hir::BlockCheckMode::DefaultBlock,
3102 span: self.lower_span(span),
3103 targeted_by_break: false,
3104 };
3105 self.arena.alloc(blk)
3106 }
3107
3108 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3109 let field = self.single_pat_field(span, pat);
3110 self.pat_lang_item_variant(span, LangItem::ControlFlowContinue, field)
3111 }
3112
3113 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3114 let field = self.single_pat_field(span, pat);
3115 self.pat_lang_item_variant(span, LangItem::ControlFlowBreak, field)
3116 }
3117
3118 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3119 let field = self.single_pat_field(span, pat);
3120 self.pat_lang_item_variant(span, LangItem::OptionSome, field)
3121 }
3122
3123 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
3124 self.pat_lang_item_variant(span, LangItem::OptionNone, &[])
3125 }
3126
3127 fn single_pat_field(
3128 &mut self,
3129 span: Span,
3130 pat: &'hir hir::Pat<'hir>,
3131 ) -> &'hir [hir::PatField<'hir>] {
3132 let field = hir::PatField {
3133 hir_id: self.next_id(),
3134 ident: Ident::new(sym::integer(0), self.lower_span(span)),
3135 is_shorthand: false,
3136 pat,
3137 span: self.lower_span(span),
3138 };
3139 self.arena.alloc_from_iter([field])arena_vec![self; field]
3140 }
3141
3142 fn pat_lang_item_variant(
3143 &mut self,
3144 span: Span,
3145 lang_item: LangItem,
3146 fields: &'hir [hir::PatField<'hir>],
3147 ) -> &'hir hir::Pat<'hir> {
3148 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
3149 self.pat(span, hir::PatKind::Struct(path, fields, None))
3150 }
3151
3152 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
3153 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
3154 }
3155
3156 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
3157 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
3158 }
3159
3160 fn pat_ident_binding_mode(
3161 &mut self,
3162 span: Span,
3163 ident: Ident,
3164 bm: hir::BindingMode,
3165 ) -> (&'hir hir::Pat<'hir>, HirId) {
3166 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
3167 (self.arena.alloc(pat), hir_id)
3168 }
3169
3170 fn pat_ident_binding_mode_mut(
3171 &mut self,
3172 span: Span,
3173 ident: Ident,
3174 bm: hir::BindingMode,
3175 ) -> (hir::Pat<'hir>, HirId) {
3176 let hir_id = self.next_id();
3177
3178 (
3179 hir::Pat {
3180 hir_id,
3181 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
3182 span: self.lower_span(span),
3183 default_binding_modes: true,
3184 },
3185 hir_id,
3186 )
3187 }
3188
3189 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
3190 self.arena.alloc(hir::Pat {
3191 hir_id: self.next_id(),
3192 kind,
3193 span: self.lower_span(span),
3194 default_binding_modes: true,
3195 })
3196 }
3197
3198 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
3199 hir::Pat {
3200 hir_id: self.next_id(),
3201 kind,
3202 span: self.lower_span(span),
3203 default_binding_modes: false,
3204 }
3205 }
3206
3207 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
3208 let kind = match qpath {
3209 hir::QPath::Resolved(None, path) => {
3210 match path.res {
3212 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
3213 let principal = hir::PolyTraitRef {
3214 bound_generic_params: &[],
3215 modifiers: hir::TraitBoundModifiers::NONE,
3216 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
3217 span: self.lower_span(span),
3218 };
3219
3220 hir_id = self.next_id();
3223 hir::TyKind::TraitObject(
3224 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
3225 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
3226 )
3227 }
3228 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
3229 }
3230 }
3231 _ => hir::TyKind::Path(qpath),
3232 };
3233
3234 hir::Ty { hir_id, kind, span: self.lower_span(span) }
3235 }
3236
3237 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
3242 let r = hir::Lifetime::new(
3243 self.next_id(),
3244 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
3245 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
3246 LifetimeSource::Other,
3247 LifetimeSyntax::Implicit,
3248 );
3249 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs:3249",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/fd8e211ae301c84a86d13cf52a6d3ce08c589e2e/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(3249u32),
::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("elided_dyn_bound: r={0:?}",
r) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("elided_dyn_bound: r={:?}", r);
3250 self.arena.alloc(r)
3251 }
3252}
3253
3254struct GenericArgsCtor<'hir> {
3256 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
3257 constraints: &'hir [hir::AssocItemConstraint<'hir>],
3258 parenthesized: hir::GenericArgsParentheses,
3259 span: Span,
3260}
3261
3262impl<'hir> GenericArgsCtor<'hir> {
3263 fn is_empty(&self) -> bool {
3264 self.args.is_empty()
3265 && self.constraints.is_empty()
3266 && self.parenthesized == hir::GenericArgsParentheses::No
3267 }
3268
3269 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
3270 let ga = hir::GenericArgs {
3271 args: this.arena.alloc_from_iter(self.args),
3272 constraints: self.constraints,
3273 parenthesized: self.parenthesized,
3274 span_ext: this.lower_span(self.span),
3275 };
3276 this.arena.alloc(ga)
3277 }
3278}
3279
3280#[derive(#[automatically_derived]
impl ::core::marker::Copy for DirectConstArgContext { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for DirectConstArgContext { }
#[automatically_derived]
impl ::core::clone::Clone for DirectConstArgContext {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for DirectConstArgContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
DirectConstArgContext::Stable => "Stable",
DirectConstArgContext::MinGenericConstArgs =>
"MinGenericConstArgs",
DirectConstArgContext::MacrolessMinGenericConstArgs =>
"MacrolessMinGenericConstArgs",
})
}
}Debug)]
3281enum DirectConstArgContext {
3282 Stable,
3285 MinGenericConstArgs,
3287 MacrolessMinGenericConstArgs,
3293}
3294
3295#[derive(#[automatically_derived]
impl ::core::fmt::Debug for UnrepresentableConstArgError {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"UnrepresentableConstArgError", "span", &self.span,
"will_create_def_ids", &&self.will_create_def_ids)
}
}Debug)]
3296struct UnrepresentableConstArgError {
3297 span: Span,
3298 will_create_def_ids: bool,
3299}
3300
3301impl UnrepresentableConstArgError {
3302 fn new(expr: &Expr) -> Self {
3303 Self {
3304 span: expr.span,
3305 will_create_def_ids: expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break(),
3306 }
3307 }
3308
3309 fn emit<'hir>(self, lowering_context: &mut LoweringContext<'_, 'hir>) -> ConstArg<'hir> {
3310 let msg = "complex const arguments must be placed inside of a `const` block";
3311 let e = if self.will_create_def_ids {
3312 lowering_context.dcx().span_fatal(self.span, msg)
3316 } else {
3317 lowering_context.dcx().span_err(self.span, msg)
3318 };
3319
3320 ConstArg {
3321 hir_id: lowering_context.next_id(),
3322 kind: hir::ConstArgKind::Error(e),
3323 span: self.span,
3324 }
3325 }
3326}