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