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::AstTarget;
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::{CtorKind, 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 can_relower",
&self.node_id_to_local_id, &&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 const_defs: Vec<hir::GenericParam<'hir>>,
186}
187
188impl<'a, 'hir> PerOwnerLoweringState<'a, 'hir> {
189 fn new(resolver: &'a ResolverAstLowering<'hir>, owner: NodeId) -> Self {
190 let owner = &resolver.owners[&owner];
191
192 let disambiguator = resolver
193 .disambiguators
194 .get(&owner.def_id)
195 .map(|s| s.steal())
196 .unwrap_or_else(|| PerParentDisambiguatorState::new(owner.def_id));
197
198 PerOwnerLoweringState {
199 owner,
200 disambiguator,
201 item_local_id_counter: hir::ItemLocalId::new(1),
204 ident_and_label_to_local_id: Default::default(),
205 #[cfg(debug_assertions)]
206 relowering_checker: Default::default(),
207 attrs: SortedMap::default(),
208 bodies: Vec::new(),
209 define_opaque: None,
210 trait_map: Default::default(),
211 delayed_lints: Vec::new(),
212 children: LocalDefIdMap::default(),
213 impl_trait_defs: Vec::new(),
214 impl_trait_bounds: Vec::new(),
215 const_defs: Vec::new(),
216 }
217 }
218
219 fn owner_id(&self) -> hir::OwnerId {
220 hir::OwnerId { def_id: self.owner.def_id }
221 }
222
223 fn into_owner_info(
224 self,
225 tcx: TyCtxt<'hir>,
226 node: hir::OwnerNode<'hir>,
227 ) -> &'hir hir::OwnerInfo<'hir> {
228 {
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());
229 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());
230 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());
231 if !self.const_defs.is_empty() {
::core::panicking::panic("assertion failed: self.const_defs.is_empty()")
};assert!(self.const_defs.is_empty());
232
233 let attrs = self.attrs;
234 let mut bodies = self.bodies;
235 let define_opaque = self.define_opaque;
236 let trait_map = self.trait_map;
237 let delayed_lints = Steal::new(self.delayed_lints.into_boxed_slice());
238 let children = self.children;
239
240 #[cfg(debug_assertions)]
241 for (id, attrs) in attrs.iter() {
242 if attrs.is_empty() {
244 {
::core::panicking::panic_fmt(format_args!("Stored empty attributes for {0:?}",
id));
};panic!("Stored empty attributes for {:?}", id);
245 }
246 }
247
248 bodies.sort_by_key(|(k, _)| *k);
249 let bodies = SortedMap::from_presorted_elements(bodies);
250
251 let rustc_middle::hir::Hashes { bodies_hash, attrs_hash } =
253 tcx.hash_owner_nodes(node, &bodies, &attrs, define_opaque);
254 let num_nodes = self.item_local_id_counter.as_usize();
255 let (nodes, parenting) = index::index_hir(tcx, node, &bodies, num_nodes);
256 let nodes = hir::OwnerNodes { opt_hash: bodies_hash, nodes, bodies };
257 let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
258
259 let opt_hash = tcx.needs_owner_info_hash().then(|| {
260 tcx.with_stable_hashing_context(|mut hcx| {
261 let mut stable_hasher = StableHasher::new();
262 bodies_hash.unwrap().stable_hash(&mut hcx, &mut stable_hasher);
263 attrs_hash.unwrap().stable_hash(&mut hcx, &mut stable_hasher);
264 parenting.stable_hash(&mut hcx, &mut stable_hasher);
266 trait_map.stable_hash(&mut hcx, &mut stable_hasher);
267 children.stable_hash(&mut hcx, &mut stable_hasher);
268 stable_hasher.finish()
269 })
270 });
271
272 tcx.hir_arena.alloc(hir::OwnerInfo {
273 opt_hash,
274 nodes,
275 parenting,
276 attrs,
277 trait_map,
278 delayed_lints,
279 children,
280 })
281 }
282}
283
284struct LoweringContext<'a, 'hir> {
285 tcx: TyCtxt<'hir>,
286 resolver: &'a ResolverAstLowering<'hir>,
287
288 curr_owner: PerOwnerLoweringState<'a, 'hir>,
289
290 arena: &'hir hir::Arena<'hir>,
292
293 contract_ensures: Option<(Span, Ident, HirId)>,
294
295 coroutine_kind: Option<hir::CoroutineKind>,
296
297 task_context: Option<HirId>,
300
301 current_item_span: Option<Span>,
304
305 try_block_scope: TryBlockScope,
306 loop_scope: Option<HirId>,
307 is_in_loop_condition: bool,
308 is_in_dyn_type: bool,
309
310 next_node_id: NodeId,
314 node_id_to_def_id: NodeMap<LocalDefId>,
316 partial_res_overrides: NodeMap<NodeId>,
320
321 move_expr_bindings: Vec<Option<expr::MoveExprState<'hir>>>,
325
326 lowering_move_expr_initializer: bool,
328
329 attribute_parser: AttributeParser<'hir>,
330}
331
332macro_rules! allow {
333 ($($name:ident: $list:expr;)*) => {
334 $( static $name: LazyLock<Arc<[Symbol]>> = LazyLock::new(|| $list.into()); )*
335 }
336}
337
338static 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! {
339 ALLOW_CONTRACTS: [sym::contracts_internals];
340 ALLOW_TRY_TRAIT: [sym::try_trait_v2, sym::try_trait_v2_residual, sym::yeet_desugar_details];
341 ALLOW_PATTERN_TYPE: [sym::pattern_types, sym::pattern_type_range_trait];
342 ALLOW_GEN_FUTURE: [sym::gen_future];
343 ALLOW_GEN_FUTURE_WITH_ASYNC_FN_TRACK_CALLER: [sym::gen_future, sym::closure_track_caller];
344 ALLOW_FOR_AWAIT: [sym::async_gen_internals, sym::async_iterator];
345 ALLOW_ASYNC_FN_TRAITS: [sym::async_fn_traits];
346 ALLOW_ASYNC_GEN: [sym::async_gen_internals];
347 ALLOW_ASYNC_ITERATOR: [sym::gen_future, sym::async_iterator];
350}
351
352impl<'a, 'hir> LoweringContext<'a, 'hir> {
353 fn new(tcx: TyCtxt<'hir>, resolver: &'a ResolverAstLowering<'hir>, owner: NodeId) -> Self {
354 Self {
355 tcx,
356 resolver,
357 curr_owner: PerOwnerLoweringState::new(resolver, owner),
358 arena: tcx.hir_arena,
359
360 contract_ensures: None,
361
362 next_node_id: resolver.next_node_id,
363 node_id_to_def_id: NodeMap::default(),
364 partial_res_overrides: NodeMap::default(),
365
366 try_block_scope: TryBlockScope::Function,
368 loop_scope: None,
369 is_in_loop_condition: false,
370 is_in_dyn_type: false,
371 coroutine_kind: None,
372 task_context: None,
373 current_item_span: None,
374
375 move_expr_bindings: Vec::new(),
376 lowering_move_expr_initializer: false,
377 attribute_parser: AttributeParser::new(
378 tcx.sess,
379 tcx.features(),
380 tcx.registered_attr_tools(()),
381 ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
382 ),
383 }
384 }
385
386 pub(crate) fn dcx(&self) -> DiagCtxtHandle<'hir> {
387 self.tcx.dcx()
388 }
389
390 fn allow_gen_future(&self) -> &Arc<[Symbol]> {
391 if self.tcx.features().async_fn_track_caller() {
392 &ALLOW_GEN_FUTURE_WITH_ASYNC_FN_TRACK_CALLER
393 } else {
394 &ALLOW_GEN_FUTURE
395 }
396 }
397}
398
399struct SpanLowerer {
400 is_incremental: bool,
401 def_id: LocalDefId,
402}
403
404impl SpanLowerer {
405 fn lower(&self, span: Span) -> Span {
406 if self.is_incremental {
407 span.with_parent(Some(self.def_id))
408 } else {
409 span
411 }
412 }
413}
414
415trait 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::Tool(..) |
::rustc_attr_ir::Attribute::DeriveHelper(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.map(|fn_indexes|
fn_indexes.iter().map(|(num, _)| *num).collect())
}
}#[extension(trait ResolverAstLoweringExt<'tcx>)]
416impl<'tcx> ResolverAstLowering<'tcx> {
417 fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'tcx>) -> Option<Vec<usize>> {
418 let ExprKind::Path(None, path) = &expr.kind else {
419 return None;
420 };
421
422 if path.segments.last().unwrap().args.is_some() {
425 return None;
426 }
427
428 let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
432
433 if def_id.is_local() {
437 return None;
438 }
439
440 find_attr!(
442 tcx, def_id,
443 RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes
444 )
445 .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
446 }
447}
448
449#[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_struct_field1_finish(f,
"Allowed", &__self_0),
Self::Forbidden(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Forbidden", &__self_0),
}
}
}Debug)]
454enum RelaxedBoundPolicy<'a> {
455 Allowed(&'a mut FxIndexMap<DefId, Span>),
457 Forbidden(RelaxedBoundForbiddenReason),
458}
459impl RelaxedBoundPolicy<'_> {
460 fn reborrow(&mut self) -> RelaxedBoundPolicy<'_> {
461 match self {
462 RelaxedBoundPolicy::Allowed(m) => RelaxedBoundPolicy::Allowed(m),
463 RelaxedBoundPolicy::Forbidden(reason) => RelaxedBoundPolicy::Forbidden(*reason),
464 }
465 }
466}
467
468#[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::debug_c_like_enum_write_str(f,
"TraitObjectTy SuperTrait TraitAlias AssocTyBounds WhereBound",
match self {
RelaxedBoundForbiddenReason::TraitObjectTy => 0usize,
RelaxedBoundForbiddenReason::SuperTrait => 14usize,
RelaxedBoundForbiddenReason::TraitAlias => 25usize,
RelaxedBoundForbiddenReason::AssocTyBounds => 36usize,
RelaxedBoundForbiddenReason::WhereBound => 50usize,
})
}
}Debug)]
469enum RelaxedBoundForbiddenReason {
470 TraitObjectTy,
471 SuperTrait,
472 TraitAlias,
473 AssocTyBounds,
474 WhereBound,
477}
478
479#[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_struct_field2_finish(f,
"FeatureGated", __self_0, &__self_1),
Self::Disallowed(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Disallowed", &__self_0),
Self::AlreadyErrored(__self_0) =>
::core::fmt::Formatter::debug_struct_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)]
482enum ImplTraitContext {
483 Universal,
489
490 OpaqueTy { origin: hir::OpaqueTyOrigin<LocalDefId> },
495
496 InBinding,
501
502 FeatureGated(ImplTraitPosition, Symbol),
504 Disallowed(ImplTraitPosition),
506
507 AlreadyErrored(ErrorGuaranteed),
509}
510
511#[derive(#[automatically_derived]impl ::core::fmt::Debug for ImplTraitPosition {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"Path Variable Trait Bound Generic ExternFnParam ClosureParam PointerParam FnTraitParam ExternFnReturn ClosureReturn PointerReturn FnTraitReturn GenericDefault ConstTy StaticTy AssocTy FieldTy Cast ImplSelf OffsetOf",
match self {
ImplTraitPosition::Path => 0usize,
ImplTraitPosition::Variable => 5usize,
ImplTraitPosition::Trait => 14usize,
ImplTraitPosition::Bound => 20usize,
ImplTraitPosition::Generic => 26usize,
ImplTraitPosition::ExternFnParam => 34usize,
ImplTraitPosition::ClosureParam => 48usize,
ImplTraitPosition::PointerParam => 61usize,
ImplTraitPosition::FnTraitParam => 74usize,
ImplTraitPosition::ExternFnReturn => 87usize,
ImplTraitPosition::ClosureReturn => 102usize,
ImplTraitPosition::PointerReturn => 116usize,
ImplTraitPosition::FnTraitReturn => 130usize,
ImplTraitPosition::GenericDefault => 144usize,
ImplTraitPosition::ConstTy => 159usize,
ImplTraitPosition::StaticTy => 167usize,
ImplTraitPosition::AssocTy => 176usize,
ImplTraitPosition::FieldTy => 184usize,
ImplTraitPosition::Cast => 192usize,
ImplTraitPosition::ImplSelf => 197usize,
ImplTraitPosition::OffsetOf => 206usize,
})
}
}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)]
513enum ImplTraitPosition {
514 Path,
515 Variable,
516 Trait,
517 Bound,
518 Generic,
519 ExternFnParam,
520 ClosureParam,
521 PointerParam,
522 FnTraitParam,
523 ExternFnReturn,
524 ClosureReturn,
525 PointerReturn,
526 FnTraitReturn,
527 GenericDefault,
528 ConstTy,
529 StaticTy,
530 AssocTy,
531 FieldTy,
532 Cast,
533 ImplSelf,
534 OffsetOf,
535}
536
537impl std::fmt::Display for ImplTraitPosition {
538 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
539 let name = match self {
540 ImplTraitPosition::Path => "paths",
541 ImplTraitPosition::Variable => "the type of variable bindings",
542 ImplTraitPosition::Trait => "traits",
543 ImplTraitPosition::Bound => "bounds",
544 ImplTraitPosition::Generic => "generics",
545 ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
546 ImplTraitPosition::ClosureParam => "closure parameters",
547 ImplTraitPosition::PointerParam => "`fn` pointer parameters",
548 ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
549 ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
550 ImplTraitPosition::ClosureReturn => "closure return types",
551 ImplTraitPosition::PointerReturn => "`fn` pointer return types",
552 ImplTraitPosition::FnTraitReturn => "the return type of `Fn` trait bounds",
553 ImplTraitPosition::GenericDefault => "generic parameter defaults",
554 ImplTraitPosition::ConstTy => "const types",
555 ImplTraitPosition::StaticTy => "static types",
556 ImplTraitPosition::AssocTy => "associated types",
557 ImplTraitPosition::FieldTy => "field types",
558 ImplTraitPosition::Cast => "cast expression types",
559 ImplTraitPosition::ImplSelf => "impl headers",
560 ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
561 };
562
563 f.write_fmt(format_args!("{0}", name))write!(f, "{name}")
564 }
565}
566
567#[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::debug_c_like_enum_write_str(f,
"Fn Inherent ExternFn Closure Pointer Trait Impl",
match self {
FnDeclKind::Fn => 0usize,
FnDeclKind::Inherent => 3usize,
FnDeclKind::ExternFn => 12usize,
FnDeclKind::Closure => 21usize,
FnDeclKind::Pointer => 29usize,
FnDeclKind::Trait => 37usize,
FnDeclKind::Impl => 43usize,
})
}
}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)]
568enum FnDeclKind {
569 Fn,
570 Inherent,
571 ExternFn,
572 Closure,
573 Pointer,
574 Trait,
575 Impl,
576}
577
578#[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_struct_field1_finish(f,
"Homogeneous", &__self_0),
Self::Heterogeneous(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Heterogeneous", &__self_0),
}
}
}Debug)]
579enum TryBlockScope {
580 Function,
582 Homogeneous(HirId),
585 Heterogeneous(HirId),
588}
589
590fn index_ast<'tcx>(
591 tcx: TyCtxt<'tcx>,
592 (): (),
593) -> &'tcx IndexSlice<LocalDefId, Option<Steal<(Arc<ResolverAstLowering<'tcx>>, AstOwner)>>> {
594 tcx.ensure_done().output_filenames(());
596 tcx.ensure_done().early_lint_checks(());
597 tcx.ensure_done().get_lang_items(());
598 tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
599
600 let (resolver, krate) = tcx.resolver_for_lowering();
601 let mut resolver = resolver.steal();
602 let mut krate = krate.steal();
603
604 let mut indexer = Indexer {
605 owners: &resolver.owners,
606 index: IndexVec::new(),
607 next_node_id: resolver.next_node_id,
608 };
609 indexer.visit_crate(&mut krate);
610 indexer.insert(CRATE_NODE_ID, AstOwner::Crate(Box::new(krate)));
611 resolver.next_node_id = indexer.next_node_id;
612
613 let index = indexer.index;
614 let resolver = Arc::new(resolver);
615 return tcx.arena.alloc_index_slice_from_iter::<LocalDefId, _, _>(
616 index.into_iter().map(|owner| owner.map(|o| Steal::new((Arc::clone(&resolver), o)))),
617 );
618
619 struct Indexer<'s, 'hir> {
620 owners: &'s NodeMap<PerOwnerResolverData<'hir>>,
621 index: IndexVec<LocalDefId, Option<AstOwner>>,
622 next_node_id: NodeId,
623 }
624
625 impl Indexer<'_, '_> {
626 fn insert(&mut self, id: NodeId, node: AstOwner) {
627 let def_id = self.owners[&id].def_id;
628 self.index.insert(def_id, node);
629 }
630
631 fn make_dummy<K>(
632 &mut self,
633 id: NodeId,
634 span: Span,
635 dummy: impl FnOnce(Box<MacCall>) -> K,
636 ) -> Box<Item<K>> {
637 use rustc_ast::token::Delimiter;
638 use rustc_ast::tokenstream::{DelimSpan, TokenStream};
639 use thin_vec::thin_vec;
640
641 Box::new(Item {
642 attrs: AttrVec::default(),
643 id,
644 span,
645 vis: Visibility { kind: VisibilityKind::Public, span },
646 kind: dummy(Box::new(MacCall {
649 path: Path { span, segments: ::thin_vec::ThinVec::new()thin_vec![] },
650 args: Box::new(DelimArgs {
651 dspan: DelimSpan::from_single(span),
652 delim: Delimiter::Parenthesis,
653 tokens: TokenStream::new(Vec::new()),
654 }),
655 })),
656 tokens: None,
657 })
658 }
659
660 fn replace_with_dummy<K>(
661 &mut self,
662 item: &mut ast::Item<K>,
663 dummy: impl FnOnce(Box<MacCall>) -> K,
664 node: impl FnOnce(Box<Item<K>>) -> AstOwner,
665 ) {
666 let dummy = self.make_dummy(item.id, item.span, dummy);
667 let item = mem::replace(item, *dummy);
668 self.insert(item.id, node(Box::new(item)));
669 }
670 }
671
672 impl MutVisitor for Indexer<'_, '_> {
673 fn visit_attribute(&mut self, _: &mut Attribute) {
674 }
677
678 fn flat_map_item(&mut self, mut item: Box<Item>) -> SmallVec<[Box<Item>; 1]> {
679 mut_visit::walk_item(self, &mut *item);
680 let dummy = self.make_dummy(item.id, item.span, ItemKind::MacCall);
681 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];
682 self.insert(item.id, AstOwner::Item(item));
683 items
684 }
685
686 fn visit_assoc_item(&mut self, item: &mut AssocItem, ctxt: visit::AssocCtxt) {
687 mut_visit::walk_assoc_item(self, item, ctxt);
688 match ctxt {
689 visit::AssocCtxt::Trait => {
690 self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::TraitItem)
691 }
692 visit::AssocCtxt::Impl { .. } => {
693 self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::ImplItem)
694 }
695 }
696 }
697
698 fn visit_foreign_item(&mut self, item: &mut ForeignItem) {
699 mut_visit::walk_item(self, item);
700 self.replace_with_dummy(item, ForeignItemKind::MacCall, AstOwner::ForeignItem);
701 }
702 }
703}
704
705{}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(705u32),
::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);
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(Some(r_and_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 (resolver, node) = r_and_node.steal();
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, AstTarget::Crate(c));
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))
}),
};
tcx.sess.time("drop_ast", || mem::drop(node));
item
}
}
}#[instrument(level = "trace", skip(tcx))]
706fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> {
707 tcx.ensure_done().resolve_type_relative_delegations(());
708
709 let ast_index = tcx.index_ast(());
710 let resolver_and_node = ast_index.get(def_id);
711
712 let fallback_to_ancestor = || {
713 let parent_id = tcx.local_parent(def_id);
716 let mut parent_info = tcx.lower_to_hir(parent_id);
717 while let hir::MaybeOwner::NonOwner(hir_id) = parent_info {
718 parent_info = tcx.lower_to_hir(hir_id.owner);
724 }
725
726 let parent_info = parent_info.unwrap();
727 *parent_info.children.get(&def_id).unwrap_or_else(|| {
728 span_bug!(
729 tcx.source_span(def_id),
730 "{:?} does not appear in children of {:?}",
731 def_id,
732 parent_info.nodes.node().def_id()
733 )
734 })
735 };
736
737 let Some(Some(r_and_node)) = resolver_and_node else {
738 return fallback_to_ancestor();
745 };
746
747 fn with_lctx<'hir>(
748 tcx: TyCtxt<'hir>,
749 resolver: &ResolverAstLowering<'hir>,
750 owner: NodeId,
751 f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
752 ) -> hir::MaybeOwner<'hir> {
753 let mut lctx = LoweringContext::new(tcx, resolver, owner);
754 let item = f(&mut lctx);
755 hir::MaybeOwner::Owner(lctx.curr_owner.into_owner_info(tcx, item))
756 }
757
758 let (resolver, node) = r_and_node.steal();
759
760 let item = match &node {
761 AstOwner::Crate(c) => with_lctx(tcx, &*resolver, CRATE_NODE_ID, |lctx| {
763 debug_assert_eq!(lctx.curr_owner.owner_id(), CRATE_OWNER_ID);
764 let module = lctx.lower_mod(&c.items, &c.spans);
765 lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, c.spans.inner_span, AstTarget::Crate(c));
766 hir::OwnerNode::Crate(module)
767 }),
768 AstOwner::Item(item) => {
769 with_lctx(tcx, &*resolver, item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
770 }
771 AstOwner::TraitItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
772 hir::OwnerNode::TraitItem(lctx.lower_trait_item(item))
773 }),
774 AstOwner::ImplItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
775 hir::OwnerNode::ImplItem(lctx.lower_impl_item(item))
776 }),
777 AstOwner::ForeignItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
778 hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
779 }),
780 };
781
782 tcx.sess.time("drop_ast", || mem::drop(node));
783
784 item
785}
786
787#[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)]
788enum ParamMode {
789 Explicit,
791 Optional,
793}
794
795#[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)]
796enum AllowReturnTypeNotation {
797 Yes,
799 No,
801}
802
803enum GenericArgsMode {
804 ParenSugar,
806 ReturnTypeNotation,
808 Err,
810 Silence,
812}
813
814#[derive(#[automatically_derived]impl ::core::fmt::Debug for DiscardParams {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
DiscardParams::Yes => "Yes",
DiscardParams::No => "No",
})
}
}Debug, #[automatically_derived]impl ::core::marker::Copy for DiscardParams { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DiscardParams {
}
#[automatically_derived]impl ::core::clone::Clone for DiscardParams {
#[inline]
fn clone(&self) -> Self { *self }
}Clone)]
815enum DiscardParams {
816 Yes,
818 No,
820}
821
822impl<'hir> LoweringContext<'_, 'hir> {
823 fn create_def(
824 &mut self,
825 node_id: NodeId,
826 name: Option<Symbol>,
827 def_kind: DefKind,
828 span: Span,
829 ) -> LocalDefId {
830 let parent = self.curr_owner.owner_id().def_id;
831 {
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);
832 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!(
833 self.opt_local_def_id(node_id).is_none(),
834 "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
835 node_id,
836 def_kind,
837 self.tcx.hir_def_key(self.local_def_id(node_id)),
838 );
839
840 let def_id = self
841 .tcx
842 .at(span)
843 .create_def(parent, name, def_kind, None, &mut self.curr_owner.disambiguator)
844 .def_id();
845
846 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:846",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(846u32),
::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);
847 self.node_id_to_def_id.insert(node_id, def_id);
848
849 def_id
850 }
851
852 fn next_node_id(&mut self) -> NodeId {
853 let start = self.next_node_id;
854 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
855 self.next_node_id = NodeId::from_u32(next);
856 start
857 }
858
859 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(861u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:861",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(861u32),
::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)]
862 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
863 self.node_id_to_def_id
864 .get(&node)
865 .or_else(|| self.curr_owner.owner.node_id_to_def_id.get(&node))
866 .copied()
867 }
868
869 fn local_def_id(&self, node: NodeId) -> LocalDefId {
870 self.opt_local_def_id(node).unwrap_or_else(|| {
871 self.resolver.owners.items().any(|(id, items)| {
872 items.node_id_to_def_id.items().any(|(node_id, def_id)| {
873 if *node_id == node {
874 let actual_owner = items.node_id_to_def_id.get(id);
875 {
::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})",)
876 }
877 false
878 })
879 });
880 {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
};panic!("no entry for node id: `{node:?}`");
881 })
882 }
883
884 fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
885 match self.partial_res_overrides.get(&id) {
886 Some(self_param_id) => Some(PartialRes::new(Res::Local(*self_param_id))),
887 None => self.resolver.partial_res_map.get(&id).copied(),
888 }
889 }
890
891 fn owner_id(&self, node: NodeId) -> hir::OwnerId {
893 hir::OwnerId { def_id: self.resolver.owners[&node].def_id }
894 }
895
896 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(901u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:901",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(901u32),
::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)]
902 fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
903 assert_ne!(ast_node_id, DUMMY_NODE_ID);
904
905 let owner = self.curr_owner.owner_id();
906 let local_id = self.curr_owner.item_local_id_counter;
907 assert_ne!(local_id, hir::ItemLocalId::ZERO);
908 self.curr_owner.item_local_id_counter.increment_by(1);
909 let hir_id = HirId { owner, local_id };
910
911 if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
912 self.curr_owner.children.insert(def_id, hir::MaybeOwner::NonOwner(hir_id));
913 }
914
915 if let Some(traits) = self.curr_owner.owner.trait_map.get(&ast_node_id) {
916 self.curr_owner.trait_map.insert(hir_id.local_id, *traits);
917 }
918
919 #[cfg(debug_assertions)]
921 self.curr_owner.relowering_checker.assert_node_is_not_relowered(ast_node_id, local_id);
922
923 hir_id
924 }
925
926 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(927u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:927",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(927u32),
::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)]
928 fn next_id(&mut self) -> HirId {
929 let owner = self.curr_owner.owner_id();
930 let local_id = self.curr_owner.item_local_id_counter;
931 assert_ne!(local_id, hir::ItemLocalId::ZERO);
932 self.curr_owner.item_local_id_counter.increment_by(1);
933 HirId { owner, local_id }
934 }
935
936 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(936u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:944",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(944u32),
::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))]
937 fn lower_res(&self, res: Res<NodeId>) -> Res {
938 let res: Result<Res, ()> = res.apply_id(|id| {
939 let owner = self.curr_owner.owner_id();
940 let local_id =
941 self.curr_owner.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
942 Ok(HirId { owner, local_id })
943 });
944 trace!(?res);
945
946 res.unwrap_or(Res::Err)
952 }
953
954 fn expect_full_res(&self, id: NodeId) -> Res<NodeId> {
955 self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
956 }
957
958 fn lower_import_res(&self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
959 let per_ns = self
960 .curr_owner
961 .owner
962 .import_res
963 .get(&id)
964 .unwrap_or_else(|| {
965 let sp = self.tcx.source_span(self.curr_owner.owner.def_id);
966 self.tcx.dcx().span_delayed_bug(
967 sp,
968 "no import_res entry for import, \
969 this should only happen if it already errored in resolve",
970 );
971 &PerNS { value_ns: None, type_ns: None, macro_ns: None }
972 })
973 .map(|res| res.map(|res| self.lower_res(res)));
974
975 if per_ns.is_empty() {
976 self.dcx().span_delayed_bug(span, "no resolution for an import");
978 let err = Some(Res::Err);
979 return PerNS { type_ns: err, value_ns: err, macro_ns: err };
980 }
981 per_ns
982 }
983
984 fn make_lang_item_qpath(
985 &mut self,
986 lang_item: LangItem,
987 span: Span,
988 args: Option<&'hir hir::GenericArgs<'hir>>,
989 ) -> hir::QPath<'hir> {
990 hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
991 }
992
993 fn make_lang_item_path(
994 &mut self,
995 lang_item: LangItem,
996 span: Span,
997 args: Option<&'hir hir::GenericArgs<'hir>>,
998 ) -> &'hir hir::Path<'hir> {
999 let def_id = self.tcx.require_lang_item(lang_item, span);
1000 let def_kind = self.tcx.def_kind(def_id);
1001 let res = Res::Def(def_kind, def_id);
1002 self.arena.alloc(hir::Path {
1003 span,
1004 res,
1005 segments: self.arena.alloc_from_iter([hir::PathSegment {
1006 ident: Ident::new(lang_item.name(), span),
1007 hir_id: self.next_id(),
1008 res,
1009 args,
1010 infer_args: args.is_none(),
1011 delegation_child_segment: false,
1012 }]),
1013 })
1014 }
1015
1016 fn mark_span_with_reason(
1019 &self,
1020 reason: DesugaringKind,
1021 span: Span,
1022 allow_internal_unstable: Option<Arc<[Symbol]>>,
1023 ) -> Span {
1024 self.tcx.with_stable_hashing_context(|hcx| {
1025 span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
1026 })
1027 }
1028
1029 fn span_lowerer(&self) -> SpanLowerer {
1030 SpanLowerer {
1031 is_incremental: self.tcx.sess.opts.incremental.is_some(),
1032 def_id: self.curr_owner.owner_id().def_id,
1033 }
1034 }
1035
1036 fn lower_span(&self, span: Span) -> Span {
1039 self.span_lowerer().lower(span)
1040 }
1041
1042 fn lower_ident(&self, ident: Ident) -> Ident {
1043 Ident::new(ident.name, self.lower_span(ident.span))
1044 }
1045
1046 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1047u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:1062",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1062u32),
::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))]
1048 fn lifetime_res_to_generic_param(
1049 &mut self,
1050 ident: Ident,
1051 node_id: NodeId,
1052 kind: MissingLifetimeKind,
1053 source: hir::GenericParamSource,
1054 ) -> hir::GenericParam<'hir> {
1055 let _def_id = self.create_def(
1057 node_id,
1058 Some(kw::UnderscoreLifetime),
1059 DefKind::LifetimeParam,
1060 ident.span,
1061 );
1062 debug!(?_def_id);
1063
1064 let hir_id = self.lower_node_id(node_id);
1065 let def_id = self.local_def_id(node_id);
1066 hir::GenericParam {
1067 hir_id,
1068 def_id,
1069 name: hir::ParamName::Fresh,
1070 span: self.lower_span(ident.span),
1071 pure_wrt_drop: false,
1072 kind: hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided(kind) },
1073 colon_span: None,
1074 source,
1075 }
1076 }
1077
1078 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1083u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:1093",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1093u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:1083",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1083u32),
::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)]
1084 #[inline]
1085 fn lower_lifetime_binder(
1086 &mut self,
1087 binder: NodeId,
1088 generic_params: &[GenericParam],
1089 ) -> &'hir [hir::GenericParam<'hir>] {
1090 let extra_lifetimes = self.curr_owner.owner.extra_lifetime_params(binder);
1093 debug!(?extra_lifetimes);
1094 let extra_lifetimes: Vec<_> = extra_lifetimes
1095 .iter()
1096 .map(|&(ident, node_id, res)| {
1097 self.lifetime_res_to_generic_param(
1098 ident,
1099 node_id,
1100 res,
1101 hir::GenericParamSource::Binder,
1102 )
1103 })
1104 .collect();
1105 let arena = self.arena;
1106 let explicit_generic_params =
1107 self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
1108 arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
1109 }
1110
1111 fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
1112 let was_in_dyn_type = self.is_in_dyn_type;
1113 self.is_in_dyn_type = in_scope;
1114
1115 let result = f(self);
1116
1117 self.is_in_dyn_type = was_in_dyn_type;
1118
1119 result
1120 }
1121
1122 fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
1123 let current_item_span = self.current_item_span;
1124 self.current_item_span = Some(scope_span);
1125
1126 let was_in_loop_condition = self.is_in_loop_condition;
1127 self.is_in_loop_condition = false;
1128
1129 let old_contract = self.contract_ensures.take();
1130
1131 let try_block_scope = mem::replace(&mut self.try_block_scope, TryBlockScope::Function);
1132 let loop_scope = self.loop_scope.take();
1133 let ret = f(self);
1134 self.try_block_scope = try_block_scope;
1135 self.loop_scope = loop_scope;
1136
1137 self.contract_ensures = old_contract;
1138
1139 self.is_in_loop_condition = was_in_loop_condition;
1140
1141 self.current_item_span = current_item_span;
1142
1143 ret
1144 }
1145
1146 fn lower_attrs(
1147 &mut self,
1148 id: HirId,
1149 attrs: &[Attribute],
1150 target_span: Span,
1151 ast_target: AstTarget<'_>,
1152 ) -> &'hir [rustc_attr_ir::Attribute] {
1153 self.lower_attrs_with_extra(id, attrs, target_span, ast_target, &[])
1154 }
1155
1156 fn lower_attrs_with_extra(
1157 &mut self,
1158 id: HirId,
1159 attrs: &[Attribute],
1160 target_span: Span,
1161 ast_target: AstTarget<'_>,
1162 extra_hir_attributes: &[rustc_attr_ir::Attribute],
1163 ) -> &'hir [rustc_attr_ir::Attribute] {
1164 if attrs.is_empty() && extra_hir_attributes.is_empty() {
1165 &[]
1166 } else {
1167 let mut lowered_attrs =
1168 self.lower_attrs_vec(attrs, self.lower_span(target_span), id, ast_target);
1169 lowered_attrs.extend(extra_hir_attributes.iter().cloned());
1170
1171 {
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());
1172 let ret = self.arena.alloc_from_iter(lowered_attrs);
1173
1174 if ret.is_empty() {
1181 &[]
1182 } else {
1183 self.curr_owner.attrs.insert(id.local_id, ret);
1184 ret
1185 }
1186 }
1187 }
1188
1189 fn lower_attrs_vec(
1190 &mut self,
1191 attrs: &[Attribute],
1192 target_span: Span,
1193 target_hir_id: HirId,
1194 ast_target: AstTarget<'_>,
1195 ) -> Vec<rustc_attr_ir::Attribute> {
1196 let l = self.span_lowerer();
1197 self.attribute_parser.parse_attribute_list(
1198 attrs,
1199 target_span,
1200 ast_target,
1201 |s| l.lower(s),
1202 |lint_id, span, kind| {
1203 self.curr_owner.delayed_lints.push(DelayedLint {
1204 lint_id,
1205 id: target_hir_id,
1206 span,
1207 callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
1208 let sess = sess
1209 .downcast_ref::<rustc_session::Session>()
1210 .expect("expected `Session`");
1211 (kind.0)(dcx, level, sess)
1212 }),
1213 });
1214 },
1215 )
1216 }
1217
1218 fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
1219 {
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());
1220 {
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());
1221 if let Some(&a) = self.curr_owner.attrs.get(&target_id.local_id) {
1222 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
1223 self.curr_owner.attrs.insert(id.local_id, a);
1224 }
1225 }
1226
1227 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1228u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:1234",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1234u32),
::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.ctxt() == constraint.span.ctxt() {
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)]
1229 fn lower_assoc_item_constraint(
1230 &mut self,
1231 constraint: &AssocItemConstraint,
1232 itctx: ImplTraitContext,
1233 ) -> hir::AssocItemConstraint<'hir> {
1234 debug!(?constraint, ?itctx);
1235 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1237 let gen_args_ctor = match gen_args {
1238 GenericArgs::AngleBracketed(data) => {
1239 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1240 }
1241 GenericArgs::Parenthesized(data) => {
1242 if let Some(first_char) = constraint.ident.as_str().chars().next()
1243 && first_char.is_ascii_lowercase()
1244 {
1245 let err = match (&data.inputs[..], &data.output) {
1246 ([_, ..], FnRetTy::Default(_)) => {
1247 diagnostics::BadReturnTypeNotation::Inputs {
1248 span: data.inputs_span,
1249 }
1250 }
1251 ([], FnRetTy::Default(_)) => {
1252 diagnostics::BadReturnTypeNotation::NeedsDots {
1253 span: data.inputs_span,
1254 }
1255 }
1256 (_, FnRetTy::Ty(ty)) => {
1258 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1259 diagnostics::BadReturnTypeNotation::Output {
1260 span,
1261 suggestion: diagnostics::RTNSuggestion {
1262 output: span,
1263 input: data.inputs_span,
1264 },
1265 }
1266 }
1267 };
1268 let mut err = self.dcx().create_err(err);
1269 if !self.tcx.features().return_type_notation()
1270 && self.tcx.sess.is_nightly_build()
1271 {
1272 add_feature_diagnostics(
1273 &mut err,
1274 &self.tcx.sess,
1275 sym::return_type_notation,
1276 );
1277 }
1278 err.emit();
1279 GenericArgsCtor {
1280 args: Default::default(),
1281 constraints: &[],
1282 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1283 span: data.span,
1284 }
1285 } else {
1286 let guar = self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1287 self.lower_angle_bracketed_parameter_data(
1288 &data.as_angle_bracketed_args(),
1289 ParamMode::Explicit,
1290 ImplTraitContext::AlreadyErrored(guar),
1291 )
1292 .0
1293 }
1294 }
1295 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1296 args: Default::default(),
1297 constraints: &[],
1298 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1299 span: *span,
1300 },
1301 };
1302 gen_args_ctor.into_generic_args(self)
1303 } else {
1304 hir::GenericArgs::NONE
1305 };
1306 let kind = match &constraint.kind {
1307 AssocItemConstraintKind::Equality { term } => {
1308 let term = match term {
1309 Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
1310 Term::Const(c) => self.lower_anon_const_to_const_arg_and_alloc(c).into(),
1311 };
1312 hir::AssocItemConstraintKind::Equality { term }
1313 }
1314 AssocItemConstraintKind::Bound { bounds } => {
1315 if self.is_in_dyn_type {
1317 let suggestion = match itctx {
1318 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1319 let bound_end_span = constraint
1320 .gen_args
1321 .as_ref()
1322 .map_or(constraint.ident.span, |args| args.span());
1323 if bound_end_span.ctxt() == constraint.span.ctxt() {
1324 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1325 } else {
1326 None
1327 }
1328 }
1329 _ => None,
1330 };
1331
1332 let guar = self.dcx().emit_err(diagnostics::MisplacedAssocTyBinding {
1333 span: constraint.span,
1334 suggestion,
1335 });
1336 let err_ty =
1337 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1338 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1339 } else {
1340 let bounds = self.lower_param_bounds(
1341 bounds,
1342 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1343 itctx,
1344 );
1345 hir::AssocItemConstraintKind::Bound { bounds }
1346 }
1347 }
1348 };
1349
1350 hir::AssocItemConstraint {
1351 hir_id: self.lower_node_id(constraint.id),
1352 ident: self.lower_ident(constraint.ident),
1353 gen_args,
1354 kind,
1355 span: self.lower_span(constraint.span),
1356 }
1357 }
1358
1359 fn emit_bad_parenthesized_trait_in_assoc_ty(
1360 &self,
1361 data: &ParenthesizedArgs,
1362 ) -> ErrorGuaranteed {
1363 let sub = if data.inputs.is_empty() {
1365 let parentheses_span =
1366 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1367 AssocTyParenthesesSub::Empty { parentheses_span }
1368 }
1369 else {
1371 let open_param = data.inputs_span.shrink_to_lo().to(data
1373 .inputs
1374 .first()
1375 .unwrap()
1376 .span
1377 .shrink_to_lo());
1378 let close_param =
1380 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1381 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1382 };
1383 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub })
1384 }
1385
1386 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1386u32),
::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() => {
let ct =
match self.can_lower_expr_to_const_arg_direct(expr,
self.direct_const_arg_context_enabled_by_gca_macro()) {
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))]
1387 fn lower_generic_arg(
1388 &mut self,
1389 arg: &ast::GenericArg,
1390 itctx: ImplTraitContext,
1391 ) -> hir::GenericArg<'hir> {
1392 match arg {
1393 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1394 lt,
1395 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1396 lt.ident.into(),
1397 )),
1398 ast::GenericArg::Type(ty) => {
1399 if ty.is_maybe_parenthesised_infer() {
1402 return GenericArg::Infer(self.arena.alloc(hir::InferArg {
1403 hir_id: self.lower_node_id(ty.id),
1404 span: self.lower_span(ty.span),
1405 kind: hir::InferArgKind::TypeOrConst,
1406 }));
1407 }
1408
1409 match &ty.kind {
1410 TyKind::Path(None, path)
1421 if path.is_single_argless_ident()
1422 && let Some(res) = self
1423 .get_partial_res(ty.id)
1424 .and_then(|partial_res| partial_res.full_res())
1425 && !res.matches_ns(Namespace::TypeNS) =>
1426 {
1427 let ct =
1428 self.lower_const_path_to_const_arg(&None, path, res, ty.id, ty.span);
1429 let ct = self.arena.alloc(ct);
1430 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1431 }
1432 TyKind::GcaMacro(expr) if self.tcx.features().gca() => {
1433 let ct = match self.can_lower_expr_to_const_arg_direct(
1434 expr,
1435 self.direct_const_arg_context_enabled_by_gca_macro(),
1436 ) {
1437 Ok(()) => self.lower_expr_to_const_arg_direct(expr, None),
1438 Err(e) => e.emit(self),
1439 };
1440 let ct = self.arena.alloc(ct);
1441 return match ct.try_as_ambig_ct() {
1442 Some(ct) => GenericArg::Const(ct),
1443 None => GenericArg::Infer(self.arena.alloc(hir::InferArg {
1444 hir_id: ct.hir_id,
1445 span: ct.span,
1446 kind: hir::InferArgKind::Const,
1447 })),
1448 };
1449 }
1450 _ => {}
1451 }
1452 GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
1453 }
1454 ast::GenericArg::Const(ct) => {
1455 let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1456 match ct.try_as_ambig_ct() {
1457 Some(ct) => GenericArg::Const(ct),
1458 None => GenericArg::Infer(self.arena.alloc(hir::InferArg {
1459 hir_id: ct.hir_id,
1460 span: ct.span,
1461 kind: hir::InferArgKind::Const,
1462 })),
1463 }
1464 }
1465 }
1466 }
1467
1468 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1468u32),
::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))]
1469 fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1470 self.arena.alloc(self.lower_ty(t, itctx))
1471 }
1472
1473 fn lower_path_ty(
1474 &mut self,
1475 t: &Ty,
1476 qself: &Option<Box<QSelf>>,
1477 path: &Path,
1478 param_mode: ParamMode,
1479 itctx: ImplTraitContext,
1480 ) -> hir::Ty<'hir> {
1481 if qself.is_none()
1487 && let Some(partial_res) = self.get_partial_res(t.id)
1488 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1489 {
1490 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1491 let bound = this.lower_poly_trait_ref(
1492 &PolyTraitRef {
1493 bound_generic_params: ThinVec::new(),
1494 modifiers: TraitBoundModifiers::NONE,
1495 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1496 span: t.span,
1497 parens: ast::Parens::No,
1498 },
1499 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1500 itctx,
1501 );
1502 let bounds = this.arena.alloc_from_iter([bound]);
1503 let lifetime_bound = this.elided_dyn_bound(t.span);
1504 (bounds, lifetime_bound)
1505 });
1506 let kind = hir::TyKind::TraitObject(
1507 bounds,
1508 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1509 );
1510 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1511 }
1512
1513 let id = self.lower_node_id(t.id);
1514 let qpath = self.lower_qpath(
1515 t.id,
1516 qself,
1517 path,
1518 param_mode,
1519 AllowReturnTypeNotation::Yes,
1520 itctx,
1521 None,
1522 );
1523 self.ty_path(id, t.span, qpath)
1524 }
1525
1526 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1527 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1528 }
1529
1530 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1531 self.ty(span, hir::TyKind::Tup(tys))
1532 }
1533
1534 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1535 let kind = match &t.kind {
1536 TyKind::Infer => hir::TyKind::Infer(()),
1537 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1538 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
1539 TyKind::Ptr(ty, mutbl) => hir::TyKind::Ptr(self.lower_ty_alloc(ty, itctx), *mutbl),
1540 TyKind::Ref(region, ty, mutbl) => {
1541 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1542 hir::TyKind::Ref(lifetime, self.lower_ty_alloc(ty, itctx), *mutbl)
1543 }
1544 TyKind::PinnedRef(region, ty, mutbl) => {
1545 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1546 let kind = hir::TyKind::Ref(lifetime, self.lower_ty_alloc(ty, itctx), *mutbl);
1547 let span = self.lower_span(t.span);
1548 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1549 let args = self.arena.alloc(hir::GenericArgs {
1550 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1551 constraints: &[],
1552 parenthesized: hir::GenericArgsParentheses::No,
1553 span_ext: span,
1554 });
1555 let path = self.make_lang_item_qpath(LangItem::Pin, span, Some(args));
1556 hir::TyKind::Path(path)
1557 }
1558 TyKind::FnPtr(f) => {
1559 let hir_id = self.lower_node_id(t.id);
1560 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1561 let kind = hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1562 generic_params,
1563 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1564 abi: self.lower_extern(f.ext),
1565 decl: self.lower_fn_decl(
1566 &f.decl,
1567 t.id,
1568 hir_id,
1569 FnDeclKind::Pointer,
1570 None,
1571 DiscardParams::Yes,
1572 ),
1573 param_idents: self.lower_fn_params_to_idents(&f.decl),
1574 }));
1575 return hir::Ty { kind, span: self.lower_span(t.span), hir_id };
1576 }
1577 TyKind::UnsafeBinder(f) => {
1578 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1579 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1580 generic_params,
1581 inner_ty: self.lower_ty_alloc(&f.inner_ty, itctx),
1582 }))
1583 }
1584 TyKind::Never => hir::TyKind::Never,
1585 TyKind::Tup(tys) => hir::TyKind::Tup(
1586 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty(ty, itctx))),
1587 ),
1588 TyKind::Paren(ty) => {
1589 return self.lower_ty(ty, itctx);
1590 }
1591 TyKind::Path(qself, path) => {
1592 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1593 }
1594 TyKind::ImplicitSelf => {
1595 let hir_id = self.next_id();
1596 let res = self.expect_full_res(t.id);
1597 let res = self.lower_res(res);
1598 hir::TyKind::Path(hir::QPath::Resolved(
1599 None,
1600 self.arena.alloc(hir::Path {
1601 res,
1602 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1603 Ident::with_dummy_span(kw::SelfUpper),
1604 hir_id,
1605 res
1606 )],
1607 span: self.lower_span(t.span),
1608 }),
1609 ))
1610 }
1611 TyKind::Array(ty, length) => hir::TyKind::Array(
1612 self.lower_ty_alloc(ty, itctx),
1613 self.lower_array_length_to_const_arg(length),
1614 ),
1615 TyKind::TraitObject(bounds, kind) => {
1616 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1617 let mut lifetime_bound = None;
1618 let bounds =
1619 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1620 GenericBound::Trait(ty) => {
1624 let trait_ref = this.lower_poly_trait_ref(
1625 ty,
1626 RelaxedBoundPolicy::Forbidden(
1627 RelaxedBoundForbiddenReason::TraitObjectTy,
1628 ),
1629 itctx,
1630 );
1631 Some(trait_ref)
1632 }
1633 GenericBound::Outlives(lifetime) => {
1634 if lifetime_bound.is_none() {
1635 lifetime_bound = Some(this.lower_lifetime(
1636 lifetime,
1637 LifetimeSource::Other,
1638 lifetime.ident.into(),
1639 ));
1640 }
1641 None
1642 }
1643 GenericBound::Use(_, span) => {
1645 this.dcx()
1646 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1647 None
1648 }
1649 }));
1650 (bounds, lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span)))
1651 });
1652 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1653 }
1654 TyKind::ImplTrait(def_node_id, bounds) => {
1655 let span = t.span;
1656 match itctx {
1657 ImplTraitContext::OpaqueTy { origin } => {
1658 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1659 }
1660 ImplTraitContext::Universal => {
1661 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1662 ast::GenericBound::Use(_, span) => Some(span),
1663 _ => None,
1664 }) {
1665 self.tcx.dcx().emit_err(diagnostics::NoPreciseCapturesOnApit { span });
1666 }
1667
1668 let def_id = self.local_def_id(*def_node_id);
1669 let name = self.tcx.item_name(def_id.to_def_id());
1670 let ident = Ident::new(name, span);
1671 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1672 *def_node_id,
1673 span,
1674 ident,
1675 bounds,
1676 );
1677 self.curr_owner.impl_trait_defs.push(param);
1678 if let Some(bounds) = bounds {
1679 self.curr_owner.impl_trait_bounds.push(bounds);
1680 }
1681 path
1682 }
1683 ImplTraitContext::InBinding => {
1684 hir::TyKind::TraitAscription(self.lower_param_bounds(
1685 bounds,
1686 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1687 itctx,
1688 ))
1689 }
1690 ImplTraitContext::FeatureGated(position, feature) => {
1691 let guar = self
1692 .tcx
1693 .sess
1694 .create_feature_err(
1695 MisplacedImplTrait {
1696 span: t.span,
1697 position: DiagArgFromDisplay(&position),
1698 },
1699 feature,
1700 )
1701 .emit_err();
1702 hir::TyKind::Err(guar)
1703 }
1704 ImplTraitContext::Disallowed(position) => {
1705 let guar = self.dcx().emit_err(MisplacedImplTrait {
1706 span: t.span,
1707 position: DiagArgFromDisplay(&position),
1708 });
1709 hir::TyKind::Err(guar)
1710 }
1711 ImplTraitContext::AlreadyErrored(guar) => {
1712 hir::TyKind::Err(guar)
1719 }
1720 }
1721 }
1722 TyKind::Pat(ty, pat) => {
1723 hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
1724 }
1725 TyKind::FieldOf(ty, variant, field) => hir::TyKind::FieldOf(
1726 self.lower_ty_alloc(ty, itctx),
1727 self.arena.alloc(hir::TyFieldPath {
1728 variant: variant.map(|variant| self.lower_ident(variant)),
1729 field: self.lower_ident(*field),
1730 }),
1731 ),
1732 TyKind::MacCall(_) => {
1733 ::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")
1734 }
1735 TyKind::CVarArgs => {
1736 let guar = self.dcx().span_delayed_bug(
1737 t.span,
1738 "`TyKind::CVarArgs` should have been handled elsewhere",
1739 );
1740 hir::TyKind::Err(guar)
1741 }
1742 TyKind::View(ty, fields) => {
1743 let ty = self.lower_ty_alloc(ty, itctx);
1744 let fields = self.arena.alloc_slice(fields);
1745 hir::TyKind::View(ty, fields)
1746 }
1747 TyKind::GcaMacro(expr) => {
1748 let e = self.emit_bad_gca_macro(t.span, expr, "type");
1749 hir::TyKind::Err(e)
1750 }
1751 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1752 };
1753
1754 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1755 }
1756
1757 pub(crate) fn emit_bad_gca_macro(
1758 &mut self,
1759 span: Span,
1760 expr: &Expr,
1761 expected: &'static str,
1762 ) -> ErrorGuaranteed {
1763 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected {0}, found `gca!()` constant",
expected))
})format!("expected {expected}, found `gca!()` constant");
1764 if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
1765 self.dcx().span_fatal(span, msg)
1768 } else {
1769 self.dcx().span_err(span, msg)
1770 }
1771 }
1772
1773 fn lower_ty_direct_lifetime(
1774 &mut self,
1775 t: &Ty,
1776 region: Option<Lifetime>,
1777 ) -> &'hir hir::Lifetime {
1778 let (region, syntax) = match region {
1779 Some(region) => (region, region.ident.into()),
1780
1781 None => {
1782 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1783 self.curr_owner.owner.get_lifetime_res(t.id)
1784 {
1785 {
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);
1786 start
1787 } else {
1788 self.next_node_id()
1789 };
1790 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1791 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1792 (region, LifetimeSyntax::Implicit)
1793 }
1794 };
1795 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1796 }
1797
1798 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1829u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:1829",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1829u32),
::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)]
1830 fn lower_opaque_impl_trait(
1831 &mut self,
1832 span: Span,
1833 origin: hir::OpaqueTyOrigin<LocalDefId>,
1834 opaque_ty_node_id: NodeId,
1835 bounds: &GenericBounds,
1836 itctx: ImplTraitContext,
1837 ) -> hir::TyKind<'hir> {
1838 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1844
1845 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1846 this.lower_param_bounds(
1847 bounds,
1848 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1849 itctx,
1850 )
1851 })
1852 }
1853
1854 fn lower_opaque_inner(
1855 &mut self,
1856 opaque_ty_node_id: NodeId,
1857 origin: hir::OpaqueTyOrigin<LocalDefId>,
1858 opaque_ty_span: Span,
1859 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1860 ) -> hir::TyKind<'hir> {
1861 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1862 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1863 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:1863",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1863u32),
::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);
1864
1865 let bounds = lower_item_bounds(self);
1866 let opaque_ty_def = hir::OpaqueTy {
1867 hir_id: opaque_ty_hir_id,
1868 def_id: opaque_ty_def_id,
1869 bounds,
1870 origin,
1871 span: self.lower_span(opaque_ty_span),
1872 };
1873 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1874
1875 hir::TyKind::OpaqueDef(opaque_ty_def)
1876 }
1877
1878 fn lower_precise_capturing_args(
1879 &mut self,
1880 precise_capturing_args: &[PreciseCapturingArg],
1881 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1882 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1883 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1884 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1885 ),
1886 PreciseCapturingArg::Arg(path, id) => {
1887 let [segment] = path.segments.as_slice() else {
1888 ::core::panicking::panic_default_msg();panic!();
1889 };
1890 let res = self.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1891 partial_res.full_res().expect("no partial res expected for precise capture arg")
1892 });
1893 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1894 hir_id: self.lower_node_id(*id),
1895 ident: self.lower_ident(segment.ident),
1896 res: self.lower_res(res),
1897 })
1898 }
1899 }))
1900 }
1901
1902 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1903 self.arena.alloc_from_iter(decl.inputs.iter().filter(|param| !param.is_const_param()).map(
1904 |param| match param.pat.kind {
1905 PatKind::Missing => None,
1906 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1907 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1908 _ => {
1909 self.dcx().span_delayed_bug(
1910 param.pat.span,
1911 "non-missing/ident/wild param pat must trigger an error",
1912 );
1913 None
1914 }
1915 },
1916 ))
1917 }
1918
1919 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1934u32),
::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("fn_hir_id")
}> =
::tracing::__macro_support::FieldName::new("fn_hir_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()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("discard_params")
}> =
::tracing::__macro_support::FieldName::new("discard_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(&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(&fn_hir_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)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&discard_params)
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 input_count =
if decl.c_variadic() {
splatted = None;
decl.inputs.len() - 1
} else { decl.inputs.len() };
let inputs = decl.inputs.iter().enumerate().take(input_count);
let inputs =
self.arena.alloc_from_iter(inputs.filter_map(|(param_idx,
param)|
{
if let Some(ident) = param.const_param_ident() {
if !#[allow(non_exhaustive_omitted_patterns)] match kind {
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl |
FnDeclKind::Trait => true,
_ => false,
} {
self.dcx().span_delayed_bug(param.span,
"Const args only allowed for Free/Inherent/Impl/Trait methods");
return None;
}
let ty =
self.lower_ty_alloc(¶m.ty,
ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
let hir_id = self.lower_node_id(param.id);
let generic_param =
hir::GenericParam {
hir_id,
def_id: self.local_def_id(param.id),
name: ParamName::Plain(self.lower_ident(ident)),
span: self.lower_span(param.span),
pure_wrt_drop: false,
kind: hir::GenericParamKind::Const {
ty,
default: None,
arg_pos: Some(param_idx as u16),
},
colon_span: None,
source: hir::GenericParamSource::Generics,
};
let ast_generic_param =
ast::GenericParam {
id: param.id,
ident,
attrs: param.attrs.clone(),
bounds: Default::default(),
is_placeholder: false,
kind: ast::GenericParamKind::Const {
ty: param.ty.clone(),
span: param.span,
default: None,
},
colon_span: None,
};
self.lower_attrs(hir_id, ¶m.attrs, param.span,
AstTarget::GenericParam(&ast_generic_param));
self.curr_owner.const_defs.push(generic_param);
return None;
}
if let DiscardParams::Yes = discard_params {
self.lower_attrs(fn_hir_id, ¶m.attrs, param.span,
AstTarget::Param(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)
}
};
Some(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(_, ty, mutbl) | TyKind::PinnedRef(_, ty, mutbl)
if ty.kind.is_implicit_self() => {
match 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))]
1935 fn lower_fn_decl(
1936 &mut self,
1937 decl: &FnDecl,
1938 fn_node_id: NodeId,
1939 fn_hir_id: HirId,
1940 kind: FnDeclKind,
1941 coro: Option<CoroutineMarker>,
1942 discard_params: DiscardParams,
1943 ) -> &'hir hir::FnDecl<'hir> {
1944 let c_variadic = decl.c_variadic();
1945 let mut splatted = decl.splatted();
1946
1947 let input_count = if decl.c_variadic() {
1951 splatted = None;
1953 decl.inputs.len() - 1
1954 } else {
1955 decl.inputs.len()
1956 };
1957
1958 let inputs = decl.inputs.iter().enumerate().take(input_count);
1959 let inputs = self.arena.alloc_from_iter(inputs.filter_map(|(param_idx, param)| {
1963 if let Some(ident) = param.const_param_ident() {
1964 if !matches!(
1965 kind,
1966 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait
1967 ) {
1968 self.dcx().span_delayed_bug(
1969 param.span,
1970 "Const args only allowed for Free/Inherent/Impl/Trait methods",
1971 );
1972 return None;
1973 }
1974 let ty = self.lower_ty_alloc(
1975 ¶m.ty,
1976 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
1977 );
1978 let hir_id = self.lower_node_id(param.id);
1979 let generic_param = hir::GenericParam {
1980 hir_id,
1981 def_id: self.local_def_id(param.id),
1982 name: ParamName::Plain(self.lower_ident(ident)),
1983 span: self.lower_span(param.span),
1984 pure_wrt_drop: false,
1985 kind: hir::GenericParamKind::Const {
1986 ty,
1987 default: None,
1988 arg_pos: Some(param_idx as u16),
1989 },
1990 colon_span: None,
1991 source: hir::GenericParamSource::Generics,
1992 };
1993 let ast_generic_param = ast::GenericParam {
1994 id: param.id,
1995 ident,
1996 attrs: param.attrs.clone(),
1997 bounds: Default::default(),
1998 is_placeholder: false,
1999 kind: ast::GenericParamKind::Const {
2000 ty: param.ty.clone(),
2001 span: param.span,
2002 default: None,
2003 },
2004 colon_span: None,
2005 };
2006 self.lower_attrs(
2007 hir_id,
2008 ¶m.attrs,
2009 param.span,
2010 AstTarget::GenericParam(&ast_generic_param),
2011 );
2012 self.curr_owner.const_defs.push(generic_param);
2013 return None;
2014 }
2015 if let DiscardParams::Yes = discard_params {
2016 self.lower_attrs(fn_hir_id, ¶m.attrs, param.span, AstTarget::Param(param));
2020 }
2021 let itctx = match kind {
2022 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
2023 ImplTraitContext::Universal
2024 }
2025 FnDeclKind::ExternFn => {
2026 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
2027 }
2028 FnDeclKind::Closure => {
2029 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
2030 }
2031 FnDeclKind::Pointer => {
2032 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
2033 }
2034 };
2035 Some(self.lower_ty(¶m.ty, itctx))
2036 }));
2037
2038 let output = match coro {
2039 Some(coro) => {
2040 let fn_def_id = self.curr_owner.owner.def_id;
2041 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
2042 }
2043 None => match &decl.output {
2044 FnRetTy::Ty(ty) => {
2045 let itctx = match kind {
2046 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
2047 origin: hir::OpaqueTyOrigin::FnReturn {
2048 parent: self.curr_owner.owner.def_id,
2049 in_trait_or_impl: None,
2050 },
2051 },
2052 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
2053 origin: hir::OpaqueTyOrigin::FnReturn {
2054 parent: self.curr_owner.owner.def_id,
2055 in_trait_or_impl: Some(hir::RpitContext::Trait),
2056 },
2057 },
2058 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
2059 origin: hir::OpaqueTyOrigin::FnReturn {
2060 parent: self.curr_owner.owner.def_id,
2061 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
2062 },
2063 },
2064 FnDeclKind::ExternFn => {
2065 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
2066 }
2067 FnDeclKind::Closure => {
2068 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
2069 }
2070 FnDeclKind::Pointer => {
2071 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
2072 }
2073 };
2074 hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
2075 }
2076 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
2077 },
2078 };
2079
2080 let fn_decl_kind = hir::FnDeclFlags::default()
2081 .set_implicit_self(decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
2082 let is_mutable_pat = matches!(
2083 arg.pat.kind,
2084 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
2085 );
2086
2087 match &arg.ty.kind {
2088 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
2089 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
2090 TyKind::Ref(_, ty, mutbl) | TyKind::PinnedRef(_, ty, mutbl)
2094 if ty.kind.is_implicit_self() =>
2095 {
2096 match mutbl {
2097 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
2098 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
2099 }
2100 }
2101 _ => hir::ImplicitSelfKind::None,
2102 }
2103 }))
2104 .set_lifetime_elision_allowed(
2105 self.curr_owner.owner.id == fn_node_id
2106 && self.curr_owner.owner.lifetime_elision_allowed,
2107 )
2108 .set_c_variadic(c_variadic)
2109 .set_splatted(splatted, inputs.len())
2110 .unwrap();
2111
2112 self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
2113 }
2114
2115 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2123u32),
::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::unreachable_default_msg(),
};
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))]
2124 fn lower_coroutine_fn_ret_ty(
2125 &mut self,
2126 output: &FnRetTy,
2127 fn_def_id: LocalDefId,
2128 coro: CoroutineMarker,
2129 fn_kind: FnDeclKind,
2130 ) -> hir::FnRetTy<'hir> {
2131 let span = self.lower_span(output.span());
2132
2133 let (opaque_ty_node_id, allowed_features) = match coro.kind {
2134 CoroutineKind::Async | CoroutineKind::Gen => (coro.return_impl_trait_id, None),
2135 CoroutineKind::AsyncGen => {
2136 (coro.return_impl_trait_id, Some(Arc::clone(&ALLOW_ASYNC_ITERATOR)))
2137 }
2138 };
2139
2140 let opaque_ty_span =
2141 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
2142
2143 let in_trait_or_impl = match fn_kind {
2144 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
2145 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
2146 FnDeclKind::Fn | FnDeclKind::Inherent => None,
2147 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
2148 };
2149
2150 let opaque_ty_ref = self.lower_opaque_inner(
2151 opaque_ty_node_id,
2152 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
2153 opaque_ty_span,
2154 |this| {
2155 let bound = this.lower_coroutine_fn_output_type_to_bound(
2156 output,
2157 coro,
2158 opaque_ty_span,
2159 ImplTraitContext::OpaqueTy {
2160 origin: hir::OpaqueTyOrigin::FnReturn {
2161 parent: fn_def_id,
2162 in_trait_or_impl,
2163 },
2164 },
2165 );
2166 arena_vec![this; bound]
2167 },
2168 );
2169
2170 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
2171 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
2172 }
2173
2174 fn lower_coroutine_fn_output_type_to_bound(
2176 &mut self,
2177 output: &FnRetTy,
2178 coro: CoroutineMarker,
2179 opaque_ty_span: Span,
2180 itctx: ImplTraitContext,
2181 ) -> hir::GenericBound<'hir> {
2182 let output_ty = match output {
2184 FnRetTy::Ty(ty) => {
2185 self.lower_ty_alloc(ty, itctx)
2189 }
2190 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
2191 };
2192
2193 let (assoc_ty_name, trait_lang_item) = match coro.kind {
2195 CoroutineKind::Async => (sym::Output, LangItem::Future),
2196 CoroutineKind::Gen => (sym::Item, LangItem::Iterator),
2197 CoroutineKind::AsyncGen => (sym::Item, LangItem::AsyncIterator),
2198 };
2199
2200 let bound_args = self.arena.alloc(hir::GenericArgs {
2201 args: &[],
2202 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)],
2203 parenthesized: hir::GenericArgsParentheses::No,
2204 span_ext: DUMMY_SP,
2205 });
2206
2207 hir::GenericBound::Trait(hir::PolyTraitRef {
2208 bound_generic_params: &[],
2209 modifiers: hir::TraitBoundModifiers::NONE,
2210 trait_ref: hir::TraitRef {
2211 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
2212 hir_ref_id: self.next_id(),
2213 },
2214 span: opaque_ty_span,
2215 })
2216 }
2217
2218 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2218u32),
::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))]
2219 fn lower_param_bound(
2220 &mut self,
2221 tpb: &GenericBound,
2222 rbp: RelaxedBoundPolicy<'_>,
2223 itctx: ImplTraitContext,
2224 ) -> hir::GenericBound<'hir> {
2225 match tpb {
2226 GenericBound::Trait(p) => {
2227 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
2228 }
2229 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
2230 lifetime,
2231 LifetimeSource::OutlivesBound,
2232 lifetime.ident.into(),
2233 )),
2234 GenericBound::Use(args, span) => hir::GenericBound::Use(
2235 self.lower_precise_capturing_args(args),
2236 self.lower_span(*span),
2237 ),
2238 }
2239 }
2240
2241 fn lower_lifetime(
2242 &mut self,
2243 l: &Lifetime,
2244 source: LifetimeSource,
2245 syntax: LifetimeSyntax,
2246 ) -> &'hir hir::Lifetime {
2247 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
2248 }
2249
2250 fn lower_lifetime_hidden_in_path(
2251 &mut self,
2252 id: NodeId,
2253 span: Span,
2254 angle_brackets: AngleBrackets,
2255 ) -> &'hir hir::Lifetime {
2256 self.new_named_lifetime(
2257 id,
2258 id,
2259 Ident::new(kw::UnderscoreLifetime, span),
2260 LifetimeSource::Path { angle_brackets },
2261 LifetimeSyntax::Implicit,
2262 )
2263 }
2264
2265 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2265u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:2299",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2299u32),
::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))]
2266 fn new_named_lifetime(
2267 &mut self,
2268 id: NodeId,
2269 new_id: NodeId,
2270 ident: Ident,
2271 source: LifetimeSource,
2272 syntax: LifetimeSyntax,
2273 ) -> &'hir hir::Lifetime {
2274 let res = if let Some(res) = self.curr_owner.owner.get_lifetime_res(id) {
2275 match res {
2276 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
2277 LifetimeRes::Fresh { param, .. } => {
2278 assert_eq!(ident.name, kw::UnderscoreLifetime);
2279 let param = self.local_def_id(param);
2280 hir::LifetimeKind::Param(param)
2281 }
2282 LifetimeRes::Infer => {
2283 assert_eq!(ident.name, kw::UnderscoreLifetime);
2284 hir::LifetimeKind::Infer
2285 }
2286 LifetimeRes::Static { .. } => {
2287 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
2288 hir::LifetimeKind::Static
2289 }
2290 LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
2291 LifetimeRes::ElidedAnchor { .. } => {
2292 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
2293 }
2294 }
2295 } else {
2296 hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
2297 };
2298
2299 debug!(?res);
2300 self.arena.alloc(hir::Lifetime::new(
2301 self.lower_node_id(new_id),
2302 self.lower_ident(ident),
2303 res,
2304 source,
2305 syntax,
2306 ))
2307 }
2308
2309 fn lower_generic_params_mut(
2310 &mut self,
2311 params: &[GenericParam],
2312 source: hir::GenericParamSource,
2313 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
2314 params.iter().map(move |param| self.lower_generic_param(param, source))
2315 }
2316
2317 fn lower_generic_params(
2318 &mut self,
2319 params: &[GenericParam],
2320 source: hir::GenericParamSource,
2321 ) -> &'hir [hir::GenericParam<'hir>] {
2322 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
2323 }
2324
2325 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2325u32),
::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 =
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,
AstTarget::GenericParam(param));
param_hir
}
}
}#[instrument(level = "trace", skip(self))]
2326 fn lower_generic_param(
2327 &mut self,
2328 param: &GenericParam,
2329 source: hir::GenericParamSource,
2330 ) -> hir::GenericParam<'hir> {
2331 let (name, kind) = self.lower_generic_param_kind(param, source);
2332
2333 let hir_id = self.lower_node_id(param.id);
2334 let param_attrs = ¶m.attrs;
2335 let param_span = param.span();
2336 let param_hir = hir::GenericParam {
2337 hir_id,
2338 def_id: self.local_def_id(param.id),
2339 name,
2340 span: self.lower_span(param.span()),
2341 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
2342 kind,
2343 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2344 source,
2345 };
2346 self.lower_attrs(hir_id, param_attrs, param_span, AstTarget::GenericParam(param));
2347 param_hir
2348 }
2349
2350 fn lower_generic_param_kind(
2351 &mut self,
2352 param: &GenericParam,
2353 source: hir::GenericParamSource,
2354 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2355 match ¶m.kind {
2356 GenericParamKind::Lifetime => {
2357 let ident = self.lower_ident(param.ident);
2360 let param_name = if let Some(LifetimeRes::Error(..)) =
2361 self.curr_owner.owner.get_lifetime_res(param.id)
2362 {
2363 ParamName::Error(ident)
2364 } else {
2365 ParamName::Plain(ident)
2366 };
2367 let kind =
2368 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2369
2370 (param_name, kind)
2371 }
2372 GenericParamKind::Type { default, .. } => {
2373 let default = default
2376 .as_ref()
2377 .filter(|_| match source {
2378 hir::GenericParamSource::Generics => true,
2379 hir::GenericParamSource::Binder => {
2380 self.dcx().emit_err(diagnostics::GenericParamDefaultInBinder {
2381 span: param.span(),
2382 });
2383
2384 false
2385 }
2386 })
2387 .map(|def| {
2388 self.lower_ty_alloc(
2389 def,
2390 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2391 )
2392 });
2393
2394 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2395
2396 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2397 }
2398 GenericParamKind::Const { ty, span: _, default } => {
2399 let ty = self.lower_ty_alloc(
2400 ty,
2401 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2402 );
2403
2404 let default = default
2407 .as_ref()
2408 .filter(|anon_const| match source {
2409 hir::GenericParamSource::Generics => true,
2410 hir::GenericParamSource::Binder => {
2411 let err =
2412 diagnostics::GenericParamDefaultInBinder { span: param.span() };
2413 if expr::WillCreateDefIdsVisitor
2414 .visit_expr(&anon_const.value)
2415 .is_break()
2416 {
2417 self.dcx().emit_fatal(err)
2421 } else {
2422 self.dcx().emit_err(err);
2423 false
2424 }
2425 }
2426 })
2427 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2428
2429 (
2430 hir::ParamName::Plain(self.lower_ident(param.ident)),
2431 hir::GenericParamKind::Const { ty, default, arg_pos: None },
2432 )
2433 }
2434 }
2435 }
2436
2437 fn lower_trait_ref(
2438 &mut self,
2439 modifiers: ast::TraitBoundModifiers,
2440 p: &TraitRef,
2441 itctx: ImplTraitContext,
2442 ) -> hir::TraitRef<'hir> {
2443 let path = match self.lower_qpath(
2444 p.ref_id,
2445 &None,
2446 &p.path,
2447 ParamMode::Explicit,
2448 AllowReturnTypeNotation::No,
2449 itctx,
2450 Some(modifiers),
2451 ) {
2452 hir::QPath::Resolved(None, path) => path,
2453 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2454 };
2455 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2456 }
2457
2458 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2458u32),
::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))]
2459 fn lower_poly_trait_ref(
2460 &mut self,
2461 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2462 rbp: RelaxedBoundPolicy<'_>,
2463 itctx: ImplTraitContext,
2464 ) -> hir::PolyTraitRef<'hir> {
2465 let bound_generic_params =
2466 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2467 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2468 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2469
2470 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2471 self.validate_relaxed_bound(trait_ref, *span, rbp);
2472 }
2473
2474 hir::PolyTraitRef {
2475 bound_generic_params,
2476 modifiers,
2477 trait_ref,
2478 span: self.lower_span(*span),
2479 }
2480 }
2481
2482 fn validate_relaxed_bound(
2483 &self,
2484 trait_ref: hir::TraitRef<'_>,
2485 span: Span,
2486 rbp: RelaxedBoundPolicy<'_>,
2487 ) {
2488 match rbp {
2498 RelaxedBoundPolicy::Allowed(dedup_map) => {
2499 let Some(trait_def_id) = trait_ref.trait_def_id() else { return };
2501 let tcx = self.tcx;
2502 let err = |s| {
2503 let name = tcx.item_name(trait_def_id);
2504 tcx.dcx()
2505 .struct_span_err(
2506 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[span, s]))vec![span, s],
2507 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("duplicate relaxed `{0}` bounds",
name))
})format!("duplicate relaxed `{name}` bounds"),
2508 )
2509 .with_code(E0203)
2510 .emit();
2511 };
2512 dedup_map.entry(trait_def_id).and_modify(|&mut s| err(s)).or_insert(span);
2513 return;
2514 }
2515 RelaxedBoundPolicy::Forbidden(reason) => {
2516 let gate = |context, subject| {
2517 let extended = self.tcx.features().more_maybe_bounds();
2518 let is_sized = trait_ref
2519 .trait_def_id()
2520 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, LangItem::Sized));
2521
2522 if extended && !is_sized {
2523 return;
2524 }
2525
2526 let prefix = if extended { "`Sized` " } else { "" };
2527 let mut diag = self.dcx().struct_span_err(
2528 span,
2529 ::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}"),
2530 );
2531 if is_sized {
2532 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!(
2533 "{subject} are not implicitly bounded by `Sized`, \
2534 so there is nothing to relax"
2535 ));
2536 }
2537 diag.emit();
2538 };
2539
2540 match reason {
2541 RelaxedBoundForbiddenReason::TraitObjectTy => {
2542 gate("trait object types", "trait object types");
2543 return;
2544 }
2545 RelaxedBoundForbiddenReason::SuperTrait => {
2546 gate("supertrait bounds", "traits");
2547 return;
2548 }
2549 RelaxedBoundForbiddenReason::TraitAlias => {
2550 gate("trait alias bounds", "trait aliases");
2551 return;
2552 }
2553 RelaxedBoundForbiddenReason::AssocTyBounds
2554 | RelaxedBoundForbiddenReason::WhereBound => {}
2555 };
2556 }
2557 }
2558
2559 self.dcx()
2560 .struct_span_err(span, "this relaxed bound is not permitted here")
2561 .with_note(
2562 "in this context, relaxed bounds are only allowed on \
2563 type parameters defined on the closest item",
2564 )
2565 .emit();
2566 }
2567
2568 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2568u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:2568",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2568u32),
::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)]
2569 fn lower_param_bounds(
2570 &mut self,
2571 bounds: &[GenericBound],
2572 rbp: RelaxedBoundPolicy<'_>,
2573 itctx: ImplTraitContext,
2574 ) -> hir::GenericBounds<'hir> {
2575 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2576 }
2577
2578 fn lower_param_bounds_mut(
2579 &mut self,
2580 bounds: &[GenericBound],
2581 mut rbp: RelaxedBoundPolicy<'_>,
2582 itctx: ImplTraitContext,
2583 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2584 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp.reborrow(), itctx))
2585 }
2586
2587 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2587u32),
::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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:2587",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2587u32),
::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)]
2588 fn lower_universal_param_and_bounds(
2589 &mut self,
2590 node_id: NodeId,
2591 span: Span,
2592 ident: Ident,
2593 bounds: &[GenericBound],
2594 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2595 let def_id = self.local_def_id(node_id);
2597 let span = self.lower_span(span);
2598
2599 let param = hir::GenericParam {
2601 hir_id: self.lower_node_id(node_id),
2602 def_id,
2603 name: ParamName::Plain(self.lower_ident(ident)),
2604 pure_wrt_drop: false,
2605 span,
2606 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2607 colon_span: None,
2608 source: hir::GenericParamSource::Generics,
2609 };
2610
2611 let preds = self.lower_generic_bound_predicate(
2612 ident,
2613 node_id,
2614 &GenericParamKind::Type { default: None },
2615 bounds,
2616 None,
2617 span,
2618 RelaxedBoundPolicy::Allowed(&mut Default::default()),
2619 ImplTraitContext::Universal,
2620 hir::PredicateOrigin::ImplTrait,
2621 );
2622
2623 let hir_id = self.next_id();
2624 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2625 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2626 None,
2627 self.arena.alloc(hir::Path {
2628 span,
2629 res,
2630 segments:
2631 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2632 }),
2633 ));
2634
2635 (param, preds, ty)
2636 }
2637
2638 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2641 let block = self.lower_block(b, false);
2642 self.expr_block(block)
2643 }
2644
2645 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2646 match c.value.peel_parens().kind {
2653 ExprKind::Underscore => {
2654 let ct_kind = hir::ConstArgKind::Infer(());
2655 self.arena.alloc(hir::ConstArg {
2656 hir_id: self.lower_node_id(c.id),
2657 kind: ct_kind,
2658 span: self.lower_span(c.value.span),
2659 })
2660 }
2661 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2662 }
2663 }
2664
2665 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2668u32),
::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))]
2669 fn lower_const_path_to_const_arg(
2670 &mut self,
2671 qself: &Option<Box<QSelf>>,
2672 path: &Path,
2673 res: Res<NodeId>,
2674 id: NodeId,
2675 span: Span,
2676 ) -> hir::ConstArg<'hir> {
2677 let context = self.ambient_direct_const_arg_context();
2678 if self.can_lower_path_to_const_arg_direct(qself, path, span, Some(res), context).is_ok() {
2679 let span = self.lower_span(span);
2680 self.lower_path_to_const_arg_direct(id, None, qself, path, span)
2681 } else {
2682 let node_id = self.next_node_id();
2684 let span = self.lower_span(span);
2685
2686 let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2691 let hir_id = self.lower_node_id(node_id);
2692
2693 let path_expr = Expr {
2694 id,
2695 kind: ExprKind::Path(qself.clone(), path.clone()),
2696 span,
2697 attrs: AttrVec::new(),
2698 tokens: None,
2699 };
2700
2701 let ct = self.with_new_scopes(span, |this| {
2702 self.arena.alloc(hir::AnonConst {
2703 def_id,
2704 hir_id,
2705 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2706 span,
2707 })
2708 });
2709 hir::ConstArg {
2710 hir_id: self.next_id(),
2711 kind: hir::ConstArgKind::Anon(ct),
2712 span: self.lower_span(span),
2713 }
2714 }
2715 }
2716
2717 fn lower_const_item_rhs(
2718 &mut self,
2719 body: &Option<Box<Expr>>,
2720 span: Span,
2721 ) -> hir::ConstItemRhs<'hir> {
2722 let is_direct = |body| {
2723 let context = if self.tcx.features().gca_macroless_items() {
2724 self.direct_const_arg_context_enabled_by_gca_macro()
2725 } else {
2726 DirectConstArgContext::GCA_MACRO
2727 };
2728 self.can_lower_expr_to_const_arg_direct(body, context).is_ok()
2729 };
2730 if self.tcx.features().gca_min_const_items()
2731 && let Some(body) = body
2732 && is_direct(body)
2733 {
2734 hir::ConstItemRhs::Direct(
2735 self.arena.alloc(self.lower_expr_to_const_arg_direct(&body, None)),
2736 )
2737 } else {
2738 hir::ConstItemRhs::Body(self.lower_const_body(span, body.as_deref()))
2739 }
2740 }
2741
2742 fn direct_const_arg_context_enabled_by_gca_macro(&self) -> DirectConstArgContext {
2743 let mut result = DirectConstArgContext::GCA_BASE_FEATURES;
2744 if self.tcx.features().gca_min_const_items() {
2745 result |= DirectConstArgContext::GCA_MIN_CONST_ITEMS;
2746 }
2747 if self.tcx.features().gca_adts() {
2748 result |= DirectConstArgContext::GCA_ADTS;
2749 }
2750 result
2751 }
2752
2753 fn ambient_direct_const_arg_context(&self) -> DirectConstArgContext {
2755 if self.tcx.features().gca_macroless_args() {
2756 self.direct_const_arg_context_enabled_by_gca_macro()
2757 } else if self.tcx.features().gca() {
2758 DirectConstArgContext::GCA
2759 } else {
2760 DirectConstArgContext::STABLE
2761 }
2762 }
2763
2764 fn can_lower_path_to_const_arg_direct(
2765 &self,
2766 qself: &Option<Box<QSelf>>,
2767 path: &Path,
2768 span: Span,
2769 res: Option<Res<NodeId>>,
2770 context: DirectConstArgContext,
2771 ) -> Result<(), UnrepresentableConstArgError> {
2772 if context.contains(DirectConstArgContext::PATH_ANY) {
2773 Ok(())
2774 } else if context.contains(DirectConstArgContext::PATH_CONST_CTOR)
2775 && #[allow(non_exhaustive_omitted_patterns)] match res {
Some(Res::Def(DefKind::Ctor(_, CtorKind::Const), _)) => true,
_ => false,
}matches!(res, Some(Res::Def(DefKind::Ctor(_, CtorKind::Const), _)))
2776 {
2777 Ok(())
2780 } else if context.contains(DirectConstArgContext::PATH_PLAIN_PARAM)
2781 && qself.is_none()
2782 && path.is_single_argless_ident()
2783 && #[allow(non_exhaustive_omitted_patterns)] match res {
Some(Res::Def(DefKind::ConstParam, _)) => true,
_ => false,
}matches!(res, Some(Res::Def(DefKind::ConstParam, _)))
2784 {
2785 Ok(())
2786 } else {
2787 Err(UnrepresentableConstArgError { span, will_create_def_ids: false })
2788 }
2789 }
2790
2791 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2791u32),
::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;
}
{
match &expr.kind {
ExprKind::Call(Expr { kind: ExprKind::Path(_, _), .. },
args) if context.contains(DirectConstArgContext::TUPLE_CALL)
=> {
for arg in args {
self.can_lower_expr_to_const_arg_direct(arg, context)?;
}
Ok(())
}
ExprKind::Tup(exprs) if
context.contains(DirectConstArgContext::TUPLE) => {
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) if
context.contains(DirectConstArgContext::STRUCT) => {
for f in &se.fields {
self.can_lower_expr_to_const_arg_direct(&f.expr, context)?;
}
Ok(())
}
ExprKind::Array(elements) if
context.contains(DirectConstArgContext::ARRAY) => {
for element in elements {
self.can_lower_expr_to_const_arg_direct(element, context)?;
}
Ok(())
}
ExprKind::Underscore if
context.contains(DirectConstArgContext::UNDERSCORE) =>
Ok(()),
ExprKind::Paren(expr) if
context.contains(DirectConstArgContext::PAREN) => {
self.can_lower_expr_to_const_arg_direct(expr, context)
}
ExprKind::Block(block, _) if
context.contains(DirectConstArgContext::BLOCK) &&
let [stmt] = block.stmts.as_slice() &&
let StmtKind::Expr(expr) = &stmt.kind => {
self.can_lower_expr_to_const_arg_direct(expr, context)
}
ExprKind::Lit(_) if
context.contains(DirectConstArgContext::LIT) => Ok(()),
ExprKind::Unary(UnOp::Neg, inner_expr) if
context.contains(DirectConstArgContext::LIT) &&
let ExprKind::Lit(_) = &inner_expr.kind => {
Ok(())
}
ExprKind::ConstBlock(_) if
context.contains(DirectConstArgContext::CONST_BLOCK) => {
Ok(())
}
ExprKind::GcaMacro(_) if
context.contains(DirectConstArgContext::GCA_MACRO) => {
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:2791",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2791u32),
::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)]
2792 fn can_lower_expr_to_const_arg_direct(
2793 &self,
2794 expr: &Expr,
2795 context: DirectConstArgContext,
2796 ) -> Result<(), UnrepresentableConstArgError> {
2797 match &expr.kind {
2799 ExprKind::Call(Expr { kind: ExprKind::Path(_, _), .. }, args)
2800 if context.contains(DirectConstArgContext::TUPLE_CALL) =>
2801 {
2802 for arg in args {
2803 self.can_lower_expr_to_const_arg_direct(arg, context)?;
2804 }
2805 Ok(())
2806 }
2807 ExprKind::Tup(exprs) if context.contains(DirectConstArgContext::TUPLE) => {
2808 for expr in exprs {
2809 self.can_lower_expr_to_const_arg_direct(expr, context)?;
2810 }
2811 Ok(())
2812 }
2813 ExprKind::Path(qself, path) => {
2814 let res =
2815 self.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2816 self.can_lower_path_to_const_arg_direct(qself, path, expr.span, res, context)
2817 }
2818 ExprKind::Struct(se) if context.contains(DirectConstArgContext::STRUCT) => {
2819 for f in &se.fields {
2820 self.can_lower_expr_to_const_arg_direct(&f.expr, context)?;
2821 }
2822 Ok(())
2823 }
2824 ExprKind::Array(elements) if context.contains(DirectConstArgContext::ARRAY) => {
2825 for element in elements {
2826 self.can_lower_expr_to_const_arg_direct(element, context)?;
2827 }
2828 Ok(())
2829 }
2830 ExprKind::Underscore if context.contains(DirectConstArgContext::UNDERSCORE) => Ok(()),
2831 ExprKind::Paren(expr) if context.contains(DirectConstArgContext::PAREN) => {
2832 self.can_lower_expr_to_const_arg_direct(expr, context)
2833 }
2834 ExprKind::Block(block, _)
2835 if context.contains(DirectConstArgContext::BLOCK)
2836 && let [stmt] = block.stmts.as_slice()
2837 && let StmtKind::Expr(expr) = &stmt.kind =>
2838 {
2839 self.can_lower_expr_to_const_arg_direct(expr, context)
2840 }
2841 ExprKind::Lit(_) if context.contains(DirectConstArgContext::LIT) => Ok(()),
2842 ExprKind::Unary(UnOp::Neg, inner_expr)
2843 if context.contains(DirectConstArgContext::LIT)
2844 && let ExprKind::Lit(_) = &inner_expr.kind =>
2845 {
2846 Ok(())
2847 }
2848 ExprKind::ConstBlock(_) if context.contains(DirectConstArgContext::CONST_BLOCK) => {
2849 Ok(())
2850 }
2851 ExprKind::GcaMacro(_) if context.contains(DirectConstArgContext::GCA_MACRO) => {
2852 Ok(())
2855 }
2856 _ => Err(UnrepresentableConstArgError::new(expr)),
2857 }
2858 }
2859
2860 fn lower_path_to_const_arg_direct(
2863 &mut self,
2864 id: NodeId,
2865 id_override: Option<NodeId>,
2866 qself: &Option<Box<QSelf>>,
2867 path: &Path,
2868 span: Span,
2869 ) -> hir::ConstArg<'hir> {
2870 let qpath = self.lower_qpath(
2871 id,
2872 qself,
2873 path,
2874 ParamMode::Explicit,
2875 AllowReturnTypeNotation::No,
2876 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2878 None,
2879 );
2880
2881 let node_id = id_override.unwrap_or(id);
2882 ConstArg { hir_id: self.lower_node_id(node_id), kind: hir::ConstArgKind::Path(qpath), span }
2883 }
2884
2885 {}
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2887u32),
::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|
self.lower_expr_to_const_arg_direct(arg, None)));
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|
self.lower_expr_to_const_arg_direct(expr, None)));
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,
AstTarget::ExprField(f));
let expr =
self.lower_expr_to_const_arg_direct(&f.expr, None);
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|
self.lower_expr_to_const_arg_direct(element, None)));
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,
self.direct_const_arg_context_enabled_by_gca_macro()) {
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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:2887",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2887u32),
::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)]
2888 fn lower_expr_to_const_arg_direct(
2889 &mut self,
2890 expr: &Expr,
2891 id_override: Option<NodeId>,
2892 ) -> hir::ConstArg<'hir> {
2893 let span = self.lower_span(expr.span);
2894 let node_id = id_override.unwrap_or(expr.id);
2895 match &expr.kind {
2896 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2897 let qpath = self.lower_qpath(
2898 func.id,
2899 qself,
2900 path,
2901 ParamMode::Explicit,
2902 AllowReturnTypeNotation::No,
2903 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2904 None,
2905 );
2906
2907 let lowered_args = self.arena.alloc_from_iter(
2908 args.iter().map(|arg| self.lower_expr_to_const_arg_direct(arg, None)),
2909 );
2910
2911 ConstArg {
2912 hir_id: self.lower_node_id(node_id),
2913 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2914 span,
2915 }
2916 }
2917 ExprKind::Tup(exprs) => {
2918 let exprs = self.arena.alloc_from_iter(
2919 exprs.iter().map(|expr| self.lower_expr_to_const_arg_direct(expr, None)),
2920 );
2921
2922 ConstArg {
2923 hir_id: self.lower_node_id(node_id),
2924 kind: hir::ConstArgKind::Tup(exprs),
2925 span,
2926 }
2927 }
2928 ExprKind::Path(qself, path) => {
2929 self.lower_path_to_const_arg_direct(expr.id, id_override, qself, path, span)
2930 }
2931 ExprKind::Struct(se) => {
2932 let path = self.lower_qpath(
2933 expr.id,
2934 &se.qself,
2935 &se.path,
2936 ParamMode::Explicit,
2940 AllowReturnTypeNotation::No,
2941 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2942 None,
2943 );
2944
2945 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2946 let hir_id = self.lower_node_id(f.id);
2947 self.lower_attrs(hir_id, &f.attrs, f.span, AstTarget::ExprField(f));
2951 let expr = self.lower_expr_to_const_arg_direct(&f.expr, None);
2952
2953 hir::ConstArgExprField {
2954 hir_id,
2955 field: self.lower_ident(f.ident),
2956 expr: self.arena.alloc(expr),
2957 span: self.lower_span(f.span),
2958 }
2959 }));
2960
2961 ConstArg {
2962 hir_id: self.lower_node_id(node_id),
2963 kind: hir::ConstArgKind::Struct(path, fields),
2964 span,
2965 }
2966 }
2967 ExprKind::Array(elements) => {
2968 let lowered_elems = self.arena.alloc_from_iter(
2969 elements
2970 .iter()
2971 .map(|element| self.lower_expr_to_const_arg_direct(element, None)),
2972 );
2973 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
2974 span: self.lower_span(expr.span),
2975 elems: lowered_elems,
2976 });
2977
2978 ConstArg {
2979 hir_id: self.lower_node_id(node_id),
2980 kind: hir::ConstArgKind::Array(array_expr),
2981 span,
2982 }
2983 }
2984 ExprKind::Underscore => ConstArg {
2985 hir_id: self.lower_node_id(node_id),
2986 kind: hir::ConstArgKind::Infer(()),
2987 span,
2988 },
2989 ExprKind::Paren(expr) => self.lower_expr_to_const_arg_direct(expr, id_override),
2990 ExprKind::Block(block, _)
2991 if let [stmt] = block.stmts.as_slice()
2992 && let StmtKind::Expr(expr) = &stmt.kind =>
2993 {
2994 self.lower_expr_to_const_arg_direct(expr, id_override)
2995 }
2996 ExprKind::Lit(literal) => {
2997 let span = self.lower_span(expr.span);
2998 let literal = self.lower_lit(literal, span);
2999
3000 ConstArg {
3001 hir_id: self.lower_node_id(node_id),
3002 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
3003 span,
3004 }
3005 }
3006 ExprKind::Unary(UnOp::Neg, inner_expr)
3007 if let ExprKind::Lit(literal) = &inner_expr.kind =>
3008 {
3009 let span = self.lower_span(expr.span);
3010 let literal = self.lower_lit(literal, span);
3011
3012 let kind = if !matches!(literal.node, LitKind::Int(..)) {
3013 let err = self.dcx().span_err(expr.span, "negated literal must be an integer");
3014 hir::ConstArgKind::Error(err)
3015 } else {
3016 hir::ConstArgKind::Literal { lit: literal.node, negated: true }
3017 };
3018 ConstArg { hir_id: self.lower_node_id(node_id), kind, span }
3019 }
3020 ExprKind::ConstBlock(anon_const) => {
3021 let def_id = self.local_def_id(anon_const.id);
3024 assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
3025 let lowered_anon = self.lower_anon_const_to_anon_const(anon_const, span);
3026 ConstArg {
3027 hir_id: self.lower_node_id(node_id),
3028 kind: hir::ConstArgKind::Anon(lowered_anon),
3029 span,
3030 }
3031 }
3032 ExprKind::GcaMacro(expr) => {
3033 match self.can_lower_expr_to_const_arg_direct(
3037 expr,
3038 self.direct_const_arg_context_enabled_by_gca_macro(),
3039 ) {
3040 Ok(()) => self.lower_expr_to_const_arg_direct(expr, id_override),
3041 Err(err) => err.emit(self),
3042 }
3043 }
3044 _ => {
3045 span_bug!(
3046 expr.span,
3047 "lower_expr_to_const_arg_direct encountered an unlowerable expression, either \
3048 can_lower_expr_to_const_arg_direct returned Ok() on something it shouldn't \
3049 have, or you forgot to check can_lower_expr_to_const_arg_direct first"
3050 );
3051 }
3052 }
3053 }
3054
3055 fn lower_anon_const_to_const_arg_and_alloc(
3058 &mut self,
3059 anon: &AnonConst,
3060 ) -> &'hir hir::ConstArg<'hir> {
3061 self.arena.alloc(self.lower_anon_const_to_const_arg(anon))
3062 }
3063
3064 {}
#[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/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(3064u32),
::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))]
3065 fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
3066 let expr = if self.tcx.features().gca_macroless_args() {
3069 &anon.value
3070 } else {
3071 anon.value.maybe_unwrap_block()
3072 };
3073
3074 let context = self.ambient_direct_const_arg_context();
3075 if self.can_lower_expr_to_const_arg_direct(expr, context).is_ok() {
3076 return self.lower_expr_to_const_arg_direct(expr, Some(anon.id));
3077 }
3078
3079 let lowered_anon = self.lower_anon_const_to_anon_const(anon, anon.value.span);
3080 ConstArg {
3081 hir_id: self.next_id(),
3082 kind: hir::ConstArgKind::Anon(lowered_anon),
3083 span: self.lower_span(anon.value.span),
3084 }
3085 }
3086
3087 fn lower_anon_const_to_anon_const(
3090 &mut self,
3091 c: &AnonConst,
3092 span: Span,
3093 ) -> &'hir hir::AnonConst {
3094 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
3095 let def_id = this.local_def_id(c.id);
3096 let hir_id = this.lower_node_id(c.id);
3097 hir::AnonConst {
3098 def_id,
3099 hir_id,
3100 body: this.lower_const_body(c.value.span, Some(&c.value)),
3101 span: this.lower_span(span),
3102 }
3103 }))
3104 }
3105
3106 fn lower_unsafe_source(&self, u: UnsafeSource) -> hir::UnsafeSource {
3107 match u {
3108 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
3109 UserProvided => hir::UnsafeSource::UserProvided,
3110 }
3111 }
3112
3113 fn lower_trait_bound_modifiers(
3114 &self,
3115 modifiers: TraitBoundModifiers,
3116 ) -> hir::TraitBoundModifiers {
3117 let constness = match modifiers.constness {
3118 BoundConstness::Never => BoundConstness::Never,
3119 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
3120 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
3121 };
3122 let polarity = match modifiers.polarity {
3123 BoundPolarity::Positive => BoundPolarity::Positive,
3124 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
3125 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
3126 };
3127 hir::TraitBoundModifiers { constness, polarity }
3128 }
3129
3130 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
3133 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
3134 }
3135
3136 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
3137 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
3138 }
3139
3140 fn stmt_let_pat(
3141 &mut self,
3142 attrs: Option<&'hir [rustc_attr_ir::Attribute]>,
3143 span: Span,
3144 init: Option<&'hir hir::Expr<'hir>>,
3145 pat: &'hir hir::Pat<'hir>,
3146 source: hir::LocalSource,
3147 ) -> hir::Stmt<'hir> {
3148 let hir_id = self.next_id();
3149 if let Some(a) = attrs {
3150 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
3151 self.curr_owner.attrs.insert(hir_id.local_id, a);
3152 }
3153 let local = hir::LetStmt {
3154 super_: None,
3155 hir_id,
3156 init,
3157 pat,
3158 els: None,
3159 source,
3160 span: self.lower_span(span),
3161 ty: None,
3162 };
3163 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
3164 }
3165
3166 fn stmt_super_let_pat(
3167 &mut self,
3168 span: Span,
3169 pat: &'hir hir::Pat<'hir>,
3170 init: Option<&'hir hir::Expr<'hir>>,
3171 ) -> hir::Stmt<'hir> {
3172 let hir_id = self.next_id();
3173 let span = self.lower_span(span);
3174 let local = hir::LetStmt {
3175 super_: Some(span),
3176 hir_id,
3177 init,
3178 pat,
3179 els: None,
3180 source: hir::LocalSource::Normal,
3181 span,
3182 ty: None,
3183 };
3184 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
3185 }
3186
3187 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
3188 self.block_all(expr.span, &[], Some(expr))
3189 }
3190
3191 fn block_all(
3192 &mut self,
3193 span: Span,
3194 stmts: &'hir [hir::Stmt<'hir>],
3195 expr: Option<&'hir hir::Expr<'hir>>,
3196 ) -> &'hir hir::Block<'hir> {
3197 let blk = hir::Block {
3198 stmts,
3199 expr,
3200 hir_id: self.next_id(),
3201 rules: hir::BlockCheckMode::DefaultBlock,
3202 span: self.lower_span(span),
3203 targeted_by_break: false,
3204 };
3205 self.arena.alloc(blk)
3206 }
3207
3208 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3209 let field = self.single_pat_field(span, pat);
3210 self.pat_lang_item_variant(span, LangItem::ControlFlowContinue, field)
3211 }
3212
3213 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3214 let field = self.single_pat_field(span, pat);
3215 self.pat_lang_item_variant(span, LangItem::ControlFlowBreak, field)
3216 }
3217
3218 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3219 let field = self.single_pat_field(span, pat);
3220 self.pat_lang_item_variant(span, LangItem::OptionSome, field)
3221 }
3222
3223 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
3224 self.pat_lang_item_variant(span, LangItem::OptionNone, &[])
3225 }
3226
3227 fn single_pat_field(
3228 &mut self,
3229 span: Span,
3230 pat: &'hir hir::Pat<'hir>,
3231 ) -> &'hir [hir::PatField<'hir>] {
3232 let field = hir::PatField {
3233 hir_id: self.next_id(),
3234 ident: Ident::new(sym::integer(0), self.lower_span(span)),
3235 is_shorthand: false,
3236 pat,
3237 span: self.lower_span(span),
3238 };
3239 self.arena.alloc_from_iter([field])arena_vec![self; field]
3240 }
3241
3242 fn pat_lang_item_variant(
3243 &mut self,
3244 span: Span,
3245 lang_item: LangItem,
3246 fields: &'hir [hir::PatField<'hir>],
3247 ) -> &'hir hir::Pat<'hir> {
3248 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
3249 self.pat(span, hir::PatKind::Struct(path, fields, None))
3250 }
3251
3252 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
3253 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
3254 }
3255
3256 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
3257 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
3258 }
3259
3260 fn pat_ident_binding_mode(
3261 &mut self,
3262 span: Span,
3263 ident: Ident,
3264 bm: hir::BindingMode,
3265 ) -> (&'hir hir::Pat<'hir>, HirId) {
3266 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
3267 (self.arena.alloc(pat), hir_id)
3268 }
3269
3270 fn pat_ident_binding_mode_mut(
3271 &mut self,
3272 span: Span,
3273 ident: Ident,
3274 bm: hir::BindingMode,
3275 ) -> (hir::Pat<'hir>, HirId) {
3276 let hir_id = self.next_id();
3277
3278 (
3279 hir::Pat {
3280 hir_id,
3281 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
3282 span: self.lower_span(span),
3283 default_binding_modes: true,
3284 },
3285 hir_id,
3286 )
3287 }
3288
3289 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
3290 self.arena.alloc(hir::Pat {
3291 hir_id: self.next_id(),
3292 kind,
3293 span: self.lower_span(span),
3294 default_binding_modes: true,
3295 })
3296 }
3297
3298 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
3299 hir::Pat {
3300 hir_id: self.next_id(),
3301 kind,
3302 span: self.lower_span(span),
3303 default_binding_modes: false,
3304 }
3305 }
3306
3307 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
3308 let kind = match qpath {
3309 hir::QPath::Resolved(None, path) => {
3310 match path.res {
3312 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
3313 let principal = hir::PolyTraitRef {
3314 bound_generic_params: &[],
3315 modifiers: hir::TraitBoundModifiers::NONE,
3316 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
3317 span: self.lower_span(span),
3318 };
3319
3320 hir_id = self.next_id();
3323 hir::TyKind::TraitObject(
3324 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
3325 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
3326 )
3327 }
3328 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
3329 }
3330 }
3331 _ => hir::TyKind::Path(qpath),
3332 };
3333
3334 hir::Ty { hir_id, kind, span: self.lower_span(span) }
3335 }
3336
3337 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
3342 let r = hir::Lifetime::new(
3343 self.next_id(),
3344 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
3345 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
3346 LifetimeSource::Other,
3347 LifetimeSyntax::Implicit,
3348 );
3349 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs:3349",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(3349u32),
::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);
3350 self.arena.alloc(r)
3351 }
3352}
3353
3354struct GenericArgsCtor<'hir> {
3356 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
3357 constraints: &'hir [hir::AssocItemConstraint<'hir>],
3358 parenthesized: hir::GenericArgsParentheses,
3359 span: Span,
3360}
3361
3362impl<'hir> GenericArgsCtor<'hir> {
3363 fn is_empty(&self) -> bool {
3364 self.args.is_empty()
3365 && self.constraints.is_empty()
3366 && self.parenthesized == hir::GenericArgsParentheses::No
3367 }
3368
3369 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
3370 let ga = hir::GenericArgs {
3371 args: this.arena.alloc_from_iter(self.args),
3372 constraints: self.constraints,
3373 parenthesized: self.parenthesized,
3374 span_ext: this.lower_span(self.span),
3375 };
3376 this.arena.alloc(ga)
3377 }
3378}
3379
3380struct DirectConstArgContext(<DirectConstArgContext as
::bitflags::__private::PublicFlags>::Internal);
#[automatically_derived]impl ::core::marker::Copy for DirectConstArgContext {
}
#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DirectConstArgContext {
}
#[automatically_derived]impl ::core::clone::Clone for DirectConstArgContext {
#[inline]
fn clone(&self) -> Self {
let _:
::core::clone::AssertParamIsClone<<DirectConstArgContext as
::bitflags::__private::PublicFlags>::Internal>;
*self
}
}
#[automatically_derived]impl ::core::fmt::Debug for DirectConstArgContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DirectConstArgContext", &&self.0)
}
}
impl DirectConstArgContext {
#[allow(deprecated, non_upper_case_globals,)]
pub const TUPLE_CALL: Self = Self::from_bits_retain(1 << 0);
#[allow(deprecated, non_upper_case_globals,)]
pub const TUPLE: Self = Self::from_bits_retain(1 << 1);
#[allow(deprecated, non_upper_case_globals,)]
pub const PATH_PLAIN_PARAM: Self = Self::from_bits_retain(1 << 2);
#[allow(deprecated, non_upper_case_globals,)]
pub const PATH_CONST_CTOR: Self = Self::from_bits_retain(1 << 3);
#[allow(deprecated, non_upper_case_globals,)]
pub const PATH_ANY: Self = Self::from_bits_retain(1 << 4);
#[allow(deprecated, non_upper_case_globals,)]
pub const STRUCT: Self = Self::from_bits_retain(1 << 5);
#[allow(deprecated, non_upper_case_globals,)]
pub const ARRAY: Self = Self::from_bits_retain(1 << 6);
#[allow(deprecated, non_upper_case_globals,)]
pub const UNDERSCORE: Self = Self::from_bits_retain(1 << 7);
#[allow(deprecated, non_upper_case_globals,)]
pub const PAREN: Self = Self::from_bits_retain(1 << 8);
#[allow(deprecated, non_upper_case_globals,)]
pub const BLOCK: Self = Self::from_bits_retain(1 << 9);
#[allow(deprecated, non_upper_case_globals,)]
pub const LIT: Self = Self::from_bits_retain(1 << 10);
#[allow(deprecated, non_upper_case_globals,)]
pub const CONST_BLOCK: Self = Self::from_bits_retain(1 << 11);
#[allow(deprecated, non_upper_case_globals,)]
pub const GCA_MACRO: Self = Self::from_bits_retain(1 << 12);
}
impl ::bitflags::Flags for DirectConstArgContext {
const FLAGS: &'static [::bitflags::Flag<DirectConstArgContext>] =
&[{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("TUPLE_CALL",
DirectConstArgContext::TUPLE_CALL)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("TUPLE", DirectConstArgContext::TUPLE)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("PATH_PLAIN_PARAM",
DirectConstArgContext::PATH_PLAIN_PARAM)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("PATH_CONST_CTOR",
DirectConstArgContext::PATH_CONST_CTOR)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("PATH_ANY",
DirectConstArgContext::PATH_ANY)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("STRUCT",
DirectConstArgContext::STRUCT)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("ARRAY", DirectConstArgContext::ARRAY)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("UNDERSCORE",
DirectConstArgContext::UNDERSCORE)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("PAREN", DirectConstArgContext::PAREN)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("BLOCK", DirectConstArgContext::BLOCK)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("LIT", DirectConstArgContext::LIT)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("CONST_BLOCK",
DirectConstArgContext::CONST_BLOCK)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("GCA_MACRO",
DirectConstArgContext::GCA_MACRO)
}];
type Bits = u16;
fn bits(&self) -> u16 { DirectConstArgContext::bits(self) }
fn from_bits_retain(bits: u16) -> DirectConstArgContext {
DirectConstArgContext::from_bits_retain(bits)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: indexing_slicing, clippy :: same_name_method,
clippy :: iter_without_into_iter,)]
const _: () =
{
#[repr(transparent)]
struct InternalBitFlags(u16);
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InternalBitFlags { }
#[automatically_derived]
impl ::core::clone::Clone for InternalBitFlags {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u16>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for InternalBitFlags { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for InternalBitFlags { }
#[automatically_derived]
impl ::core::cmp::PartialEq for InternalBitFlags {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for InternalBitFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u16>;
}
}
#[automatically_derived]
impl ::core::cmp::PartialOrd for InternalBitFlags {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self,
other))
}
}
#[automatically_derived]
impl ::core::cmp::Ord for InternalBitFlags {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}
#[automatically_derived]
impl ::core::hash::Hash for InternalBitFlags {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
impl ::bitflags::__private::PublicFlags for DirectConstArgContext {
type Primitive = u16;
type Internal = InternalBitFlags;
}
impl ::bitflags::__private::core::default::Default for
InternalBitFlags {
#[inline]
fn default() -> Self { InternalBitFlags::empty() }
}
impl ::bitflags::__private::core::fmt::Debug for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
if self.is_empty() {
f.write_fmt(format_args!("{0:#x}",
<u16 as ::bitflags::Bits>::EMPTY))
} else {
::bitflags::__private::core::fmt::Display::fmt(self, f)
}
}
}
impl ::bitflags::__private::core::fmt::Display for InternalBitFlags {
fn fmt(&self,
f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
-> ::bitflags::__private::core::fmt::Result {
::bitflags::parser::to_writer(&DirectConstArgContext(*self),
f)
}
}
impl ::bitflags::__private::core::str::FromStr for InternalBitFlags {
type Err = ::bitflags::parser::ParseError;
fn from_str(s: &str)
->
::bitflags::__private::core::result::Result<Self,
Self::Err> {
::bitflags::parser::from_str::<DirectConstArgContext>(s).map(|flags|
flags.0)
}
}
impl ::bitflags::__private::core::convert::AsRef<u16> for
InternalBitFlags {
fn as_ref(&self) -> &u16 { &self.0 }
}
impl ::bitflags::__private::core::convert::From<u16> for
InternalBitFlags {
fn from(bits: u16) -> Self { Self::from_bits_retain(bits) }
}
#[allow(dead_code, deprecated, unused_attributes)]
impl InternalBitFlags {
#[inline]
pub const fn empty() -> Self {
Self(<u16 as ::bitflags::Bits>::EMPTY)
}
#[inline]
pub const fn all() -> Self {
let mut truncated = <u16 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<DirectConstArgContext as
::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
#[inline]
pub const fn bits(&self) -> u16 { self.0 }
#[inline]
pub const fn from_bits(bits: u16)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
#[inline]
pub const fn from_bits_truncate(bits: u16) -> Self {
Self(bits & Self::all().0)
}
#[inline]
pub const fn from_bits_retain(bits: u16) -> Self { Self(bits) }
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
{
if name == "TUPLE_CALL" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::TUPLE_CALL.bits()));
}
};
;
{
if name == "TUPLE" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::TUPLE.bits()));
}
};
;
{
if name == "PATH_PLAIN_PARAM" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::PATH_PLAIN_PARAM.bits()));
}
};
;
{
if name == "PATH_CONST_CTOR" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::PATH_CONST_CTOR.bits()));
}
};
;
{
if name == "PATH_ANY" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::PATH_ANY.bits()));
}
};
;
{
if name == "STRUCT" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::STRUCT.bits()));
}
};
;
{
if name == "ARRAY" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::ARRAY.bits()));
}
};
;
{
if name == "UNDERSCORE" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::UNDERSCORE.bits()));
}
};
;
{
if name == "PAREN" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::PAREN.bits()));
}
};
;
{
if name == "BLOCK" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::BLOCK.bits()));
}
};
;
{
if name == "LIT" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::LIT.bits()));
}
};
;
{
if name == "CONST_BLOCK" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::CONST_BLOCK.bits()));
}
};
;
{
if name == "GCA_MACRO" {
return ::bitflags::__private::core::option::Option::Some(Self(DirectConstArgContext::GCA_MACRO.bits()));
}
};
;
let _ = name;
::bitflags::__private::core::option::Option::None
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u16 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u16 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for InternalBitFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for InternalBitFlags {
type Output = Self;
#[inline]
fn bitor(self, other: InternalBitFlags) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
InternalBitFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for InternalBitFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
InternalBitFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for InternalBitFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
InternalBitFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for InternalBitFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for InternalBitFlags
{
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for InternalBitFlags {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<InternalBitFlags> for
InternalBitFlags {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<InternalBitFlags>
for InternalBitFlags {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl InternalBitFlags {
#[inline]
pub const fn iter(&self)
-> ::bitflags::iter::Iter<DirectConstArgContext> {
::bitflags::iter::Iter::__private_const_new(<DirectConstArgContext
as ::bitflags::Flags>::FLAGS,
DirectConstArgContext::from_bits_retain(self.bits()),
DirectConstArgContext::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<DirectConstArgContext> {
::bitflags::iter::IterNames::__private_const_new(<DirectConstArgContext
as ::bitflags::Flags>::FLAGS,
DirectConstArgContext::from_bits_retain(self.bits()),
DirectConstArgContext::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
InternalBitFlags {
type Item = DirectConstArgContext;
type IntoIter = ::bitflags::iter::Iter<DirectConstArgContext>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
impl InternalBitFlags {
#[inline]
pub fn bits_mut(&mut self) -> &mut u16 { &mut self.0 }
}
#[allow(dead_code, deprecated, unused_attributes)]
impl DirectConstArgContext {
#[inline]
pub const fn empty() -> Self { Self(InternalBitFlags::empty()) }
#[inline]
pub const fn all() -> Self { Self(InternalBitFlags::all()) }
#[inline]
pub const fn bits(&self) -> u16 { self.0.bits() }
#[inline]
pub const fn from_bits(bits: u16)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_bits(bits) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
#[inline]
pub const fn from_bits_truncate(bits: u16) -> Self {
Self(InternalBitFlags::from_bits_truncate(bits))
}
#[inline]
pub const fn from_bits_retain(bits: u16) -> Self {
Self(InternalBitFlags::from_bits_retain(bits))
}
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
match InternalBitFlags::from_name(name) {
::bitflags::__private::core::option::Option::Some(bits) =>
::bitflags::__private::core::option::Option::Some(Self(bits)),
::bitflags::__private::core::option::Option::None =>
::bitflags::__private::core::option::Option::None,
}
}
#[inline]
pub const fn is_empty(&self) -> bool { self.0.is_empty() }
#[inline]
pub const fn is_all(&self) -> bool { self.0.is_all() }
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0.intersects(other.0)
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0.contains(other.0)
}
#[inline]
pub fn insert(&mut self, other: Self) { self.0.insert(other.0) }
#[inline]
pub fn remove(&mut self, other: Self) { self.0.remove(other.0) }
#[inline]
pub fn toggle(&mut self, other: Self) { self.0.toggle(other.0) }
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
self.0.set(other.0, value)
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0.intersection(other.0))
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0.union(other.0))
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0.difference(other.0))
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0.symmetric_difference(other.0))
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self(self.0.complement())
}
}
impl ::bitflags::__private::core::fmt::Binary for
DirectConstArgContext {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for DirectConstArgContext
{
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for
DirectConstArgContext {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for
DirectConstArgContext {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for DirectConstArgContext
{
type Output = Self;
#[inline]
fn bitor(self, other: DirectConstArgContext) -> Self {
self.union(other)
}
}
impl ::bitflags::__private::core::ops::BitOrAssign for
DirectConstArgContext {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for
DirectConstArgContext {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for
DirectConstArgContext {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for
DirectConstArgContext {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for
DirectConstArgContext {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for DirectConstArgContext {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for
DirectConstArgContext {
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for DirectConstArgContext {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<DirectConstArgContext>
for DirectConstArgContext {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<DirectConstArgContext>
for DirectConstArgContext {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl DirectConstArgContext {
#[inline]
pub const fn iter(&self)
-> ::bitflags::iter::Iter<DirectConstArgContext> {
::bitflags::iter::Iter::__private_const_new(<DirectConstArgContext
as ::bitflags::Flags>::FLAGS,
DirectConstArgContext::from_bits_retain(self.bits()),
DirectConstArgContext::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<DirectConstArgContext> {
::bitflags::iter::IterNames::__private_const_new(<DirectConstArgContext
as ::bitflags::Flags>::FLAGS,
DirectConstArgContext::from_bits_retain(self.bits()),
DirectConstArgContext::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for
DirectConstArgContext {
type Item = DirectConstArgContext;
type IntoIter = ::bitflags::iter::Iter<DirectConstArgContext>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};bitflags::bitflags! {
3381 #[derive(Copy, Clone, Debug)]
3382 struct DirectConstArgContext: u16 {
3383 const TUPLE_CALL = 1 << 0;
3384 const TUPLE = 1 << 1;
3385 const PATH_PLAIN_PARAM = 1 << 2;
3386 const PATH_CONST_CTOR = 1 << 3;
3387 const PATH_ANY = 1 << 4;
3388 const STRUCT = 1 << 5;
3389 const ARRAY = 1 << 6;
3390 const UNDERSCORE = 1 << 7;
3391 const PAREN = 1 << 8;
3392 const BLOCK = 1 << 9;
3393 const LIT = 1 << 10;
3394 const CONST_BLOCK = 1 << 11;
3395 const GCA_MACRO = 1 << 12;
3396 }
3397}
3398
3399impl DirectConstArgContext {
3400 const STABLE: DirectConstArgContext = Self::PATH_PLAIN_PARAM;
3403
3404 const GCA: DirectConstArgContext = Self::STABLE.union(Self::GCA_MACRO);
3406
3407 const GCA_BASE_FEATURES: DirectConstArgContext = Self::GCA
3412 .union(DirectConstArgContext::UNDERSCORE)
3413 .union(DirectConstArgContext::PAREN)
3414 .union(DirectConstArgContext::BLOCK)
3415 .union(DirectConstArgContext::LIT)
3416 .union(DirectConstArgContext::CONST_BLOCK);
3417
3418 const GCA_MIN_CONST_ITEMS: DirectConstArgContext = DirectConstArgContext::PATH_ANY;
3420
3421 const GCA_ADTS: DirectConstArgContext = DirectConstArgContext::PATH_CONST_CTOR
3423 .union(DirectConstArgContext::TUPLE_CALL)
3424 .union(DirectConstArgContext::TUPLE)
3425 .union(DirectConstArgContext::STRUCT)
3426 .union(DirectConstArgContext::ARRAY);
3427}
3428
3429#[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 will_create_def_ids",
&self.span, &&self.will_create_def_ids)
}
}Debug)]
3430struct UnrepresentableConstArgError {
3431 span: Span,
3432 will_create_def_ids: bool,
3433}
3434
3435impl UnrepresentableConstArgError {
3436 fn new(expr: &Expr) -> Self {
3437 Self {
3438 span: expr.span,
3439 will_create_def_ids: expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break(),
3440 }
3441 }
3442
3443 fn emit<'hir>(self, lowering_context: &mut LoweringContext<'_, 'hir>) -> ConstArg<'hir> {
3444 let msg = "complex const arguments must be placed inside of a `const` block";
3445 let e = if self.will_create_def_ids {
3446 lowering_context.dcx().span_fatal(self.span, msg)
3450 } else {
3451 lowering_context.dcx().span_err(self.span, msg)
3452 };
3453
3454 ConstArg {
3455 hir_id: lowering_context.next_id(),
3456 kind: hir::ConstArgKind::Error(e),
3457 span: lowering_context.lower_span(self.span),
3458 }
3459 }
3460}