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