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, Target};
51use rustc_attr_parsing::{AttributeParser, Recovery, ShouldEmit};
52use rustc_data_structures::fx::FxIndexMap;
53use rustc_data_structures::sorted_map::SortedMap;
54use rustc_data_structures::stable_hash::{StableHash, StableHasher};
55use rustc_data_structures::steal::Steal;
56use rustc_data_structures::tagged_ptr::TaggedRef;
57use rustc_errors::codes::*;
58use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, ErrorGuaranteed};
59use rustc_hir::def::{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_tuple_field1_finish(f,
"Allowed", &__self_0),
Self::Forbidden(__self_0) =>
::core::fmt::Formatter::debug_tuple_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_tuple_field2_finish(f,
"FeatureGated", __self_0, &__self_1),
Self::Disallowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Disallowed", &__self_0),
Self::AlreadyErrored(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AlreadyErrored", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::marker::Copy for ImplTraitContext { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ImplTraitContext {
}
#[automatically_derived]impl ::core::clone::Clone for ImplTraitContext {
#[inline]
fn clone(&self) -> Self {
let _:
::core::clone::AssertParamIsClone<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::clone::AssertParamIsClone<ImplTraitPosition>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
let _: ::core::clone::AssertParamIsClone<ErrorGuaranteed>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ImplTraitContext {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ImplTraitContext {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::OpaqueTy { origin: __self_0 }, Self::OpaqueTy {
origin: __arg1_0 }) => __self_0 == __arg1_0,
(Self::FeatureGated(__self_0, __self_1),
Self::FeatureGated(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Disallowed(__self_0), Self::Disallowed(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::AlreadyErrored(__self_0),
Self::AlreadyErrored(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ImplTraitContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::cmp::AssertParamIsEq<ImplTraitPosition>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
let _: ::core::cmp::AssertParamIsEq<ErrorGuaranteed>;
}
}Eq)]
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_tuple_field1_finish(f,
"Homogeneous", &__self_0),
Self::Heterogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_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/92b5b8c87c61b20adc9001b41baf587634a74734/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, Target::Crate, 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(
766 hir::CRATE_HIR_ID,
767 &c.attrs,
768 c.spans.inner_span,
769 Target::Crate,
770 AstTarget::Crate(c),
771 );
772 hir::OwnerNode::Crate(module)
773 }),
774 AstOwner::Item(item) => {
775 with_lctx(tcx, &*resolver, item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
776 }
777 AstOwner::TraitItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
778 hir::OwnerNode::TraitItem(lctx.lower_trait_item(item))
779 }),
780 AstOwner::ImplItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
781 hir::OwnerNode::ImplItem(lctx.lower_impl_item(item))
782 }),
783 AstOwner::ForeignItem(item) => with_lctx(tcx, &*resolver, item.id, |lctx| {
784 hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
785 }),
786 };
787
788 tcx.sess.time("drop_ast", || mem::drop(node));
789
790 item
791}
792
793#[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)]
794enum ParamMode {
795 Explicit,
797 Optional,
799}
800
801#[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)]
802enum AllowReturnTypeNotation {
803 Yes,
805 No,
807}
808
809enum GenericArgsMode {
810 ParenSugar,
812 ReturnTypeNotation,
814 Err,
816 Silence,
818}
819
820#[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)]
821enum DiscardParams {
822 Yes,
824 No,
826}
827
828impl<'hir> LoweringContext<'_, 'hir> {
829 fn create_def(
830 &mut self,
831 node_id: NodeId,
832 name: Option<Symbol>,
833 def_kind: DefKind,
834 span: Span,
835 ) -> LocalDefId {
836 let parent = self.curr_owner.owner_id().def_id;
837 {
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);
838 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!(
839 self.opt_local_def_id(node_id).is_none(),
840 "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
841 node_id,
842 def_kind,
843 self.tcx.hir_def_key(self.local_def_id(node_id)),
844 );
845
846 let def_id = self
847 .tcx
848 .at(span)
849 .create_def(parent, name, def_kind, None, &mut self.curr_owner.disambiguator)
850 .def_id();
851
852 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:852",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(852u32),
::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);
853 self.node_id_to_def_id.insert(node_id, def_id);
854
855 def_id
856 }
857
858 fn next_node_id(&mut self) -> NodeId {
859 let start = self.next_node_id;
860 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
861 self.next_node_id = NodeId::from_u32(next);
862 start
863 }
864
865 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(867u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:867",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(867u32),
::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)]
868 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
869 self.node_id_to_def_id
870 .get(&node)
871 .or_else(|| self.curr_owner.owner.node_id_to_def_id.get(&node))
872 .copied()
873 }
874
875 fn local_def_id(&self, node: NodeId) -> LocalDefId {
876 self.opt_local_def_id(node).unwrap_or_else(|| {
877 self.resolver.owners.items().any(|(id, items)| {
878 items.node_id_to_def_id.items().any(|(node_id, def_id)| {
879 if *node_id == node {
880 let actual_owner = items.node_id_to_def_id.get(id);
881 {
::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})",)
882 }
883 false
884 })
885 });
886 {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
};panic!("no entry for node id: `{node:?}`");
887 })
888 }
889
890 fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
891 match self.partial_res_overrides.get(&id) {
892 Some(self_param_id) => Some(PartialRes::new(Res::Local(*self_param_id))),
893 None => self.resolver.partial_res_map.get(&id).copied(),
894 }
895 }
896
897 fn owner_id(&self, node: NodeId) -> hir::OwnerId {
899 hir::OwnerId { def_id: self.resolver.owners[&node].def_id }
900 }
901
902 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(907u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:907",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(907u32),
::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)]
908 fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
909 assert_ne!(ast_node_id, DUMMY_NODE_ID);
910
911 let owner = self.curr_owner.owner_id();
912 let local_id = self.curr_owner.item_local_id_counter;
913 assert_ne!(local_id, hir::ItemLocalId::ZERO);
914 self.curr_owner.item_local_id_counter.increment_by(1);
915 let hir_id = HirId { owner, local_id };
916
917 if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
918 self.curr_owner.children.insert(def_id, hir::MaybeOwner::NonOwner(hir_id));
919 }
920
921 if let Some(traits) = self.curr_owner.owner.trait_map.get(&ast_node_id) {
922 self.curr_owner.trait_map.insert(hir_id.local_id, *traits);
923 }
924
925 #[cfg(debug_assertions)]
927 self.curr_owner.relowering_checker.assert_node_is_not_relowered(ast_node_id, local_id);
928
929 hir_id
930 }
931
932 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(933u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:933",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(933u32),
::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)]
934 fn next_id(&mut self) -> HirId {
935 let owner = self.curr_owner.owner_id();
936 let local_id = self.curr_owner.item_local_id_counter;
937 assert_ne!(local_id, hir::ItemLocalId::ZERO);
938 self.curr_owner.item_local_id_counter.increment_by(1);
939 HirId { owner, local_id }
940 }
941
942 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(942u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:950",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(950u32),
::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))]
943 fn lower_res(&self, res: Res<NodeId>) -> Res {
944 let res: Result<Res, ()> = res.apply_id(|id| {
945 let owner = self.curr_owner.owner_id();
946 let local_id =
947 self.curr_owner.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
948 Ok(HirId { owner, local_id })
949 });
950 trace!(?res);
951
952 res.unwrap_or(Res::Err)
958 }
959
960 fn expect_full_res(&self, id: NodeId) -> Res<NodeId> {
961 self.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
962 }
963
964 fn lower_import_res(&self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
965 let per_ns = self
966 .curr_owner
967 .owner
968 .import_res
969 .get(&id)
970 .unwrap_or_else(|| {
971 let sp = self.tcx.source_span(self.curr_owner.owner.def_id);
972 self.tcx.dcx().span_delayed_bug(
973 sp,
974 "no import_res entry for import, \
975 this should only happen if it already errored in resolve",
976 );
977 &PerNS { value_ns: None, type_ns: None, macro_ns: None }
978 })
979 .map(|res| res.map(|res| self.lower_res(res)));
980
981 if per_ns.is_empty() {
982 self.dcx().span_delayed_bug(span, "no resolution for an import");
984 let err = Some(Res::Err);
985 return PerNS { type_ns: err, value_ns: err, macro_ns: err };
986 }
987 per_ns
988 }
989
990 fn make_lang_item_qpath(
991 &mut self,
992 lang_item: LangItem,
993 span: Span,
994 args: Option<&'hir hir::GenericArgs<'hir>>,
995 ) -> hir::QPath<'hir> {
996 hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
997 }
998
999 fn make_lang_item_path(
1000 &mut self,
1001 lang_item: LangItem,
1002 span: Span,
1003 args: Option<&'hir hir::GenericArgs<'hir>>,
1004 ) -> &'hir hir::Path<'hir> {
1005 let def_id = self.tcx.require_lang_item(lang_item, span);
1006 let def_kind = self.tcx.def_kind(def_id);
1007 let res = Res::Def(def_kind, def_id);
1008 self.arena.alloc(hir::Path {
1009 span,
1010 res,
1011 segments: self.arena.alloc_from_iter([hir::PathSegment {
1012 ident: Ident::new(lang_item.name(), span),
1013 hir_id: self.next_id(),
1014 res,
1015 args,
1016 infer_args: args.is_none(),
1017 delegation_child_segment: false,
1018 }]),
1019 })
1020 }
1021
1022 fn mark_span_with_reason(
1025 &self,
1026 reason: DesugaringKind,
1027 span: Span,
1028 allow_internal_unstable: Option<Arc<[Symbol]>>,
1029 ) -> Span {
1030 self.tcx.with_stable_hashing_context(|hcx| {
1031 span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
1032 })
1033 }
1034
1035 fn span_lowerer(&self) -> SpanLowerer {
1036 SpanLowerer {
1037 is_incremental: self.tcx.sess.opts.incremental.is_some(),
1038 def_id: self.curr_owner.owner_id().def_id,
1039 }
1040 }
1041
1042 fn lower_span(&self, span: Span) -> Span {
1045 self.span_lowerer().lower(span)
1046 }
1047
1048 fn lower_ident(&self, ident: Ident) -> Ident {
1049 Ident::new(ident.name, self.lower_span(ident.span))
1050 }
1051
1052 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lifetime_res_to_generic_param",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1053u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:1068",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1068u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
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))]
1054 fn lifetime_res_to_generic_param(
1055 &mut self,
1056 ident: Ident,
1057 node_id: NodeId,
1058 kind: MissingLifetimeKind,
1059 source: hir::GenericParamSource,
1060 ) -> hir::GenericParam<'hir> {
1061 let _def_id = self.create_def(
1063 node_id,
1064 Some(kw::UnderscoreLifetime),
1065 DefKind::LifetimeParam,
1066 ident.span,
1067 );
1068 debug!(?_def_id);
1069
1070 let hir_id = self.lower_node_id(node_id);
1071 let def_id = self.local_def_id(node_id);
1072 hir::GenericParam {
1073 hir_id,
1074 def_id,
1075 name: hir::ParamName::Fresh,
1076 span: self.lower_span(ident.span),
1077 pure_wrt_drop: false,
1078 kind: hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided(kind) },
1079 colon_span: None,
1080 source,
1081 }
1082 }
1083
1084 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1089u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:1099",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1099u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:1089",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1089u32),
::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)]
1090 #[inline]
1091 fn lower_lifetime_binder(
1092 &mut self,
1093 binder: NodeId,
1094 generic_params: &[GenericParam],
1095 ) -> &'hir [hir::GenericParam<'hir>] {
1096 let extra_lifetimes = self.curr_owner.owner.extra_lifetime_params(binder);
1099 debug!(?extra_lifetimes);
1100 let extra_lifetimes: Vec<_> = extra_lifetimes
1101 .iter()
1102 .map(|&(ident, node_id, res)| {
1103 self.lifetime_res_to_generic_param(
1104 ident,
1105 node_id,
1106 res,
1107 hir::GenericParamSource::Binder,
1108 )
1109 })
1110 .collect();
1111 let arena = self.arena;
1112 let explicit_generic_params =
1113 self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
1114 arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
1115 }
1116
1117 fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
1118 let was_in_dyn_type = self.is_in_dyn_type;
1119 self.is_in_dyn_type = in_scope;
1120
1121 let result = f(self);
1122
1123 self.is_in_dyn_type = was_in_dyn_type;
1124
1125 result
1126 }
1127
1128 fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
1129 let current_item_span = self.current_item_span;
1130 self.current_item_span = Some(scope_span);
1131
1132 let was_in_loop_condition = self.is_in_loop_condition;
1133 self.is_in_loop_condition = false;
1134
1135 let old_contract = self.contract_ensures.take();
1136
1137 let try_block_scope = mem::replace(&mut self.try_block_scope, TryBlockScope::Function);
1138 let loop_scope = self.loop_scope.take();
1139 let ret = f(self);
1140 self.try_block_scope = try_block_scope;
1141 self.loop_scope = loop_scope;
1142
1143 self.contract_ensures = old_contract;
1144
1145 self.is_in_loop_condition = was_in_loop_condition;
1146
1147 self.current_item_span = current_item_span;
1148
1149 ret
1150 }
1151
1152 fn lower_attrs(
1153 &mut self,
1154 id: HirId,
1155 attrs: &[Attribute],
1156 target_span: Span,
1157 target: Target,
1158 ast_target: AstTarget<'_>,
1159 ) -> &'hir [rustc_attr_ir::Attribute] {
1160 self.lower_attrs_with_extra(id, attrs, target_span, target, ast_target, &[])
1161 }
1162
1163 fn lower_attrs_with_extra(
1164 &mut self,
1165 id: HirId,
1166 attrs: &[Attribute],
1167 target_span: Span,
1168 target: Target,
1169 ast_target: AstTarget<'_>,
1170 extra_hir_attributes: &[rustc_attr_ir::Attribute],
1171 ) -> &'hir [rustc_attr_ir::Attribute] {
1172 if attrs.is_empty() && extra_hir_attributes.is_empty() {
1173 &[]
1174 } else {
1175 let mut lowered_attrs =
1176 self.lower_attrs_vec(attrs, self.lower_span(target_span), id, target, ast_target);
1177 lowered_attrs.extend(extra_hir_attributes.iter().cloned());
1178
1179 {
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());
1180 let ret = self.arena.alloc_from_iter(lowered_attrs);
1181
1182 if ret.is_empty() {
1189 &[]
1190 } else {
1191 self.curr_owner.attrs.insert(id.local_id, ret);
1192 ret
1193 }
1194 }
1195 }
1196
1197 fn lower_attrs_vec(
1198 &mut self,
1199 attrs: &[Attribute],
1200 target_span: Span,
1201 target_hir_id: HirId,
1202 target: Target,
1203 ast_target: AstTarget<'_>,
1204 ) -> Vec<rustc_attr_ir::Attribute> {
1205 let l = self.span_lowerer();
1206 self.attribute_parser.parse_attribute_list(
1207 attrs,
1208 target_span,
1209 target,
1210 ast_target,
1211 |s| l.lower(s),
1212 |lint_id, span, kind| {
1213 self.curr_owner.delayed_lints.push(DelayedLint {
1214 lint_id,
1215 id: target_hir_id,
1216 span,
1217 callback: Box::new(move |dcx, level, sess: &dyn std::any::Any| {
1218 let sess = sess
1219 .downcast_ref::<rustc_session::Session>()
1220 .expect("expected `Session`");
1221 (kind.0)(dcx, level, sess)
1222 }),
1223 });
1224 },
1225 )
1226 }
1227
1228 fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
1229 {
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());
1230 {
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());
1231 if let Some(&a) = self.curr_owner.attrs.get(&target_id.local_id) {
1232 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
1233 self.curr_owner.attrs.insert(id.local_id, a);
1234 }
1235 }
1236
1237 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1238u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:1244",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1244u32),
::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)]
1239 fn lower_assoc_item_constraint(
1240 &mut self,
1241 constraint: &AssocItemConstraint,
1242 itctx: ImplTraitContext,
1243 ) -> hir::AssocItemConstraint<'hir> {
1244 debug!(?constraint, ?itctx);
1245 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1247 let gen_args_ctor = match gen_args {
1248 GenericArgs::AngleBracketed(data) => {
1249 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1250 }
1251 GenericArgs::Parenthesized(data) => {
1252 if let Some(first_char) = constraint.ident.as_str().chars().next()
1253 && first_char.is_ascii_lowercase()
1254 {
1255 let err = match (&data.inputs[..], &data.output) {
1256 ([_, ..], FnRetTy::Default(_)) => {
1257 diagnostics::BadReturnTypeNotation::Inputs {
1258 span: data.inputs_span,
1259 }
1260 }
1261 ([], FnRetTy::Default(_)) => {
1262 diagnostics::BadReturnTypeNotation::NeedsDots {
1263 span: data.inputs_span,
1264 }
1265 }
1266 (_, FnRetTy::Ty(ty)) => {
1268 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1269 diagnostics::BadReturnTypeNotation::Output {
1270 span,
1271 suggestion: diagnostics::RTNSuggestion {
1272 output: span,
1273 input: data.inputs_span,
1274 },
1275 }
1276 }
1277 };
1278 let mut err = self.dcx().create_err(err);
1279 if !self.tcx.features().return_type_notation()
1280 && self.tcx.sess.is_nightly_build()
1281 {
1282 add_feature_diagnostics(
1283 &mut err,
1284 &self.tcx.sess,
1285 sym::return_type_notation,
1286 );
1287 }
1288 err.emit();
1289 GenericArgsCtor {
1290 args: Default::default(),
1291 constraints: &[],
1292 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1293 span: data.span,
1294 }
1295 } else {
1296 let guar = self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1297 self.lower_angle_bracketed_parameter_data(
1298 &data.as_angle_bracketed_args(),
1299 ParamMode::Explicit,
1300 ImplTraitContext::AlreadyErrored(guar),
1301 )
1302 .0
1303 }
1304 }
1305 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1306 args: Default::default(),
1307 constraints: &[],
1308 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1309 span: *span,
1310 },
1311 };
1312 gen_args_ctor.into_generic_args(self)
1313 } else {
1314 hir::GenericArgs::NONE
1315 };
1316 let kind = match &constraint.kind {
1317 AssocItemConstraintKind::Equality { term } => {
1318 let term = match term {
1319 Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
1320 Term::Const(c) => self.lower_anon_const_to_const_arg_and_alloc(c).into(),
1321 };
1322 hir::AssocItemConstraintKind::Equality { term }
1323 }
1324 AssocItemConstraintKind::Bound { bounds } => {
1325 if self.is_in_dyn_type {
1327 let suggestion = match itctx {
1328 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1329 let bound_end_span = constraint
1330 .gen_args
1331 .as_ref()
1332 .map_or(constraint.ident.span, |args| args.span());
1333 if bound_end_span.ctxt() == constraint.span.ctxt() {
1334 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1335 } else {
1336 None
1337 }
1338 }
1339 _ => None,
1340 };
1341
1342 let guar = self.dcx().emit_err(diagnostics::MisplacedAssocTyBinding {
1343 span: constraint.span,
1344 suggestion,
1345 });
1346 let err_ty =
1347 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1348 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1349 } else {
1350 let bounds = self.lower_param_bounds(
1351 bounds,
1352 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1353 itctx,
1354 );
1355 hir::AssocItemConstraintKind::Bound { bounds }
1356 }
1357 }
1358 };
1359
1360 hir::AssocItemConstraint {
1361 hir_id: self.lower_node_id(constraint.id),
1362 ident: self.lower_ident(constraint.ident),
1363 gen_args,
1364 kind,
1365 span: self.lower_span(constraint.span),
1366 }
1367 }
1368
1369 fn emit_bad_parenthesized_trait_in_assoc_ty(
1370 &self,
1371 data: &ParenthesizedArgs,
1372 ) -> ErrorGuaranteed {
1373 let sub = if data.inputs.is_empty() {
1375 let parentheses_span =
1376 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1377 AssocTyParenthesesSub::Empty { parentheses_span }
1378 }
1379 else {
1381 let open_param = data.inputs_span.shrink_to_lo().to(data
1383 .inputs
1384 .first()
1385 .unwrap()
1386 .span
1387 .shrink_to_lo());
1388 let close_param =
1390 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1391 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1392 };
1393 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub })
1394 }
1395
1396 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1396u32),
::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))]
1397 fn lower_generic_arg(
1398 &mut self,
1399 arg: &ast::GenericArg,
1400 itctx: ImplTraitContext,
1401 ) -> hir::GenericArg<'hir> {
1402 match arg {
1403 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1404 lt,
1405 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1406 lt.ident.into(),
1407 )),
1408 ast::GenericArg::Type(ty) => {
1409 if ty.is_maybe_parenthesised_infer() {
1412 return GenericArg::Infer(self.arena.alloc(hir::InferArg {
1413 hir_id: self.lower_node_id(ty.id),
1414 span: self.lower_span(ty.span),
1415 kind: hir::InferArgKind::TypeOrConst,
1416 }));
1417 }
1418
1419 match &ty.kind {
1420 TyKind::Path(None, path)
1431 if path.is_single_argless_ident()
1432 && let Some(res) = self
1433 .get_partial_res(ty.id)
1434 .and_then(|partial_res| partial_res.full_res())
1435 && !res.matches_ns(Namespace::TypeNS) =>
1436 {
1437 let ct =
1438 self.lower_const_path_to_const_arg(&None, path, res, ty.id, ty.span);
1439 let ct = self.arena.alloc(ct);
1440 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1441 }
1442 TyKind::GcaMacro(expr) if self.tcx.features().gca() => {
1443 let ct = match self.can_lower_expr_to_const_arg_direct(
1444 expr,
1445 self.direct_const_arg_context_enabled_by_gca_macro(),
1446 ) {
1447 Ok(()) => self.lower_expr_to_const_arg_direct(expr, None),
1448 Err(e) => e.emit(self),
1449 };
1450 let ct = self.arena.alloc(ct);
1451 return match ct.try_as_ambig_ct() {
1452 Some(ct) => GenericArg::Const(ct),
1453 None => GenericArg::Infer(self.arena.alloc(hir::InferArg {
1454 hir_id: ct.hir_id,
1455 span: ct.span,
1456 kind: hir::InferArgKind::Const,
1457 })),
1458 };
1459 }
1460 _ => {}
1461 }
1462 GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
1463 }
1464 ast::GenericArg::Const(ct) => {
1465 let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1466 match ct.try_as_ambig_ct() {
1467 Some(ct) => GenericArg::Const(ct),
1468 None => GenericArg::Infer(self.arena.alloc(hir::InferArg {
1469 hir_id: ct.hir_id,
1470 span: ct.span,
1471 kind: hir::InferArgKind::Const,
1472 })),
1473 }
1474 }
1475 }
1476 }
1477
1478 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1478u32),
::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))]
1479 fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1480 self.arena.alloc(self.lower_ty(t, itctx))
1481 }
1482
1483 fn lower_path_ty(
1484 &mut self,
1485 t: &Ty,
1486 qself: &Option<Box<QSelf>>,
1487 path: &Path,
1488 param_mode: ParamMode,
1489 itctx: ImplTraitContext,
1490 ) -> hir::Ty<'hir> {
1491 if qself.is_none()
1497 && let Some(partial_res) = self.get_partial_res(t.id)
1498 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1499 {
1500 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1501 let bound = this.lower_poly_trait_ref(
1502 &PolyTraitRef {
1503 bound_generic_params: ThinVec::new(),
1504 modifiers: TraitBoundModifiers::NONE,
1505 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1506 span: t.span,
1507 parens: ast::Parens::No,
1508 },
1509 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1510 itctx,
1511 );
1512 let bounds = this.arena.alloc_from_iter([bound]);
1513 let lifetime_bound = this.elided_dyn_bound(t.span);
1514 (bounds, lifetime_bound)
1515 });
1516 let kind = hir::TyKind::TraitObject(
1517 bounds,
1518 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1519 );
1520 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1521 }
1522
1523 let id = self.lower_node_id(t.id);
1524 let qpath = self.lower_qpath(
1525 t.id,
1526 qself,
1527 path,
1528 param_mode,
1529 AllowReturnTypeNotation::Yes,
1530 itctx,
1531 None,
1532 );
1533 self.ty_path(id, t.span, qpath)
1534 }
1535
1536 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1537 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1538 }
1539
1540 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1541 self.ty(span, hir::TyKind::Tup(tys))
1542 }
1543
1544 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1545 let kind = match &t.kind {
1546 TyKind::Infer => hir::TyKind::Infer(()),
1547 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1548 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
1549 TyKind::Ptr(ty, mutbl) => hir::TyKind::Ptr(self.lower_ty_alloc(ty, itctx), *mutbl),
1550 TyKind::Ref(region, ty, mutbl) => {
1551 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1552 hir::TyKind::Ref(lifetime, self.lower_ty_alloc(ty, itctx), *mutbl)
1553 }
1554 TyKind::PinnedRef(region, ty, mutbl) => {
1555 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1556 let kind = hir::TyKind::Ref(lifetime, self.lower_ty_alloc(ty, itctx), *mutbl);
1557 let span = self.lower_span(t.span);
1558 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1559 let args = self.arena.alloc(hir::GenericArgs {
1560 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1561 constraints: &[],
1562 parenthesized: hir::GenericArgsParentheses::No,
1563 span_ext: span,
1564 });
1565 let path = self.make_lang_item_qpath(LangItem::Pin, span, Some(args));
1566 hir::TyKind::Path(path)
1567 }
1568 TyKind::FnPtr(f) => {
1569 let hir_id = self.lower_node_id(t.id);
1570 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1571 let kind = hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1572 generic_params,
1573 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1574 abi: self.lower_extern(f.ext),
1575 decl: self.lower_fn_decl(
1576 &f.decl,
1577 t.id,
1578 hir_id,
1579 FnDeclKind::Pointer,
1580 None,
1581 DiscardParams::Yes,
1582 ),
1583 param_idents: self.lower_fn_params_to_idents(&f.decl),
1584 }));
1585 return hir::Ty { kind, span: self.lower_span(t.span), hir_id };
1586 }
1587 TyKind::UnsafeBinder(f) => {
1588 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1589 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1590 generic_params,
1591 inner_ty: self.lower_ty_alloc(&f.inner_ty, itctx),
1592 }))
1593 }
1594 TyKind::Never => hir::TyKind::Never,
1595 TyKind::Tup(tys) => hir::TyKind::Tup(
1596 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty(ty, itctx))),
1597 ),
1598 TyKind::Paren(ty) => {
1599 return self.lower_ty(ty, itctx);
1600 }
1601 TyKind::Path(qself, path) => {
1602 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1603 }
1604 TyKind::ImplicitSelf => {
1605 let hir_id = self.next_id();
1606 let res = self.expect_full_res(t.id);
1607 let res = self.lower_res(res);
1608 hir::TyKind::Path(hir::QPath::Resolved(
1609 None,
1610 self.arena.alloc(hir::Path {
1611 res,
1612 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1613 Ident::with_dummy_span(kw::SelfUpper),
1614 hir_id,
1615 res
1616 )],
1617 span: self.lower_span(t.span),
1618 }),
1619 ))
1620 }
1621 TyKind::Array(ty, length) => hir::TyKind::Array(
1622 self.lower_ty_alloc(ty, itctx),
1623 self.lower_array_length_to_const_arg(length),
1624 ),
1625 TyKind::TraitObject(bounds, kind) => {
1626 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1627 let mut lifetime_bound = None;
1628 let bounds =
1629 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1630 GenericBound::Trait(ty) => {
1634 let trait_ref = this.lower_poly_trait_ref(
1635 ty,
1636 RelaxedBoundPolicy::Forbidden(
1637 RelaxedBoundForbiddenReason::TraitObjectTy,
1638 ),
1639 itctx,
1640 );
1641 Some(trait_ref)
1642 }
1643 GenericBound::Outlives(lifetime) => {
1644 if lifetime_bound.is_none() {
1645 lifetime_bound = Some(this.lower_lifetime(
1646 lifetime,
1647 LifetimeSource::Other,
1648 lifetime.ident.into(),
1649 ));
1650 }
1651 None
1652 }
1653 GenericBound::Use(_, span) => {
1655 this.dcx()
1656 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1657 None
1658 }
1659 }));
1660 (bounds, lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span)))
1661 });
1662 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1663 }
1664 TyKind::ImplTrait(def_node_id, bounds) => {
1665 let span = t.span;
1666 match itctx {
1667 ImplTraitContext::OpaqueTy { origin } => {
1668 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1669 }
1670 ImplTraitContext::Universal => {
1671 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1672 ast::GenericBound::Use(_, span) => Some(span),
1673 _ => None,
1674 }) {
1675 self.tcx.dcx().emit_err(diagnostics::NoPreciseCapturesOnApit { span });
1676 }
1677
1678 let def_id = self.local_def_id(*def_node_id);
1679 let name = self.tcx.item_name(def_id.to_def_id());
1680 let ident = Ident::new(name, span);
1681 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1682 *def_node_id,
1683 span,
1684 ident,
1685 bounds,
1686 );
1687 self.curr_owner.impl_trait_defs.push(param);
1688 if let Some(bounds) = bounds {
1689 self.curr_owner.impl_trait_bounds.push(bounds);
1690 }
1691 path
1692 }
1693 ImplTraitContext::InBinding => {
1694 hir::TyKind::TraitAscription(self.lower_param_bounds(
1695 bounds,
1696 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1697 itctx,
1698 ))
1699 }
1700 ImplTraitContext::FeatureGated(position, feature) => {
1701 let guar = self
1702 .tcx
1703 .sess
1704 .create_feature_err(
1705 MisplacedImplTrait {
1706 span: t.span,
1707 position: DiagArgFromDisplay(&position),
1708 },
1709 feature,
1710 )
1711 .emit_err();
1712 hir::TyKind::Err(guar)
1713 }
1714 ImplTraitContext::Disallowed(position) => {
1715 let guar = self.dcx().emit_err(MisplacedImplTrait {
1716 span: t.span,
1717 position: DiagArgFromDisplay(&position),
1718 });
1719 hir::TyKind::Err(guar)
1720 }
1721 ImplTraitContext::AlreadyErrored(guar) => {
1722 hir::TyKind::Err(guar)
1729 }
1730 }
1731 }
1732 TyKind::Pat(ty, pat) => {
1733 hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
1734 }
1735 TyKind::FieldOf(ty, variant, field) => hir::TyKind::FieldOf(
1736 self.lower_ty_alloc(ty, itctx),
1737 self.arena.alloc(hir::TyFieldPath {
1738 variant: variant.map(|variant| self.lower_ident(variant)),
1739 field: self.lower_ident(*field),
1740 }),
1741 ),
1742 TyKind::MacCall(_) => {
1743 ::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")
1744 }
1745 TyKind::CVarArgs => {
1746 let guar = self.dcx().span_delayed_bug(
1747 t.span,
1748 "`TyKind::CVarArgs` should have been handled elsewhere",
1749 );
1750 hir::TyKind::Err(guar)
1751 }
1752 TyKind::View(ty, fields) => {
1753 let ty = self.lower_ty_alloc(ty, itctx);
1754 let fields = self.arena.alloc_slice(fields);
1755 hir::TyKind::View(ty, fields)
1756 }
1757 TyKind::GcaMacro(expr) => {
1758 let e = self.emit_bad_gca_macro(t.span, expr, "type");
1759 hir::TyKind::Err(e)
1760 }
1761 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1762 };
1763
1764 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1765 }
1766
1767 pub(crate) fn emit_bad_gca_macro(
1768 &mut self,
1769 span: Span,
1770 expr: &Expr,
1771 expected: &'static str,
1772 ) -> ErrorGuaranteed {
1773 let msg = ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected {0}, found `gca!()` constant",
expected))
})format!("expected {expected}, found `gca!()` constant");
1774 if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
1775 self.dcx().span_fatal(span, msg)
1778 } else {
1779 self.dcx().span_err(span, msg)
1780 }
1781 }
1782
1783 fn lower_ty_direct_lifetime(
1784 &mut self,
1785 t: &Ty,
1786 region: Option<Lifetime>,
1787 ) -> &'hir hir::Lifetime {
1788 let (region, syntax) = match region {
1789 Some(region) => (region, region.ident.into()),
1790
1791 None => {
1792 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1793 self.curr_owner.owner.get_lifetime_res(t.id)
1794 {
1795 {
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);
1796 start
1797 } else {
1798 self.next_node_id()
1799 };
1800 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1801 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1802 (region, LifetimeSyntax::Implicit)
1803 }
1804 };
1805 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1806 }
1807
1808 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1839u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:1839",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1839u32),
::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)]
1840 fn lower_opaque_impl_trait(
1841 &mut self,
1842 span: Span,
1843 origin: hir::OpaqueTyOrigin<LocalDefId>,
1844 opaque_ty_node_id: NodeId,
1845 bounds: &GenericBounds,
1846 itctx: ImplTraitContext,
1847 ) -> hir::TyKind<'hir> {
1848 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1854
1855 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1856 this.lower_param_bounds(
1857 bounds,
1858 RelaxedBoundPolicy::Allowed(&mut Default::default()),
1859 itctx,
1860 )
1861 })
1862 }
1863
1864 fn lower_opaque_inner(
1865 &mut self,
1866 opaque_ty_node_id: NodeId,
1867 origin: hir::OpaqueTyOrigin<LocalDefId>,
1868 opaque_ty_span: Span,
1869 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1870 ) -> hir::TyKind<'hir> {
1871 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1872 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1873 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:1873",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1873u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[{
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);
1874
1875 let bounds = lower_item_bounds(self);
1876 let opaque_ty_def = hir::OpaqueTy {
1877 hir_id: opaque_ty_hir_id,
1878 def_id: opaque_ty_def_id,
1879 bounds,
1880 origin,
1881 span: self.lower_span(opaque_ty_span),
1882 };
1883 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1884
1885 hir::TyKind::OpaqueDef(opaque_ty_def)
1886 }
1887
1888 fn lower_precise_capturing_args(
1889 &mut self,
1890 precise_capturing_args: &[PreciseCapturingArg],
1891 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1892 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1893 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1894 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1895 ),
1896 PreciseCapturingArg::Arg(path, id) => {
1897 let [segment] = path.segments.as_slice() else {
1898 ::core::panicking::panic_default_msg();panic!();
1899 };
1900 let res = self.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1901 partial_res.full_res().expect("no partial res expected for precise capture arg")
1902 });
1903 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1904 hir_id: self.lower_node_id(*id),
1905 ident: self.lower_ident(segment.ident),
1906 res: self.lower_res(res),
1907 })
1908 }
1909 }))
1910 }
1911
1912 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1913 self.arena.alloc_from_iter(decl.inputs.iter().filter(|param| !param.is_const_param()).map(
1914 |param| match param.pat.kind {
1915 PatKind::Missing => None,
1916 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1917 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1918 _ => {
1919 self.dcx().span_delayed_bug(
1920 param.pat.span,
1921 "non-missing/ident/wild param pat must trigger an error",
1922 );
1923 None
1924 }
1925 },
1926 ))
1927 }
1928
1929 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1944u32),
::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,
Target::from(&generic_param),
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,
Target::Param, 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))]
1945 fn lower_fn_decl(
1946 &mut self,
1947 decl: &FnDecl,
1948 fn_node_id: NodeId,
1949 fn_hir_id: HirId,
1950 kind: FnDeclKind,
1951 coro: Option<CoroutineMarker>,
1952 discard_params: DiscardParams,
1953 ) -> &'hir hir::FnDecl<'hir> {
1954 let c_variadic = decl.c_variadic();
1955 let mut splatted = decl.splatted();
1956
1957 let input_count = if decl.c_variadic() {
1961 splatted = None;
1963 decl.inputs.len() - 1
1964 } else {
1965 decl.inputs.len()
1966 };
1967
1968 let inputs = decl.inputs.iter().enumerate().take(input_count);
1969 let inputs = self.arena.alloc_from_iter(inputs.filter_map(|(param_idx, param)| {
1973 if let Some(ident) = param.const_param_ident() {
1974 if !matches!(
1975 kind,
1976 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait
1977 ) {
1978 self.dcx().span_delayed_bug(
1979 param.span,
1980 "Const args only allowed for Free/Inherent/Impl/Trait methods",
1981 );
1982 return None;
1983 }
1984 let ty = self.lower_ty_alloc(
1985 ¶m.ty,
1986 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
1987 );
1988 let hir_id = self.lower_node_id(param.id);
1989 let generic_param = hir::GenericParam {
1990 hir_id,
1991 def_id: self.local_def_id(param.id),
1992 name: ParamName::Plain(self.lower_ident(ident)),
1993 span: self.lower_span(param.span),
1994 pure_wrt_drop: false,
1995 kind: hir::GenericParamKind::Const {
1996 ty,
1997 default: None,
1998 arg_pos: Some(param_idx as u16),
1999 },
2000 colon_span: None,
2001 source: hir::GenericParamSource::Generics,
2002 };
2003 let ast_generic_param = ast::GenericParam {
2004 id: param.id,
2005 ident,
2006 attrs: param.attrs.clone(),
2007 bounds: Default::default(),
2008 is_placeholder: false,
2009 kind: ast::GenericParamKind::Const {
2010 ty: param.ty.clone(),
2011 span: param.span,
2012 default: None,
2013 },
2014 colon_span: None,
2015 };
2016 self.lower_attrs(
2017 hir_id,
2018 ¶m.attrs,
2019 param.span,
2020 Target::from(&generic_param),
2021 AstTarget::GenericParam(&ast_generic_param),
2022 );
2023 self.curr_owner.const_defs.push(generic_param);
2024 return None;
2025 }
2026 if let DiscardParams::Yes = discard_params {
2027 self.lower_attrs(
2031 fn_hir_id,
2032 ¶m.attrs,
2033 param.span,
2034 Target::Param,
2035 AstTarget::Param(param),
2036 );
2037 }
2038 let itctx = match kind {
2039 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
2040 ImplTraitContext::Universal
2041 }
2042 FnDeclKind::ExternFn => {
2043 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
2044 }
2045 FnDeclKind::Closure => {
2046 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
2047 }
2048 FnDeclKind::Pointer => {
2049 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
2050 }
2051 };
2052 Some(self.lower_ty(¶m.ty, itctx))
2053 }));
2054
2055 let output = match coro {
2056 Some(coro) => {
2057 let fn_def_id = self.curr_owner.owner.def_id;
2058 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
2059 }
2060 None => match &decl.output {
2061 FnRetTy::Ty(ty) => {
2062 let itctx = match kind {
2063 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
2064 origin: hir::OpaqueTyOrigin::FnReturn {
2065 parent: self.curr_owner.owner.def_id,
2066 in_trait_or_impl: None,
2067 },
2068 },
2069 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
2070 origin: hir::OpaqueTyOrigin::FnReturn {
2071 parent: self.curr_owner.owner.def_id,
2072 in_trait_or_impl: Some(hir::RpitContext::Trait),
2073 },
2074 },
2075 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
2076 origin: hir::OpaqueTyOrigin::FnReturn {
2077 parent: self.curr_owner.owner.def_id,
2078 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
2079 },
2080 },
2081 FnDeclKind::ExternFn => {
2082 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
2083 }
2084 FnDeclKind::Closure => {
2085 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
2086 }
2087 FnDeclKind::Pointer => {
2088 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
2089 }
2090 };
2091 hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
2092 }
2093 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
2094 },
2095 };
2096
2097 let fn_decl_kind = hir::FnDeclFlags::default()
2098 .set_implicit_self(decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
2099 let is_mutable_pat = matches!(
2100 arg.pat.kind,
2101 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
2102 );
2103
2104 match &arg.ty.kind {
2105 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
2106 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
2107 TyKind::Ref(_, ty, mutbl) | TyKind::PinnedRef(_, ty, mutbl)
2111 if ty.kind.is_implicit_self() =>
2112 {
2113 match mutbl {
2114 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
2115 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
2116 }
2117 }
2118 _ => hir::ImplicitSelfKind::None,
2119 }
2120 }))
2121 .set_lifetime_elision_allowed(
2122 self.curr_owner.owner.id == fn_node_id
2123 && self.curr_owner.owner.lifetime_elision_allowed,
2124 )
2125 .set_c_variadic(c_variadic)
2126 .set_splatted(splatted, inputs.len())
2127 .unwrap();
2128
2129 self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
2130 }
2131
2132 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2140u32),
::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))]
2141 fn lower_coroutine_fn_ret_ty(
2142 &mut self,
2143 output: &FnRetTy,
2144 fn_def_id: LocalDefId,
2145 coro: CoroutineMarker,
2146 fn_kind: FnDeclKind,
2147 ) -> hir::FnRetTy<'hir> {
2148 let span = self.lower_span(output.span());
2149
2150 let (opaque_ty_node_id, allowed_features) = match coro.kind {
2151 CoroutineKind::Async | CoroutineKind::Gen => (coro.return_impl_trait_id, None),
2152 CoroutineKind::AsyncGen => {
2153 (coro.return_impl_trait_id, Some(Arc::clone(&ALLOW_ASYNC_ITERATOR)))
2154 }
2155 };
2156
2157 let opaque_ty_span =
2158 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
2159
2160 let in_trait_or_impl = match fn_kind {
2161 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
2162 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
2163 FnDeclKind::Fn | FnDeclKind::Inherent => None,
2164 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
2165 };
2166
2167 let opaque_ty_ref = self.lower_opaque_inner(
2168 opaque_ty_node_id,
2169 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
2170 opaque_ty_span,
2171 |this| {
2172 let bound = this.lower_coroutine_fn_output_type_to_bound(
2173 output,
2174 coro,
2175 opaque_ty_span,
2176 ImplTraitContext::OpaqueTy {
2177 origin: hir::OpaqueTyOrigin::FnReturn {
2178 parent: fn_def_id,
2179 in_trait_or_impl,
2180 },
2181 },
2182 );
2183 arena_vec![this; bound]
2184 },
2185 );
2186
2187 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
2188 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
2189 }
2190
2191 fn lower_coroutine_fn_output_type_to_bound(
2193 &mut self,
2194 output: &FnRetTy,
2195 coro: CoroutineMarker,
2196 opaque_ty_span: Span,
2197 itctx: ImplTraitContext,
2198 ) -> hir::GenericBound<'hir> {
2199 let output_ty = match output {
2201 FnRetTy::Ty(ty) => {
2202 self.lower_ty_alloc(ty, itctx)
2206 }
2207 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
2208 };
2209
2210 let (assoc_ty_name, trait_lang_item) = match coro.kind {
2212 CoroutineKind::Async => (sym::Output, LangItem::Future),
2213 CoroutineKind::Gen => (sym::Item, LangItem::Iterator),
2214 CoroutineKind::AsyncGen => (sym::Item, LangItem::AsyncIterator),
2215 };
2216
2217 let bound_args = self.arena.alloc(hir::GenericArgs {
2218 args: &[],
2219 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)],
2220 parenthesized: hir::GenericArgsParentheses::No,
2221 span_ext: DUMMY_SP,
2222 });
2223
2224 hir::GenericBound::Trait(hir::PolyTraitRef {
2225 bound_generic_params: &[],
2226 modifiers: hir::TraitBoundModifiers::NONE,
2227 trait_ref: hir::TraitRef {
2228 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
2229 hir_ref_id: self.next_id(),
2230 },
2231 span: opaque_ty_span,
2232 })
2233 }
2234
2235 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2235u32),
::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))]
2236 fn lower_param_bound(
2237 &mut self,
2238 tpb: &GenericBound,
2239 rbp: RelaxedBoundPolicy<'_>,
2240 itctx: ImplTraitContext,
2241 ) -> hir::GenericBound<'hir> {
2242 match tpb {
2243 GenericBound::Trait(p) => {
2244 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
2245 }
2246 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
2247 lifetime,
2248 LifetimeSource::OutlivesBound,
2249 lifetime.ident.into(),
2250 )),
2251 GenericBound::Use(args, span) => hir::GenericBound::Use(
2252 self.lower_precise_capturing_args(args),
2253 self.lower_span(*span),
2254 ),
2255 }
2256 }
2257
2258 fn lower_lifetime(
2259 &mut self,
2260 l: &Lifetime,
2261 source: LifetimeSource,
2262 syntax: LifetimeSyntax,
2263 ) -> &'hir hir::Lifetime {
2264 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
2265 }
2266
2267 fn lower_lifetime_hidden_in_path(
2268 &mut self,
2269 id: NodeId,
2270 span: Span,
2271 angle_brackets: AngleBrackets,
2272 ) -> &'hir hir::Lifetime {
2273 self.new_named_lifetime(
2274 id,
2275 id,
2276 Ident::new(kw::UnderscoreLifetime, span),
2277 LifetimeSource::Path { angle_brackets },
2278 LifetimeSyntax::Implicit,
2279 )
2280 }
2281
2282 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2282u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:2316",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2316u32),
::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))]
2283 fn new_named_lifetime(
2284 &mut self,
2285 id: NodeId,
2286 new_id: NodeId,
2287 ident: Ident,
2288 source: LifetimeSource,
2289 syntax: LifetimeSyntax,
2290 ) -> &'hir hir::Lifetime {
2291 let res = if let Some(res) = self.curr_owner.owner.get_lifetime_res(id) {
2292 match res {
2293 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
2294 LifetimeRes::Fresh { param, .. } => {
2295 assert_eq!(ident.name, kw::UnderscoreLifetime);
2296 let param = self.local_def_id(param);
2297 hir::LifetimeKind::Param(param)
2298 }
2299 LifetimeRes::Infer => {
2300 assert_eq!(ident.name, kw::UnderscoreLifetime);
2301 hir::LifetimeKind::Infer
2302 }
2303 LifetimeRes::Static { .. } => {
2304 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
2305 hir::LifetimeKind::Static
2306 }
2307 LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
2308 LifetimeRes::ElidedAnchor { .. } => {
2309 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
2310 }
2311 }
2312 } else {
2313 hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
2314 };
2315
2316 debug!(?res);
2317 self.arena.alloc(hir::Lifetime::new(
2318 self.lower_node_id(new_id),
2319 self.lower_ident(ident),
2320 res,
2321 source,
2322 syntax,
2323 ))
2324 }
2325
2326 fn lower_generic_params_mut(
2327 &mut self,
2328 params: &[GenericParam],
2329 source: hir::GenericParamSource,
2330 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
2331 params.iter().map(move |param| self.lower_generic_param(param, source))
2332 }
2333
2334 fn lower_generic_params(
2335 &mut self,
2336 params: &[GenericParam],
2337 source: hir::GenericParamSource,
2338 ) -> &'hir [hir::GenericParam<'hir>] {
2339 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
2340 }
2341
2342 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2342u32),
::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,
Target::from(¶m_hir), AstTarget::GenericParam(param));
param_hir
}
}
}#[instrument(level = "trace", skip(self))]
2343 fn lower_generic_param(
2344 &mut self,
2345 param: &GenericParam,
2346 source: hir::GenericParamSource,
2347 ) -> hir::GenericParam<'hir> {
2348 let (name, kind) = self.lower_generic_param_kind(param, source);
2349
2350 let hir_id = self.lower_node_id(param.id);
2351 let param_attrs = ¶m.attrs;
2352 let param_span = param.span();
2353 let param_hir = hir::GenericParam {
2354 hir_id,
2355 def_id: self.local_def_id(param.id),
2356 name,
2357 span: self.lower_span(param.span()),
2358 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
2359 kind,
2360 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2361 source,
2362 };
2363 self.lower_attrs(
2364 hir_id,
2365 param_attrs,
2366 param_span,
2367 Target::from(¶m_hir),
2368 AstTarget::GenericParam(param),
2369 );
2370 param_hir
2371 }
2372
2373 fn lower_generic_param_kind(
2374 &mut self,
2375 param: &GenericParam,
2376 source: hir::GenericParamSource,
2377 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2378 match ¶m.kind {
2379 GenericParamKind::Lifetime => {
2380 let ident = self.lower_ident(param.ident);
2383 let param_name = if let Some(LifetimeRes::Error(..)) =
2384 self.curr_owner.owner.get_lifetime_res(param.id)
2385 {
2386 ParamName::Error(ident)
2387 } else {
2388 ParamName::Plain(ident)
2389 };
2390 let kind =
2391 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2392
2393 (param_name, kind)
2394 }
2395 GenericParamKind::Type { default, .. } => {
2396 let default = default
2399 .as_ref()
2400 .filter(|_| match source {
2401 hir::GenericParamSource::Generics => true,
2402 hir::GenericParamSource::Binder => {
2403 self.dcx().emit_err(diagnostics::GenericParamDefaultInBinder {
2404 span: param.span(),
2405 });
2406
2407 false
2408 }
2409 })
2410 .map(|def| {
2411 self.lower_ty_alloc(
2412 def,
2413 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2414 )
2415 });
2416
2417 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2418
2419 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2420 }
2421 GenericParamKind::Const { ty, span: _, default } => {
2422 let ty = self.lower_ty_alloc(
2423 ty,
2424 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2425 );
2426
2427 let default = default
2430 .as_ref()
2431 .filter(|anon_const| match source {
2432 hir::GenericParamSource::Generics => true,
2433 hir::GenericParamSource::Binder => {
2434 let err =
2435 diagnostics::GenericParamDefaultInBinder { span: param.span() };
2436 if expr::WillCreateDefIdsVisitor
2437 .visit_expr(&anon_const.value)
2438 .is_break()
2439 {
2440 self.dcx().emit_fatal(err)
2444 } else {
2445 self.dcx().emit_err(err);
2446 false
2447 }
2448 }
2449 })
2450 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2451
2452 (
2453 hir::ParamName::Plain(self.lower_ident(param.ident)),
2454 hir::GenericParamKind::Const { ty, default, arg_pos: None },
2455 )
2456 }
2457 }
2458 }
2459
2460 fn lower_trait_ref(
2461 &mut self,
2462 modifiers: ast::TraitBoundModifiers,
2463 p: &TraitRef,
2464 itctx: ImplTraitContext,
2465 ) -> hir::TraitRef<'hir> {
2466 let path = match self.lower_qpath(
2467 p.ref_id,
2468 &None,
2469 &p.path,
2470 ParamMode::Explicit,
2471 AllowReturnTypeNotation::No,
2472 itctx,
2473 Some(modifiers),
2474 ) {
2475 hir::QPath::Resolved(None, path) => path,
2476 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2477 };
2478 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2479 }
2480
2481 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2481u32),
::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))]
2482 fn lower_poly_trait_ref(
2483 &mut self,
2484 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2485 rbp: RelaxedBoundPolicy<'_>,
2486 itctx: ImplTraitContext,
2487 ) -> hir::PolyTraitRef<'hir> {
2488 let bound_generic_params =
2489 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2490 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2491 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2492
2493 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2494 self.validate_relaxed_bound(trait_ref, *span, rbp);
2495 }
2496
2497 hir::PolyTraitRef {
2498 bound_generic_params,
2499 modifiers,
2500 trait_ref,
2501 span: self.lower_span(*span),
2502 }
2503 }
2504
2505 fn validate_relaxed_bound(
2506 &self,
2507 trait_ref: hir::TraitRef<'_>,
2508 span: Span,
2509 rbp: RelaxedBoundPolicy<'_>,
2510 ) {
2511 match rbp {
2521 RelaxedBoundPolicy::Allowed(dedup_map) => {
2522 let Some(trait_def_id) = trait_ref.trait_def_id() else { return };
2524 let tcx = self.tcx;
2525 let err = |s| {
2526 let name = tcx.item_name(trait_def_id);
2527 tcx.dcx()
2528 .struct_span_err(
2529 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[span, s]))vec![span, s],
2530 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("duplicate relaxed `{0}` bounds",
name))
})format!("duplicate relaxed `{name}` bounds"),
2531 )
2532 .with_code(E0203)
2533 .emit();
2534 };
2535 dedup_map.entry(trait_def_id).and_modify(|&mut s| err(s)).or_insert(span);
2536 return;
2537 }
2538 RelaxedBoundPolicy::Forbidden(reason) => {
2539 let gate = |context, subject| {
2540 let extended = self.tcx.features().more_maybe_bounds();
2541 let is_sized = trait_ref
2542 .trait_def_id()
2543 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, LangItem::Sized));
2544
2545 if extended && !is_sized {
2546 return;
2547 }
2548
2549 let prefix = if extended { "`Sized` " } else { "" };
2550 let mut diag = self.dcx().struct_span_err(
2551 span,
2552 ::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}"),
2553 );
2554 if is_sized {
2555 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!(
2556 "{subject} are not implicitly bounded by `Sized`, \
2557 so there is nothing to relax"
2558 ));
2559 }
2560 diag.emit();
2561 };
2562
2563 match reason {
2564 RelaxedBoundForbiddenReason::TraitObjectTy => {
2565 gate("trait object types", "trait object types");
2566 return;
2567 }
2568 RelaxedBoundForbiddenReason::SuperTrait => {
2569 gate("supertrait bounds", "traits");
2570 return;
2571 }
2572 RelaxedBoundForbiddenReason::TraitAlias => {
2573 gate("trait alias bounds", "trait aliases");
2574 return;
2575 }
2576 RelaxedBoundForbiddenReason::AssocTyBounds
2577 | RelaxedBoundForbiddenReason::WhereBound => {}
2578 };
2579 }
2580 }
2581
2582 self.dcx()
2583 .struct_span_err(span, "this relaxed bound is not permitted here")
2584 .with_note(
2585 "in this context, relaxed bounds are only allowed on \
2586 type parameters defined on the closest item",
2587 )
2588 .emit();
2589 }
2590
2591 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2591u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:2591",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2591u32),
::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)]
2592 fn lower_param_bounds(
2593 &mut self,
2594 bounds: &[GenericBound],
2595 rbp: RelaxedBoundPolicy<'_>,
2596 itctx: ImplTraitContext,
2597 ) -> hir::GenericBounds<'hir> {
2598 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2599 }
2600
2601 fn lower_param_bounds_mut(
2602 &mut self,
2603 bounds: &[GenericBound],
2604 mut rbp: RelaxedBoundPolicy<'_>,
2605 itctx: ImplTraitContext,
2606 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2607 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp.reborrow(), itctx))
2608 }
2609
2610 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2610u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:2610",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2610u32),
::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)]
2611 fn lower_universal_param_and_bounds(
2612 &mut self,
2613 node_id: NodeId,
2614 span: Span,
2615 ident: Ident,
2616 bounds: &[GenericBound],
2617 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2618 let def_id = self.local_def_id(node_id);
2620 let span = self.lower_span(span);
2621
2622 let param = hir::GenericParam {
2624 hir_id: self.lower_node_id(node_id),
2625 def_id,
2626 name: ParamName::Plain(self.lower_ident(ident)),
2627 pure_wrt_drop: false,
2628 span,
2629 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2630 colon_span: None,
2631 source: hir::GenericParamSource::Generics,
2632 };
2633
2634 let preds = self.lower_generic_bound_predicate(
2635 ident,
2636 node_id,
2637 &GenericParamKind::Type { default: None },
2638 bounds,
2639 None,
2640 span,
2641 RelaxedBoundPolicy::Allowed(&mut Default::default()),
2642 ImplTraitContext::Universal,
2643 hir::PredicateOrigin::ImplTrait,
2644 );
2645
2646 let hir_id = self.next_id();
2647 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2648 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2649 None,
2650 self.arena.alloc(hir::Path {
2651 span,
2652 res,
2653 segments:
2654 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2655 }),
2656 ));
2657
2658 (param, preds, ty)
2659 }
2660
2661 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2664 let block = self.lower_block(b, false);
2665 self.expr_block(block)
2666 }
2667
2668 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2669 match c.value.peel_parens().kind {
2676 ExprKind::Underscore => {
2677 let ct_kind = hir::ConstArgKind::Infer(());
2678 self.arena.alloc(hir::ConstArg {
2679 hir_id: self.lower_node_id(c.id),
2680 kind: ct_kind,
2681 span: self.lower_span(c.value.span),
2682 })
2683 }
2684 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2685 }
2686 }
2687
2688 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2691u32),
::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))]
2692 fn lower_const_path_to_const_arg(
2693 &mut self,
2694 qself: &Option<Box<QSelf>>,
2695 path: &Path,
2696 res: Res<NodeId>,
2697 id: NodeId,
2698 span: Span,
2699 ) -> hir::ConstArg<'hir> {
2700 let context = self.ambient_direct_const_arg_context();
2701 if self.can_lower_path_to_const_arg_direct(qself, path, span, Some(res), context).is_ok() {
2702 let span = self.lower_span(span);
2703 self.lower_path_to_const_arg_direct(id, None, qself, path, span)
2704 } else {
2705 let node_id = self.next_node_id();
2707 let span = self.lower_span(span);
2708
2709 let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2714 let hir_id = self.lower_node_id(node_id);
2715
2716 let path_expr = Expr {
2717 id,
2718 kind: ExprKind::Path(qself.clone(), path.clone()),
2719 span,
2720 attrs: AttrVec::new(),
2721 tokens: None,
2722 };
2723
2724 let ct = self.with_new_scopes(span, |this| {
2725 self.arena.alloc(hir::AnonConst {
2726 def_id,
2727 hir_id,
2728 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2729 span,
2730 })
2731 });
2732 hir::ConstArg {
2733 hir_id: self.next_id(),
2734 kind: hir::ConstArgKind::Anon(ct),
2735 span: self.lower_span(span),
2736 }
2737 }
2738 }
2739
2740 fn lower_const_item_rhs(
2741 &mut self,
2742 body: &Option<Box<Expr>>,
2743 span: Span,
2744 ) -> hir::ConstItemRhs<'hir> {
2745 let is_direct = |body| {
2746 let context = if self.tcx.features().gca_macroless_items() {
2747 self.direct_const_arg_context_enabled_by_gca_macro()
2748 } else {
2749 DirectConstArgContext::GCA_MACRO
2750 };
2751 self.can_lower_expr_to_const_arg_direct(body, context).is_ok()
2752 };
2753 if self.tcx.features().gca_min_const_items()
2754 && let Some(body) = body
2755 && is_direct(body)
2756 {
2757 hir::ConstItemRhs::Direct(
2758 self.arena.alloc(self.lower_expr_to_const_arg_direct(&body, None)),
2759 )
2760 } else {
2761 hir::ConstItemRhs::Body(self.lower_const_body(span, body.as_deref()))
2762 }
2763 }
2764
2765 fn direct_const_arg_context_enabled_by_gca_macro(&self) -> DirectConstArgContext {
2766 let mut result = DirectConstArgContext::GCA_BASE_FEATURES;
2767 if self.tcx.features().gca_min_const_items() {
2768 result |= DirectConstArgContext::GCA_MIN_CONST_ITEMS;
2769 }
2770 if self.tcx.features().gca_adts() {
2771 result |= DirectConstArgContext::GCA_ADTS;
2772 }
2773 result
2774 }
2775
2776 fn ambient_direct_const_arg_context(&self) -> DirectConstArgContext {
2778 if self.tcx.features().gca_macroless_args() {
2779 self.direct_const_arg_context_enabled_by_gca_macro()
2780 } else if self.tcx.features().gca() {
2781 DirectConstArgContext::GCA
2782 } else {
2783 DirectConstArgContext::STABLE
2784 }
2785 }
2786
2787 fn can_lower_path_to_const_arg_direct(
2788 &self,
2789 qself: &Option<Box<QSelf>>,
2790 path: &Path,
2791 span: Span,
2792 res: Option<Res<NodeId>>,
2793 context: DirectConstArgContext,
2794 ) -> Result<(), UnrepresentableConstArgError> {
2795 if context.contains(DirectConstArgContext::PATH_ANY) {
2796 Ok(())
2797 } else if context.contains(DirectConstArgContext::PATH_CONST_CTOR)
2798 && #[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), _)))
2799 {
2800 Ok(())
2803 } else if context.contains(DirectConstArgContext::PATH_PLAIN_PARAM)
2804 && qself.is_none()
2805 && path.is_single_argless_ident()
2806 && #[allow(non_exhaustive_omitted_patterns)] match res {
Some(Res::Def(DefKind::ConstParam, _)) => true,
_ => false,
}matches!(res, Some(Res::Def(DefKind::ConstParam, _)))
2807 {
2808 Ok(())
2809 } else {
2810 Err(UnrepresentableConstArgError { span, will_create_def_ids: false })
2811 }
2812 }
2813
2814 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2814u32),
::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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:2814",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2814u32),
::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)]
2815 fn can_lower_expr_to_const_arg_direct(
2816 &self,
2817 expr: &Expr,
2818 context: DirectConstArgContext,
2819 ) -> Result<(), UnrepresentableConstArgError> {
2820 match &expr.kind {
2822 ExprKind::Call(Expr { kind: ExprKind::Path(_, _), .. }, args)
2823 if context.contains(DirectConstArgContext::TUPLE_CALL) =>
2824 {
2825 for arg in args {
2826 self.can_lower_expr_to_const_arg_direct(arg, context)?;
2827 }
2828 Ok(())
2829 }
2830 ExprKind::Tup(exprs) if context.contains(DirectConstArgContext::TUPLE) => {
2831 for expr in exprs {
2832 self.can_lower_expr_to_const_arg_direct(expr, context)?;
2833 }
2834 Ok(())
2835 }
2836 ExprKind::Path(qself, path) => {
2837 let res =
2838 self.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2839 self.can_lower_path_to_const_arg_direct(qself, path, expr.span, res, context)
2840 }
2841 ExprKind::Struct(se) if context.contains(DirectConstArgContext::STRUCT) => {
2842 for f in &se.fields {
2843 self.can_lower_expr_to_const_arg_direct(&f.expr, context)?;
2844 }
2845 Ok(())
2846 }
2847 ExprKind::Array(elements) if context.contains(DirectConstArgContext::ARRAY) => {
2848 for element in elements {
2849 self.can_lower_expr_to_const_arg_direct(element, context)?;
2850 }
2851 Ok(())
2852 }
2853 ExprKind::Underscore if context.contains(DirectConstArgContext::UNDERSCORE) => Ok(()),
2854 ExprKind::Paren(expr) if context.contains(DirectConstArgContext::PAREN) => {
2855 self.can_lower_expr_to_const_arg_direct(expr, context)
2856 }
2857 ExprKind::Block(block, _)
2858 if context.contains(DirectConstArgContext::BLOCK)
2859 && let [stmt] = block.stmts.as_slice()
2860 && let StmtKind::Expr(expr) = &stmt.kind =>
2861 {
2862 self.can_lower_expr_to_const_arg_direct(expr, context)
2863 }
2864 ExprKind::Lit(_) if context.contains(DirectConstArgContext::LIT) => Ok(()),
2865 ExprKind::Unary(UnOp::Neg, inner_expr)
2866 if context.contains(DirectConstArgContext::LIT)
2867 && let ExprKind::Lit(_) = &inner_expr.kind =>
2868 {
2869 Ok(())
2870 }
2871 ExprKind::ConstBlock(_) if context.contains(DirectConstArgContext::CONST_BLOCK) => {
2872 Ok(())
2873 }
2874 ExprKind::GcaMacro(_) if context.contains(DirectConstArgContext::GCA_MACRO) => {
2875 Ok(())
2878 }
2879 _ => Err(UnrepresentableConstArgError::new(expr)),
2880 }
2881 }
2882
2883 fn lower_path_to_const_arg_direct(
2886 &mut self,
2887 id: NodeId,
2888 id_override: Option<NodeId>,
2889 qself: &Option<Box<QSelf>>,
2890 path: &Path,
2891 span: Span,
2892 ) -> hir::ConstArg<'hir> {
2893 let qpath = self.lower_qpath(
2894 id,
2895 qself,
2896 path,
2897 ParamMode::Explicit,
2898 AllowReturnTypeNotation::No,
2899 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2901 None,
2902 );
2903
2904 let node_id = id_override.unwrap_or(id);
2905 ConstArg { hir_id: self.lower_node_id(node_id), kind: hir::ConstArgKind::Path(qpath), span }
2906 }
2907
2908 {}
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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2910u32),
::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,
Target::ExprField, 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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:2910",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2910u32),
::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)]
2911 fn lower_expr_to_const_arg_direct(
2912 &mut self,
2913 expr: &Expr,
2914 id_override: Option<NodeId>,
2915 ) -> hir::ConstArg<'hir> {
2916 let span = self.lower_span(expr.span);
2917 let node_id = id_override.unwrap_or(expr.id);
2918 match &expr.kind {
2919 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2920 let qpath = self.lower_qpath(
2921 func.id,
2922 qself,
2923 path,
2924 ParamMode::Explicit,
2925 AllowReturnTypeNotation::No,
2926 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2927 None,
2928 );
2929
2930 let lowered_args = self.arena.alloc_from_iter(
2931 args.iter().map(|arg| self.lower_expr_to_const_arg_direct(arg, None)),
2932 );
2933
2934 ConstArg {
2935 hir_id: self.lower_node_id(node_id),
2936 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2937 span,
2938 }
2939 }
2940 ExprKind::Tup(exprs) => {
2941 let exprs = self.arena.alloc_from_iter(
2942 exprs.iter().map(|expr| self.lower_expr_to_const_arg_direct(expr, None)),
2943 );
2944
2945 ConstArg {
2946 hir_id: self.lower_node_id(node_id),
2947 kind: hir::ConstArgKind::Tup(exprs),
2948 span,
2949 }
2950 }
2951 ExprKind::Path(qself, path) => {
2952 self.lower_path_to_const_arg_direct(expr.id, id_override, qself, path, span)
2953 }
2954 ExprKind::Struct(se) => {
2955 let path = self.lower_qpath(
2956 expr.id,
2957 &se.qself,
2958 &se.path,
2959 ParamMode::Explicit,
2963 AllowReturnTypeNotation::No,
2964 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2965 None,
2966 );
2967
2968 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2969 let hir_id = self.lower_node_id(f.id);
2970 self.lower_attrs(
2974 hir_id,
2975 &f.attrs,
2976 f.span,
2977 Target::ExprField,
2978 AstTarget::ExprField(f),
2979 );
2980 let expr = self.lower_expr_to_const_arg_direct(&f.expr, None);
2981
2982 hir::ConstArgExprField {
2983 hir_id,
2984 field: self.lower_ident(f.ident),
2985 expr: self.arena.alloc(expr),
2986 span: self.lower_span(f.span),
2987 }
2988 }));
2989
2990 ConstArg {
2991 hir_id: self.lower_node_id(node_id),
2992 kind: hir::ConstArgKind::Struct(path, fields),
2993 span,
2994 }
2995 }
2996 ExprKind::Array(elements) => {
2997 let lowered_elems = self.arena.alloc_from_iter(
2998 elements
2999 .iter()
3000 .map(|element| self.lower_expr_to_const_arg_direct(element, None)),
3001 );
3002 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
3003 span: self.lower_span(expr.span),
3004 elems: lowered_elems,
3005 });
3006
3007 ConstArg {
3008 hir_id: self.lower_node_id(node_id),
3009 kind: hir::ConstArgKind::Array(array_expr),
3010 span,
3011 }
3012 }
3013 ExprKind::Underscore => ConstArg {
3014 hir_id: self.lower_node_id(node_id),
3015 kind: hir::ConstArgKind::Infer(()),
3016 span,
3017 },
3018 ExprKind::Paren(expr) => self.lower_expr_to_const_arg_direct(expr, id_override),
3019 ExprKind::Block(block, _)
3020 if let [stmt] = block.stmts.as_slice()
3021 && let StmtKind::Expr(expr) = &stmt.kind =>
3022 {
3023 self.lower_expr_to_const_arg_direct(expr, id_override)
3024 }
3025 ExprKind::Lit(literal) => {
3026 let span = self.lower_span(expr.span);
3027 let literal = self.lower_lit(literal, span);
3028
3029 ConstArg {
3030 hir_id: self.lower_node_id(node_id),
3031 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
3032 span,
3033 }
3034 }
3035 ExprKind::Unary(UnOp::Neg, inner_expr)
3036 if let ExprKind::Lit(literal) = &inner_expr.kind =>
3037 {
3038 let span = self.lower_span(expr.span);
3039 let literal = self.lower_lit(literal, span);
3040
3041 let kind = if !matches!(literal.node, LitKind::Int(..)) {
3042 let err = self.dcx().span_err(expr.span, "negated literal must be an integer");
3043 hir::ConstArgKind::Error(err)
3044 } else {
3045 hir::ConstArgKind::Literal { lit: literal.node, negated: true }
3046 };
3047 ConstArg { hir_id: self.lower_node_id(node_id), kind, span }
3048 }
3049 ExprKind::ConstBlock(anon_const) => {
3050 let def_id = self.local_def_id(anon_const.id);
3053 assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
3054 let lowered_anon = self.lower_anon_const_to_anon_const(anon_const, span);
3055 ConstArg {
3056 hir_id: self.lower_node_id(node_id),
3057 kind: hir::ConstArgKind::Anon(lowered_anon),
3058 span,
3059 }
3060 }
3061 ExprKind::GcaMacro(expr) => {
3062 match self.can_lower_expr_to_const_arg_direct(
3066 expr,
3067 self.direct_const_arg_context_enabled_by_gca_macro(),
3068 ) {
3069 Ok(()) => self.lower_expr_to_const_arg_direct(expr, id_override),
3070 Err(err) => err.emit(self),
3071 }
3072 }
3073 _ => {
3074 span_bug!(
3075 expr.span,
3076 "lower_expr_to_const_arg_direct encountered an unlowerable expression, either \
3077 can_lower_expr_to_const_arg_direct returned Ok() on something it shouldn't \
3078 have, or you forgot to check can_lower_expr_to_const_arg_direct first"
3079 );
3080 }
3081 }
3082 }
3083
3084 fn lower_anon_const_to_const_arg_and_alloc(
3087 &mut self,
3088 anon: &AnonConst,
3089 ) -> &'hir hir::ConstArg<'hir> {
3090 self.arena.alloc(self.lower_anon_const_to_const_arg(anon))
3091 }
3092
3093 {}
#[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/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(3093u32),
::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))]
3094 fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
3095 let expr = if self.tcx.features().gca_macroless_args() {
3098 &anon.value
3099 } else {
3100 anon.value.maybe_unwrap_block()
3101 };
3102
3103 let context = self.ambient_direct_const_arg_context();
3104 if self.can_lower_expr_to_const_arg_direct(expr, context).is_ok() {
3105 return self.lower_expr_to_const_arg_direct(expr, Some(anon.id));
3106 }
3107
3108 let lowered_anon = self.lower_anon_const_to_anon_const(anon, anon.value.span);
3109 ConstArg {
3110 hir_id: self.next_id(),
3111 kind: hir::ConstArgKind::Anon(lowered_anon),
3112 span: self.lower_span(anon.value.span),
3113 }
3114 }
3115
3116 fn lower_anon_const_to_anon_const(
3119 &mut self,
3120 c: &AnonConst,
3121 span: Span,
3122 ) -> &'hir hir::AnonConst {
3123 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
3124 let def_id = this.local_def_id(c.id);
3125 let hir_id = this.lower_node_id(c.id);
3126 hir::AnonConst {
3127 def_id,
3128 hir_id,
3129 body: this.lower_const_body(c.value.span, Some(&c.value)),
3130 span: this.lower_span(span),
3131 }
3132 }))
3133 }
3134
3135 fn lower_unsafe_source(&self, u: UnsafeSource) -> hir::UnsafeSource {
3136 match u {
3137 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
3138 UserProvided => hir::UnsafeSource::UserProvided,
3139 }
3140 }
3141
3142 fn lower_trait_bound_modifiers(
3143 &self,
3144 modifiers: TraitBoundModifiers,
3145 ) -> hir::TraitBoundModifiers {
3146 let constness = match modifiers.constness {
3147 BoundConstness::Never => BoundConstness::Never,
3148 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
3149 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
3150 };
3151 let polarity = match modifiers.polarity {
3152 BoundPolarity::Positive => BoundPolarity::Positive,
3153 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
3154 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
3155 };
3156 hir::TraitBoundModifiers { constness, polarity }
3157 }
3158
3159 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
3162 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
3163 }
3164
3165 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
3166 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
3167 }
3168
3169 fn stmt_let_pat(
3170 &mut self,
3171 attrs: Option<&'hir [rustc_attr_ir::Attribute]>,
3172 span: Span,
3173 init: Option<&'hir hir::Expr<'hir>>,
3174 pat: &'hir hir::Pat<'hir>,
3175 source: hir::LocalSource,
3176 ) -> hir::Stmt<'hir> {
3177 let hir_id = self.next_id();
3178 if let Some(a) = attrs {
3179 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
3180 self.curr_owner.attrs.insert(hir_id.local_id, a);
3181 }
3182 let local = hir::LetStmt {
3183 super_: None,
3184 hir_id,
3185 init,
3186 pat,
3187 els: None,
3188 source,
3189 span: self.lower_span(span),
3190 ty: None,
3191 };
3192 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
3193 }
3194
3195 fn stmt_super_let_pat(
3196 &mut self,
3197 span: Span,
3198 pat: &'hir hir::Pat<'hir>,
3199 init: Option<&'hir hir::Expr<'hir>>,
3200 ) -> hir::Stmt<'hir> {
3201 let hir_id = self.next_id();
3202 let span = self.lower_span(span);
3203 let local = hir::LetStmt {
3204 super_: Some(span),
3205 hir_id,
3206 init,
3207 pat,
3208 els: None,
3209 source: hir::LocalSource::Normal,
3210 span,
3211 ty: None,
3212 };
3213 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
3214 }
3215
3216 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
3217 self.block_all(expr.span, &[], Some(expr))
3218 }
3219
3220 fn block_all(
3221 &mut self,
3222 span: Span,
3223 stmts: &'hir [hir::Stmt<'hir>],
3224 expr: Option<&'hir hir::Expr<'hir>>,
3225 ) -> &'hir hir::Block<'hir> {
3226 let blk = hir::Block {
3227 stmts,
3228 expr,
3229 hir_id: self.next_id(),
3230 rules: hir::BlockCheckMode::DefaultBlock,
3231 span: self.lower_span(span),
3232 targeted_by_break: false,
3233 };
3234 self.arena.alloc(blk)
3235 }
3236
3237 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3238 let field = self.single_pat_field(span, pat);
3239 self.pat_lang_item_variant(span, LangItem::ControlFlowContinue, field)
3240 }
3241
3242 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3243 let field = self.single_pat_field(span, pat);
3244 self.pat_lang_item_variant(span, LangItem::ControlFlowBreak, field)
3245 }
3246
3247 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
3248 let field = self.single_pat_field(span, pat);
3249 self.pat_lang_item_variant(span, LangItem::OptionSome, field)
3250 }
3251
3252 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
3253 self.pat_lang_item_variant(span, LangItem::OptionNone, &[])
3254 }
3255
3256 fn single_pat_field(
3257 &mut self,
3258 span: Span,
3259 pat: &'hir hir::Pat<'hir>,
3260 ) -> &'hir [hir::PatField<'hir>] {
3261 let field = hir::PatField {
3262 hir_id: self.next_id(),
3263 ident: Ident::new(sym::integer(0), self.lower_span(span)),
3264 is_shorthand: false,
3265 pat,
3266 span: self.lower_span(span),
3267 };
3268 self.arena.alloc_from_iter([field])arena_vec![self; field]
3269 }
3270
3271 fn pat_lang_item_variant(
3272 &mut self,
3273 span: Span,
3274 lang_item: LangItem,
3275 fields: &'hir [hir::PatField<'hir>],
3276 ) -> &'hir hir::Pat<'hir> {
3277 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
3278 self.pat(span, hir::PatKind::Struct(path, fields, None))
3279 }
3280
3281 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
3282 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
3283 }
3284
3285 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
3286 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
3287 }
3288
3289 fn pat_ident_binding_mode(
3290 &mut self,
3291 span: Span,
3292 ident: Ident,
3293 bm: hir::BindingMode,
3294 ) -> (&'hir hir::Pat<'hir>, HirId) {
3295 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
3296 (self.arena.alloc(pat), hir_id)
3297 }
3298
3299 fn pat_ident_binding_mode_mut(
3300 &mut self,
3301 span: Span,
3302 ident: Ident,
3303 bm: hir::BindingMode,
3304 ) -> (hir::Pat<'hir>, HirId) {
3305 let hir_id = self.next_id();
3306
3307 (
3308 hir::Pat {
3309 hir_id,
3310 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
3311 span: self.lower_span(span),
3312 default_binding_modes: true,
3313 },
3314 hir_id,
3315 )
3316 }
3317
3318 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
3319 self.arena.alloc(hir::Pat {
3320 hir_id: self.next_id(),
3321 kind,
3322 span: self.lower_span(span),
3323 default_binding_modes: true,
3324 })
3325 }
3326
3327 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
3328 hir::Pat {
3329 hir_id: self.next_id(),
3330 kind,
3331 span: self.lower_span(span),
3332 default_binding_modes: false,
3333 }
3334 }
3335
3336 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
3337 let kind = match qpath {
3338 hir::QPath::Resolved(None, path) => {
3339 match path.res {
3341 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
3342 let principal = hir::PolyTraitRef {
3343 bound_generic_params: &[],
3344 modifiers: hir::TraitBoundModifiers::NONE,
3345 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
3346 span: self.lower_span(span),
3347 };
3348
3349 hir_id = self.next_id();
3352 hir::TyKind::TraitObject(
3353 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
3354 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
3355 )
3356 }
3357 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
3358 }
3359 }
3360 _ => hir::TyKind::Path(qpath),
3361 };
3362
3363 hir::Ty { hir_id, kind, span: self.lower_span(span) }
3364 }
3365
3366 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
3371 let r = hir::Lifetime::new(
3372 self.next_id(),
3373 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
3374 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
3375 LifetimeSource::Other,
3376 LifetimeSyntax::Implicit,
3377 );
3378 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs:3378",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/92b5b8c87c61b20adc9001b41baf587634a74734/compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(3378u32),
::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);
3379 self.arena.alloc(r)
3380 }
3381}
3382
3383struct GenericArgsCtor<'hir> {
3385 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
3386 constraints: &'hir [hir::AssocItemConstraint<'hir>],
3387 parenthesized: hir::GenericArgsParentheses,
3388 span: Span,
3389}
3390
3391impl<'hir> GenericArgsCtor<'hir> {
3392 fn is_empty(&self) -> bool {
3393 self.args.is_empty()
3394 && self.constraints.is_empty()
3395 && self.parenthesized == hir::GenericArgsParentheses::No
3396 }
3397
3398 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
3399 let ga = hir::GenericArgs {
3400 args: this.arena.alloc_from_iter(self.args),
3401 constraints: self.constraints,
3402 parenthesized: self.parenthesized,
3403 span_ext: this.lower_span(self.span),
3404 };
3405 this.arena.alloc(ga)
3406 }
3407}
3408
3409struct 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_tuple_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! {
3410 #[derive(Copy, Clone, Debug)]
3411 struct DirectConstArgContext: u16 {
3412 const TUPLE_CALL = 1 << 0;
3413 const TUPLE = 1 << 1;
3414 const PATH_PLAIN_PARAM = 1 << 2;
3415 const PATH_CONST_CTOR = 1 << 3;
3416 const PATH_ANY = 1 << 4;
3417 const STRUCT = 1 << 5;
3418 const ARRAY = 1 << 6;
3419 const UNDERSCORE = 1 << 7;
3420 const PAREN = 1 << 8;
3421 const BLOCK = 1 << 9;
3422 const LIT = 1 << 10;
3423 const CONST_BLOCK = 1 << 11;
3424 const GCA_MACRO = 1 << 12;
3425 }
3426}
3427
3428impl DirectConstArgContext {
3429 const STABLE: DirectConstArgContext = Self::PATH_PLAIN_PARAM;
3432
3433 const GCA: DirectConstArgContext = Self::STABLE.union(Self::GCA_MACRO);
3435
3436 const GCA_BASE_FEATURES: DirectConstArgContext = Self::GCA
3441 .union(DirectConstArgContext::UNDERSCORE)
3442 .union(DirectConstArgContext::PAREN)
3443 .union(DirectConstArgContext::BLOCK)
3444 .union(DirectConstArgContext::LIT)
3445 .union(DirectConstArgContext::CONST_BLOCK);
3446
3447 const GCA_MIN_CONST_ITEMS: DirectConstArgContext = DirectConstArgContext::PATH_ANY;
3449
3450 const GCA_ADTS: DirectConstArgContext = DirectConstArgContext::PATH_CONST_CTOR
3452 .union(DirectConstArgContext::TUPLE_CALL)
3453 .union(DirectConstArgContext::TUPLE)
3454 .union(DirectConstArgContext::STRUCT)
3455 .union(DirectConstArgContext::ARRAY);
3456}
3457
3458#[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)]
3459struct UnrepresentableConstArgError {
3460 span: Span,
3461 will_create_def_ids: bool,
3462}
3463
3464impl UnrepresentableConstArgError {
3465 fn new(expr: &Expr) -> Self {
3466 Self {
3467 span: expr.span,
3468 will_create_def_ids: expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break(),
3469 }
3470 }
3471
3472 fn emit<'hir>(self, lowering_context: &mut LoweringContext<'_, 'hir>) -> ConstArg<'hir> {
3473 let msg = "complex const arguments must be placed inside of a `const` block";
3474 let e = if self.will_create_def_ids {
3475 lowering_context.dcx().span_fatal(self.span, msg)
3479 } else {
3480 lowering_context.dcx().span_err(self.span, msg)
3481 };
3482
3483 ConstArg {
3484 hir_id: lowering_context.next_id(),
3485 kind: hir::ConstArgKind::Error(e),
3486 span: lowering_context.lower_span(self.span),
3487 }
3488 }
3489}