1#![feature(box_patterns)]
35#![feature(if_let_guard)]
36use std::mem;
39use std::sync::Arc;
40
41use rustc_ast::node_id::NodeMap;
42use rustc_ast::{self as ast, *};
43use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
44use rustc_data_structures::fingerprint::Fingerprint;
45use rustc_data_structures::sorted_map::SortedMap;
46use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
47use rustc_data_structures::sync::spawn;
48use rustc_data_structures::tagged_ptr::TaggedRef;
49use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
50use rustc_hir::attrs::AttributeKind;
51use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
52use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
53use rustc_hir::definitions::{DefPathData, DisambiguatorState};
54use rustc_hir::lints::{AttributeLint, DelayedLint};
55use rustc_hir::{
56 self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
57 LifetimeSyntax, ParamName, Target, TraitCandidate, find_attr,
58};
59use rustc_index::{Idx, IndexSlice, IndexVec};
60use rustc_macros::extension;
61use rustc_middle::span_bug;
62use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
63use rustc_session::parse::add_feature_diagnostics;
64use rustc_span::symbol::{Ident, Symbol, kw, sym};
65use rustc_span::{DUMMY_SP, DesugaringKind, Span};
66use smallvec::SmallVec;
67use thin_vec::ThinVec;
68use tracing::{debug, instrument, trace};
69
70use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
71
72macro_rules! arena_vec {
73 ($this:expr; $($x:expr),*) => (
74 $this.arena.alloc_from_iter([$($x),*])
75 );
76}
77
78mod asm;
79mod block;
80mod contract;
81mod delegation;
82mod errors;
83mod expr;
84mod format;
85mod index;
86mod item;
87mod pat;
88mod path;
89pub mod stability;
90
91struct LoweringContext<'a, 'hir> {
92 tcx: TyCtxt<'hir>,
93 resolver: &'a mut ResolverAstLowering,
94 disambiguator: DisambiguatorState,
95
96 arena: &'hir hir::Arena<'hir>,
98
99 bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
101 define_opaque: Option<&'hir [(Span, LocalDefId)]>,
103 attrs: SortedMap<hir::ItemLocalId, &'hir [hir::Attribute]>,
105 children: Vec<(LocalDefId, hir::MaybeOwner<'hir>)>,
107
108 contract_ensures: Option<(Span, Ident, HirId)>,
109
110 coroutine_kind: Option<hir::CoroutineKind>,
111
112 task_context: Option<HirId>,
115
116 current_item: Option<Span>,
119
120 try_block_scope: TryBlockScope,
121 loop_scope: Option<HirId>,
122 is_in_loop_condition: bool,
123 is_in_dyn_type: bool,
124
125 current_hir_id_owner: hir::OwnerId,
126 item_local_id_counter: hir::ItemLocalId,
127 trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
128
129 impl_trait_defs: Vec<hir::GenericParam<'hir>>,
130 impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
131
132 ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>,
134 #[cfg(debug_assertions)]
136 node_id_to_local_id: NodeMap<hir::ItemLocalId>,
137
138 allow_contracts: Arc<[Symbol]>,
139 allow_try_trait: Arc<[Symbol]>,
140 allow_gen_future: Arc<[Symbol]>,
141 allow_pattern_type: Arc<[Symbol]>,
142 allow_async_gen: Arc<[Symbol]>,
143 allow_async_iterator: Arc<[Symbol]>,
144 allow_for_await: Arc<[Symbol]>,
145 allow_async_fn_traits: Arc<[Symbol]>,
146
147 delayed_lints: Vec<DelayedLint>,
148
149 attribute_parser: AttributeParser<'hir>,
150}
151
152impl<'a, 'hir> LoweringContext<'a, 'hir> {
153 fn new(tcx: TyCtxt<'hir>, resolver: &'a mut ResolverAstLowering) -> Self {
154 let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
155 Self {
156 tcx,
158 resolver,
159 disambiguator: DisambiguatorState::new(),
160 arena: tcx.hir_arena,
161
162 bodies: Vec::new(),
164 define_opaque: None,
165 attrs: SortedMap::default(),
166 children: Vec::default(),
167 contract_ensures: None,
168 current_hir_id_owner: hir::CRATE_OWNER_ID,
169 item_local_id_counter: hir::ItemLocalId::ZERO,
170 ident_and_label_to_local_id: Default::default(),
171 #[cfg(debug_assertions)]
172 node_id_to_local_id: Default::default(),
173 trait_map: Default::default(),
174
175 try_block_scope: TryBlockScope::Function,
177 loop_scope: None,
178 is_in_loop_condition: false,
179 is_in_dyn_type: false,
180 coroutine_kind: None,
181 task_context: None,
182 current_item: None,
183 impl_trait_defs: Vec::new(),
184 impl_trait_bounds: Vec::new(),
185 allow_contracts: [sym::contracts_internals].into(),
186 allow_try_trait: [
187 sym::try_trait_v2,
188 sym::try_trait_v2_residual,
189 sym::yeet_desugar_details,
190 ]
191 .into(),
192 allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
193 allow_gen_future: if tcx.features().async_fn_track_caller() {
194 [sym::gen_future, sym::closure_track_caller].into()
195 } else {
196 [sym::gen_future].into()
197 },
198 allow_for_await: [sym::async_gen_internals, sym::async_iterator].into(),
199 allow_async_fn_traits: [sym::async_fn_traits].into(),
200 allow_async_gen: [sym::async_gen_internals].into(),
201 allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
204
205 attribute_parser: AttributeParser::new(
206 tcx.sess,
207 tcx.features(),
208 registered_tools,
209 Late,
210 ),
211 delayed_lints: Vec::new(),
212 }
213 }
214
215 pub(crate) fn dcx(&self) -> DiagCtxtHandle<'hir> {
216 self.tcx.dcx()
217 }
218}
219
220struct SpanLowerer {
221 is_incremental: bool,
222 def_id: LocalDefId,
223}
224
225impl SpanLowerer {
226 fn lower(&self, span: Span) -> Span {
227 if self.is_incremental {
228 span.with_parent(Some(self.def_id))
229 } else {
230 span
232 }
233 }
234}
235
236impl ResolverAstLoweringExt for ResolverAstLowering {
fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'_>)
-> 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 tcx.get_all_attrs(def_id) {
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(AttributeKind::RustcLegacyConstGenerics {
fn_indexes, .. }) => {
break 'done Some(fn_indexes);
}
_ => {}
}
}
None
}
}.map(|fn_indexes|
fn_indexes.iter().map(|(num, _)| *num).collect())
}
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
self.partial_res_map.get(&id).copied()
}
#[doc =
" Obtains per-namespace resolutions for `use` statement with the given `NodeId`."]
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>> {
self.import_res_map.get(&id).copied().unwrap_or_default()
}
#[doc = " Obtains resolution for a label with the given `NodeId`."]
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
self.label_res_map.get(&id).copied()
}
#[doc = " Obtains resolution for a lifetime with the given `NodeId`."]
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
self.lifetimes_res_map.get(&id).copied()
}
#[doc = " Obtain the list of lifetimes parameters to add to an item."]
#[doc = ""]
#[doc =
" Extra lifetime parameters should only be added in places that can appear"]
#[doc = " as a `binder` in `LifetimeRes`."]
#[doc = ""]
#[doc =
" The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring"]
#[doc = " should appear at the enclosing `PolyTraitRef`."]
fn extra_lifetime_params(&mut self, id: NodeId)
-> Vec<(Ident, NodeId, LifetimeRes)> {
self.extra_lifetime_params_map.get(&id).cloned().unwrap_or_default()
}
}#[extension(trait ResolverAstLoweringExt)]
237impl ResolverAstLowering {
238 fn legacy_const_generic_args(&self, expr: &Expr, tcx: TyCtxt<'_>) -> Option<Vec<usize>> {
239 let ExprKind::Path(None, path) = &expr.kind else {
240 return None;
241 };
242
243 if path.segments.last().unwrap().args.is_some() {
246 return None;
247 }
248
249 let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
250
251 if def_id.is_local() {
255 return None;
256 }
257
258 find_attr!(
259 tcx.get_all_attrs(def_id),
261 AttributeKind::RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes
262 )
263 .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
264 }
265
266 fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
267 self.partial_res_map.get(&id).copied()
268 }
269
270 fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>> {
272 self.import_res_map.get(&id).copied().unwrap_or_default()
273 }
274
275 fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
277 self.label_res_map.get(&id).copied()
278 }
279
280 fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
282 self.lifetimes_res_map.get(&id).copied()
283 }
284
285 fn extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
293 self.extra_lifetime_params_map.get(&id).cloned().unwrap_or_default()
294 }
295}
296
297#[derive(#[automatically_derived]
impl<'a> ::core::clone::Clone for RelaxedBoundPolicy<'a> {
#[inline]
fn clone(&self) -> RelaxedBoundPolicy<'a> {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<&'a [ast::GenericParam]>;
let _: ::core::clone::AssertParamIsClone<RelaxedBoundForbiddenReason>;
*self
}
}Clone, #[automatically_derived]
impl<'a> ::core::marker::Copy for RelaxedBoundPolicy<'a> { }Copy, #[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 =>
::core::fmt::Formatter::write_str(f, "Allowed"),
RelaxedBoundPolicy::AllowedIfOnTyParam(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"AllowedIfOnTyParam", __self_0, &__self_1),
RelaxedBoundPolicy::Forbidden(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Forbidden", &__self_0),
}
}
}Debug)]
302enum RelaxedBoundPolicy<'a> {
303 Allowed,
304 AllowedIfOnTyParam(NodeId, &'a [ast::GenericParam]),
305 Forbidden(RelaxedBoundForbiddenReason),
306}
307
308#[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::LateBoundVarsInScope =>
"LateBoundVarsInScope",
})
}
}Debug)]
309enum RelaxedBoundForbiddenReason {
310 TraitObjectTy,
311 SuperTrait,
312 TraitAlias,
313 AssocTyBounds,
314 LateBoundVarsInScope,
315}
316
317#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ImplTraitContext::Universal =>
::core::fmt::Formatter::write_str(f, "Universal"),
ImplTraitContext::OpaqueTy { origin: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"OpaqueTy", "origin", &__self_0),
ImplTraitContext::InBinding =>
::core::fmt::Formatter::write_str(f, "InBinding"),
ImplTraitContext::FeatureGated(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FeatureGated", __self_0, &__self_1),
ImplTraitContext::Disallowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Disallowed", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitContext { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ImplTraitContext {
#[inline]
fn clone(&self) -> ImplTraitContext {
let _:
::core::clone::AssertParamIsClone<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::clone::AssertParamIsClone<ImplTraitPosition>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitContext {
#[inline]
fn eq(&self, other: &ImplTraitContext) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ImplTraitContext::OpaqueTy { origin: __self_0 },
ImplTraitContext::OpaqueTy { origin: __arg1_0 }) =>
__self_0 == __arg1_0,
(ImplTraitContext::FeatureGated(__self_0, __self_1),
ImplTraitContext::FeatureGated(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ImplTraitContext::Disallowed(__self_0),
ImplTraitContext::Disallowed(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::cmp::AssertParamIsEq<ImplTraitPosition>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq)]
320enum ImplTraitContext {
321 Universal,
327
328 OpaqueTy { origin: hir::OpaqueTyOrigin<LocalDefId> },
333
334 InBinding,
339
340 FeatureGated(ImplTraitPosition, Symbol),
342 Disallowed(ImplTraitPosition),
344}
345
346#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitPosition {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ImplTraitPosition::Path => "Path",
ImplTraitPosition::Variable => "Variable",
ImplTraitPosition::Trait => "Trait",
ImplTraitPosition::Bound => "Bound",
ImplTraitPosition::Generic => "Generic",
ImplTraitPosition::ExternFnParam => "ExternFnParam",
ImplTraitPosition::ClosureParam => "ClosureParam",
ImplTraitPosition::PointerParam => "PointerParam",
ImplTraitPosition::FnTraitParam => "FnTraitParam",
ImplTraitPosition::ExternFnReturn => "ExternFnReturn",
ImplTraitPosition::ClosureReturn => "ClosureReturn",
ImplTraitPosition::PointerReturn => "PointerReturn",
ImplTraitPosition::FnTraitReturn => "FnTraitReturn",
ImplTraitPosition::GenericDefault => "GenericDefault",
ImplTraitPosition::ConstTy => "ConstTy",
ImplTraitPosition::StaticTy => "StaticTy",
ImplTraitPosition::AssocTy => "AssocTy",
ImplTraitPosition::FieldTy => "FieldTy",
ImplTraitPosition::Cast => "Cast",
ImplTraitPosition::ImplSelf => "ImplSelf",
ImplTraitPosition::OffsetOf => "OffsetOf",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitPosition { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ImplTraitPosition {
#[inline]
fn clone(&self) -> ImplTraitPosition { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitPosition {
#[inline]
fn eq(&self, other: &ImplTraitPosition) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitPosition {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {}
}Eq)]
348enum ImplTraitPosition {
349 Path,
350 Variable,
351 Trait,
352 Bound,
353 Generic,
354 ExternFnParam,
355 ClosureParam,
356 PointerParam,
357 FnTraitParam,
358 ExternFnReturn,
359 ClosureReturn,
360 PointerReturn,
361 FnTraitReturn,
362 GenericDefault,
363 ConstTy,
364 StaticTy,
365 AssocTy,
366 FieldTy,
367 Cast,
368 ImplSelf,
369 OffsetOf,
370}
371
372impl std::fmt::Display for ImplTraitPosition {
373 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
374 let name = match self {
375 ImplTraitPosition::Path => "paths",
376 ImplTraitPosition::Variable => "the type of variable bindings",
377 ImplTraitPosition::Trait => "traits",
378 ImplTraitPosition::Bound => "bounds",
379 ImplTraitPosition::Generic => "generics",
380 ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
381 ImplTraitPosition::ClosureParam => "closure parameters",
382 ImplTraitPosition::PointerParam => "`fn` pointer parameters",
383 ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
384 ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
385 ImplTraitPosition::ClosureReturn => "closure return types",
386 ImplTraitPosition::PointerReturn => "`fn` pointer return types",
387 ImplTraitPosition::FnTraitReturn => "the return type of `Fn` trait bounds",
388 ImplTraitPosition::GenericDefault => "generic parameter defaults",
389 ImplTraitPosition::ConstTy => "const types",
390 ImplTraitPosition::StaticTy => "static types",
391 ImplTraitPosition::AssocTy => "associated types",
392 ImplTraitPosition::FieldTy => "field types",
393 ImplTraitPosition::Cast => "cast expression types",
394 ImplTraitPosition::ImplSelf => "impl headers",
395 ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
396 };
397
398 f.write_fmt(format_args!("{0}", name))write!(f, "{name}")
399 }
400}
401
402#[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_receiver_is_total_eq(&self) {}
}Eq)]
403enum FnDeclKind {
404 Fn,
405 Inherent,
406 ExternFn,
407 Closure,
408 Pointer,
409 Trait,
410 Impl,
411}
412
413#[derive(#[automatically_derived]
impl<'a> ::core::marker::Copy for AstOwner<'a> { }Copy, #[automatically_derived]
impl<'a> ::core::clone::Clone for AstOwner<'a> {
#[inline]
fn clone(&self) -> AstOwner<'a> {
let _: ::core::clone::AssertParamIsClone<&'a ast::Crate>;
let _: ::core::clone::AssertParamIsClone<&'a ast::Item>;
let _: ::core::clone::AssertParamIsClone<&'a ast::AssocItem>;
let _: ::core::clone::AssertParamIsClone<visit::AssocCtxt>;
let _: ::core::clone::AssertParamIsClone<&'a ast::ForeignItem>;
*self
}
}Clone)]
414enum AstOwner<'a> {
415 NonOwner,
416 Crate(&'a ast::Crate),
417 Item(&'a ast::Item),
418 AssocItem(&'a ast::AssocItem, visit::AssocCtxt),
419 ForeignItem(&'a ast::ForeignItem),
420}
421
422#[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)]
423enum TryBlockScope {
424 Function,
426 Homogeneous(HirId),
429 Heterogeneous(HirId),
432}
433
434fn index_crate<'a>(
435 node_id_to_def_id: &NodeMap<LocalDefId>,
436 krate: &'a Crate,
437) -> IndexVec<LocalDefId, AstOwner<'a>> {
438 let mut indexer = Indexer { node_id_to_def_id, index: IndexVec::new() };
439 *indexer.index.ensure_contains_elem(CRATE_DEF_ID, || AstOwner::NonOwner) =
440 AstOwner::Crate(krate);
441 visit::walk_crate(&mut indexer, krate);
442 return indexer.index;
443
444 struct Indexer<'s, 'a> {
445 node_id_to_def_id: &'s NodeMap<LocalDefId>,
446 index: IndexVec<LocalDefId, AstOwner<'a>>,
447 }
448
449 impl<'a> visit::Visitor<'a> for Indexer<'_, 'a> {
450 fn visit_attribute(&mut self, _: &'a Attribute) {
451 }
454
455 fn visit_item(&mut self, item: &'a ast::Item) {
456 let def_id = self.node_id_to_def_id[&item.id];
457 *self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) = AstOwner::Item(item);
458 visit::walk_item(self, item)
459 }
460
461 fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: visit::AssocCtxt) {
462 let def_id = self.node_id_to_def_id[&item.id];
463 *self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
464 AstOwner::AssocItem(item, ctxt);
465 visit::walk_assoc_item(self, item, ctxt);
466 }
467
468 fn visit_foreign_item(&mut self, item: &'a ast::ForeignItem) {
469 let def_id = self.node_id_to_def_id[&item.id];
470 *self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
471 AstOwner::ForeignItem(item);
472 visit::walk_item(self, item);
473 }
474 }
475}
476
477fn compute_hir_hash(
480 tcx: TyCtxt<'_>,
481 owners: &IndexSlice<LocalDefId, hir::MaybeOwner<'_>>,
482) -> Fingerprint {
483 let mut hir_body_nodes: Vec<_> = owners
484 .iter_enumerated()
485 .filter_map(|(def_id, info)| {
486 let info = info.as_owner()?;
487 let def_path_hash = tcx.hir_def_path_hash(def_id);
488 Some((def_path_hash, info))
489 })
490 .collect();
491 hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
492
493 tcx.with_stable_hashing_context(|mut hcx| {
494 let mut stable_hasher = StableHasher::new();
495 hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher);
496 stable_hasher.finish()
497 })
498}
499
500pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
501 let sess = tcx.sess;
502 tcx.ensure_done().output_filenames(());
504 tcx.ensure_done().early_lint_checks(());
505 tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
506 tcx.ensure_done().get_lang_items(());
507 let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
508
509 let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
510 let mut owners = IndexVec::from_fn_n(
511 |_| hir::MaybeOwner::Phantom,
512 tcx.definitions_untracked().def_index_count(),
513 );
514
515 let mut lowerer = item::ItemLowerer {
516 tcx,
517 resolver: &mut resolver,
518 ast_index: &ast_index,
519 owners: &mut owners,
520 };
521 for def_id in ast_index.indices() {
522 lowerer.lower_node(def_id);
523 }
524
525 drop(ast_index);
526
527 let prof = sess.prof.clone();
529 spawn(move || {
530 let _timer = prof.verbose_generic_activity("drop_ast");
531 drop(krate);
532 });
533
534 let opt_hir_hash =
536 if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
537 hir::Crate { owners, opt_hir_hash }
538}
539
540#[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)]
541enum ParamMode {
542 Explicit,
544 Optional,
546}
547
548#[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)]
549enum AllowReturnTypeNotation {
550 Yes,
552 No,
554}
555
556enum GenericArgsMode {
557 ParenSugar,
559 ReturnTypeNotation,
561 Err,
563 Silence,
565}
566
567impl<'a, 'hir> LoweringContext<'a, 'hir> {
568 fn create_def(
569 &mut self,
570 node_id: ast::NodeId,
571 name: Option<Symbol>,
572 def_kind: DefKind,
573 def_path_data: DefPathData,
574 span: Span,
575 ) -> LocalDefId {
576 let parent = self.current_hir_id_owner.def_id;
577 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);
578 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!(
579 self.opt_local_def_id(node_id).is_none(),
580 "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
581 node_id,
582 def_kind,
583 self.tcx.hir_def_key(self.local_def_id(node_id)),
584 );
585
586 let def_id = self
587 .tcx
588 .at(span)
589 .create_def(parent, name, def_kind, Some(def_path_data), &mut self.disambiguator)
590 .def_id();
591
592 {
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:592",
"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(592u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("create_def: def_id_to_node_id[{0:?}] <-> {1:?}",
def_id, node_id) as &dyn Value))])
});
} else { ; }
};debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
593 self.resolver.node_id_to_def_id.insert(node_id, def_id);
594
595 def_id
596 }
597
598 fn next_node_id(&mut self) -> NodeId {
599 let start = self.resolver.next_node_id;
600 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
601 self.resolver.next_node_id = ast::NodeId::from_u32(next);
602 start
603 }
604
605 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
608 self.resolver.node_id_to_def_id.get(&node).copied()
609 }
610
611 fn local_def_id(&self, node: NodeId) -> LocalDefId {
612 self.opt_local_def_id(node).unwrap_or_else(|| {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
}panic!("no entry for node id: `{node:?}`"))
613 }
614
615 fn owner_id(&self, node: NodeId) -> hir::OwnerId {
617 hir::OwnerId { def_id: self.local_def_id(node) }
618 }
619
620 #[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(625u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["owner"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&owner)
as &dyn 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 current_attrs = std::mem::take(&mut self.attrs);
let current_bodies = std::mem::take(&mut self.bodies);
let current_define_opaque =
std::mem::take(&mut self.define_opaque);
let current_ident_and_label_to_local_id =
std::mem::take(&mut self.ident_and_label_to_local_id);
let current_node_id_to_local_id =
std::mem::take(&mut self.node_id_to_local_id);
let current_trait_map = std::mem::take(&mut self.trait_map);
let current_owner =
std::mem::replace(&mut self.current_hir_id_owner, owner_id);
let current_local_counter =
std::mem::replace(&mut self.item_local_id_counter,
hir::ItemLocalId::new(1));
let current_impl_trait_defs =
std::mem::take(&mut self.impl_trait_defs);
let current_impl_trait_bounds =
std::mem::take(&mut self.impl_trait_bounds);
let current_delayed_lints =
std::mem::take(&mut self.delayed_lints);
{
let _old =
self.node_id_to_local_id.insert(owner,
hir::ItemLocalId::ZERO);
if true {
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);
}
}
};
};
}
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.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.node_id_to_local_id = current_node_id_to_local_id; }
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;
if true {
if !!self.children.iter().any(|(id, _)|
id == &owner_id.def_id) {
::core::panicking::panic("assertion failed: !self.children.iter().any(|(id, _)| id == &owner_id.def_id)")
};
};
self.children.push((owner_id.def_id,
hir::MaybeOwner::Owner(info)));
}
}
}#[instrument(level = "debug", skip(self, f))]
626 fn with_hir_id_owner(
627 &mut self,
628 owner: NodeId,
629 f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>,
630 ) {
631 let owner_id = self.owner_id(owner);
632
633 let current_attrs = std::mem::take(&mut self.attrs);
634 let current_bodies = std::mem::take(&mut self.bodies);
635 let current_define_opaque = std::mem::take(&mut self.define_opaque);
636 let current_ident_and_label_to_local_id =
637 std::mem::take(&mut self.ident_and_label_to_local_id);
638
639 #[cfg(debug_assertions)]
640 let current_node_id_to_local_id = std::mem::take(&mut self.node_id_to_local_id);
641 let current_trait_map = std::mem::take(&mut self.trait_map);
642 let current_owner = std::mem::replace(&mut self.current_hir_id_owner, owner_id);
643 let current_local_counter =
644 std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
645 let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
646 let current_impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
647 let current_delayed_lints = std::mem::take(&mut self.delayed_lints);
648
649 #[cfg(debug_assertions)]
655 {
656 let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
657 debug_assert_eq!(_old, None);
658 }
659
660 let item = f(self);
661 assert_eq!(owner_id, item.def_id());
662 assert!(self.impl_trait_defs.is_empty());
664 assert!(self.impl_trait_bounds.is_empty());
665 let info = self.make_owner_info(item);
666
667 self.attrs = current_attrs;
668 self.bodies = current_bodies;
669 self.define_opaque = current_define_opaque;
670 self.ident_and_label_to_local_id = current_ident_and_label_to_local_id;
671
672 #[cfg(debug_assertions)]
673 {
674 self.node_id_to_local_id = current_node_id_to_local_id;
675 }
676 self.trait_map = current_trait_map;
677 self.current_hir_id_owner = current_owner;
678 self.item_local_id_counter = current_local_counter;
679 self.impl_trait_defs = current_impl_trait_defs;
680 self.impl_trait_bounds = current_impl_trait_bounds;
681 self.delayed_lints = current_delayed_lints;
682
683 debug_assert!(!self.children.iter().any(|(id, _)| id == &owner_id.def_id));
684 self.children.push((owner_id.def_id, hir::MaybeOwner::Owner(info)));
685 }
686
687 fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
688 let attrs = std::mem::take(&mut self.attrs);
689 let mut bodies = std::mem::take(&mut self.bodies);
690 let define_opaque = std::mem::take(&mut self.define_opaque);
691 let trait_map = std::mem::take(&mut self.trait_map);
692 let delayed_lints = std::mem::take(&mut self.delayed_lints).into_boxed_slice();
693
694 #[cfg(debug_assertions)]
695 for (id, attrs) in attrs.iter() {
696 if attrs.is_empty() {
698 {
::core::panicking::panic_fmt(format_args!("Stored empty attributes for {0:?}",
id));
};panic!("Stored empty attributes for {:?}", id);
699 }
700 }
701
702 bodies.sort_by_key(|(k, _)| *k);
703 let bodies = SortedMap::from_presorted_elements(bodies);
704
705 let rustc_middle::hir::Hashes { opt_hash_including_bodies, attrs_hash, delayed_lints_hash } =
707 self.tcx.hash_owner_nodes(node, &bodies, &attrs, &delayed_lints, define_opaque);
708 let num_nodes = self.item_local_id_counter.as_usize();
709 let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
710 let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
711 let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
712 let delayed_lints =
713 hir::lints::DelayedLints { lints: delayed_lints, opt_hash: delayed_lints_hash };
714
715 self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints })
716 }
717
718 x;#[instrument(level = "debug", skip(self), ret)]
724 fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
725 assert_ne!(ast_node_id, DUMMY_NODE_ID);
726
727 let owner = self.current_hir_id_owner;
728 let local_id = self.item_local_id_counter;
729 assert_ne!(local_id, hir::ItemLocalId::ZERO);
730 self.item_local_id_counter.increment_by(1);
731 let hir_id = HirId { owner, local_id };
732
733 if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
734 self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
735 }
736
737 if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
738 self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
739 }
740
741 #[cfg(debug_assertions)]
743 {
744 let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
745 assert_eq!(old, None);
746 }
747
748 hir_id
749 }
750
751 x;#[instrument(level = "debug", skip(self), ret)]
753 fn next_id(&mut self) -> HirId {
754 let owner = self.current_hir_id_owner;
755 let local_id = self.item_local_id_counter;
756 assert_ne!(local_id, hir::ItemLocalId::ZERO);
757 self.item_local_id_counter.increment_by(1);
758 HirId { owner, local_id }
759 }
760
761 #[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(761u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn 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:768",
"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(768u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&res) as
&dyn Value))])
});
} else { ; }
};
res.unwrap_or(Res::Err)
}
}
}#[instrument(level = "trace", skip(self))]
762 fn lower_res(&mut self, res: Res<NodeId>) -> Res {
763 let res: Result<Res, ()> = res.apply_id(|id| {
764 let owner = self.current_hir_id_owner;
765 let local_id = self.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
766 Ok(HirId { owner, local_id })
767 });
768 trace!(?res);
769
770 res.unwrap_or(Res::Err)
776 }
777
778 fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
779 self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
780 }
781
782 fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
783 let per_ns = self.resolver.get_import_res(id);
784 let per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res)));
785 if per_ns.is_empty() {
786 self.dcx().span_delayed_bug(span, "no resolution for an import");
788 let err = Some(Res::Err);
789 return PerNS { type_ns: err, value_ns: err, macro_ns: err };
790 }
791 per_ns
792 }
793
794 fn make_lang_item_qpath(
795 &mut self,
796 lang_item: hir::LangItem,
797 span: Span,
798 args: Option<&'hir hir::GenericArgs<'hir>>,
799 ) -> hir::QPath<'hir> {
800 hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
801 }
802
803 fn make_lang_item_path(
804 &mut self,
805 lang_item: hir::LangItem,
806 span: Span,
807 args: Option<&'hir hir::GenericArgs<'hir>>,
808 ) -> &'hir hir::Path<'hir> {
809 let def_id = self.tcx.require_lang_item(lang_item, span);
810 let def_kind = self.tcx.def_kind(def_id);
811 let res = Res::Def(def_kind, def_id);
812 self.arena.alloc(hir::Path {
813 span,
814 res,
815 segments: self.arena.alloc_from_iter([hir::PathSegment {
816 ident: Ident::new(lang_item.name(), span),
817 hir_id: self.next_id(),
818 res,
819 args,
820 infer_args: args.is_none(),
821 }]),
822 })
823 }
824
825 fn mark_span_with_reason(
828 &self,
829 reason: DesugaringKind,
830 span: Span,
831 allow_internal_unstable: Option<Arc<[Symbol]>>,
832 ) -> Span {
833 self.tcx.with_stable_hashing_context(|hcx| {
834 span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
835 })
836 }
837
838 fn span_lowerer(&self) -> SpanLowerer {
839 SpanLowerer {
840 is_incremental: self.tcx.sess.opts.incremental.is_some(),
841 def_id: self.current_hir_id_owner.def_id,
842 }
843 }
844
845 fn lower_span(&self, span: Span) -> Span {
848 self.span_lowerer().lower(span)
849 }
850
851 fn lower_ident(&self, ident: Ident) -> Ident {
852 Ident::new(ident.name, self.lower_span(ident.span))
853 }
854
855 #[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(856u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["ident", "node_id",
"res", "source"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn 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: Option<hir::GenericParam<'hir>> =
loop {};
return __tracing_attr_fake_return;
}
{
let (name, kind) =
match res {
LifetimeRes::Param { .. } => {
(hir::ParamName::Plain(ident),
hir::LifetimeParamKind::Explicit)
}
LifetimeRes::Fresh { param, kind, .. } => {
let _def_id =
self.create_def(param, Some(kw::UnderscoreLifetime),
DefKind::LifetimeParam,
DefPathData::DesugaredAnonymousLifetime, 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:877",
"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(877u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["_def_id"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&_def_id) as
&dyn Value))])
});
} else { ; }
};
(hir::ParamName::Fresh,
hir::LifetimeParamKind::Elided(kind))
}
LifetimeRes::Static { .. } | LifetimeRes::Error(..) =>
return None,
res => {
::core::panicking::panic_fmt(format_args!("Unexpected lifetime resolution {0:?} for {1:?} at {2:?}",
res, ident, ident.span));
}
};
let hir_id = self.lower_node_id(node_id);
let def_id = self.local_def_id(node_id);
Some(hir::GenericParam {
hir_id,
def_id,
name,
span: self.lower_span(ident.span),
pure_wrt_drop: false,
kind: hir::GenericParamKind::Lifetime { kind },
colon_span: None,
source,
})
}
}
}#[instrument(level = "debug", skip(self))]
857 fn lifetime_res_to_generic_param(
858 &mut self,
859 ident: Ident,
860 node_id: NodeId,
861 res: LifetimeRes,
862 source: hir::GenericParamSource,
863 ) -> Option<hir::GenericParam<'hir>> {
864 let (name, kind) = match res {
865 LifetimeRes::Param { .. } => {
866 (hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit)
867 }
868 LifetimeRes::Fresh { param, kind, .. } => {
869 let _def_id = self.create_def(
871 param,
872 Some(kw::UnderscoreLifetime),
873 DefKind::LifetimeParam,
874 DefPathData::DesugaredAnonymousLifetime,
875 ident.span,
876 );
877 debug!(?_def_id);
878
879 (hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind))
880 }
881 LifetimeRes::Static { .. } | LifetimeRes::Error(..) => return None,
882 res => panic!(
883 "Unexpected lifetime resolution {:?} for {:?} at {:?}",
884 res, ident, ident.span
885 ),
886 };
887 let hir_id = self.lower_node_id(node_id);
888 let def_id = self.local_def_id(node_id);
889 Some(hir::GenericParam {
890 hir_id,
891 def_id,
892 name,
893 span: self.lower_span(ident.span),
894 pure_wrt_drop: false,
895 kind: hir::GenericParamKind::Lifetime { kind },
896 colon_span: None,
897 source,
898 })
899 }
900
901 x;#[instrument(level = "debug", skip(self), ret)]
907 #[inline]
908 fn lower_lifetime_binder(
909 &mut self,
910 binder: NodeId,
911 generic_params: &[GenericParam],
912 ) -> &'hir [hir::GenericParam<'hir>] {
913 let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
916 debug!(?extra_lifetimes);
917 let extra_lifetimes: Vec<_> = extra_lifetimes
918 .into_iter()
919 .filter_map(|(ident, node_id, res)| {
920 self.lifetime_res_to_generic_param(
921 ident,
922 node_id,
923 res,
924 hir::GenericParamSource::Binder,
925 )
926 })
927 .collect();
928 let arena = self.arena;
929 let explicit_generic_params =
930 self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
931 arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
932 }
933
934 fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
935 let was_in_dyn_type = self.is_in_dyn_type;
936 self.is_in_dyn_type = in_scope;
937
938 let result = f(self);
939
940 self.is_in_dyn_type = was_in_dyn_type;
941
942 result
943 }
944
945 fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
946 let current_item = self.current_item;
947 self.current_item = Some(scope_span);
948
949 let was_in_loop_condition = self.is_in_loop_condition;
950 self.is_in_loop_condition = false;
951
952 let old_contract = self.contract_ensures.take();
953
954 let try_block_scope = mem::replace(&mut self.try_block_scope, TryBlockScope::Function);
955 let loop_scope = self.loop_scope.take();
956 let ret = f(self);
957 self.try_block_scope = try_block_scope;
958 self.loop_scope = loop_scope;
959
960 self.contract_ensures = old_contract;
961
962 self.is_in_loop_condition = was_in_loop_condition;
963
964 self.current_item = current_item;
965
966 ret
967 }
968
969 fn lower_attrs(
970 &mut self,
971 id: HirId,
972 attrs: &[Attribute],
973 target_span: Span,
974 target: Target,
975 ) -> &'hir [hir::Attribute] {
976 self.lower_attrs_with_extra(id, attrs, target_span, target, &[])
977 }
978
979 fn lower_attrs_with_extra(
980 &mut self,
981 id: HirId,
982 attrs: &[Attribute],
983 target_span: Span,
984 target: Target,
985 extra_hir_attributes: &[hir::Attribute],
986 ) -> &'hir [hir::Attribute] {
987 if attrs.is_empty() && extra_hir_attributes.is_empty() {
988 &[]
989 } else {
990 let mut lowered_attrs =
991 self.lower_attrs_vec(attrs, self.lower_span(target_span), id, target);
992 lowered_attrs.extend(extra_hir_attributes.iter().cloned());
993
994 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);
995 let ret = self.arena.alloc_from_iter(lowered_attrs);
996
997 if ret.is_empty() {
1004 &[]
1005 } else {
1006 self.attrs.insert(id.local_id, ret);
1007 ret
1008 }
1009 }
1010 }
1011
1012 fn lower_attrs_vec(
1013 &mut self,
1014 attrs: &[Attribute],
1015 target_span: Span,
1016 target_hir_id: HirId,
1017 target: Target,
1018 ) -> Vec<hir::Attribute> {
1019 let l = self.span_lowerer();
1020 self.attribute_parser.parse_attribute_list(
1021 attrs,
1022 target_span,
1023 target,
1024 OmitDoc::Lower,
1025 |s| l.lower(s),
1026 |lint_id, span, kind| {
1027 self.delayed_lints.push(DelayedLint::AttributeParsing(AttributeLint {
1028 lint_id,
1029 id: target_hir_id,
1030 span,
1031 kind,
1032 }));
1033 },
1034 )
1035 }
1036
1037 fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
1038 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);
1039 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);
1040 if let Some(&a) = self.attrs.get(&target_id.local_id) {
1041 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
1042 self.attrs.insert(id.local_id, a);
1043 }
1044 }
1045
1046 fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
1047 args.clone()
1048 }
1049
1050 #[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(1051u32),
::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(&[]) })
} 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:1057",
"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(1057u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["constraint",
"itctx"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&constraint)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&itctx) as
&dyn 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(_)) => {
errors::BadReturnTypeNotation::Inputs {
span: data.inputs_span,
}
}
([], FnRetTy::Default(_)) => {
errors::BadReturnTypeNotation::NeedsDots {
span: data.inputs_span,
}
}
(_, FnRetTy::Ty(ty)) => {
let span = data.inputs_span.shrink_to_hi().to(ty.span);
errors::BadReturnTypeNotation::Output {
span,
suggestion: errors::RTNSuggestion {
output: span,
input: data.inputs_span,
},
}
}
};
let mut err = self.dcx().create_err(err);
if !self.tcx.features().return_type_notation() &&
self.tcx.sess.is_nightly_build() {
add_feature_diagnostics(&mut err, &self.tcx.sess,
sym::return_type_notation);
}
err.emit();
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: data.span,
}
} else {
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
self.lower_angle_bracketed_parameter_data(&data.as_angle_bracketed_args(),
ParamMode::Explicit, itctx).0
}
}
GenericArgs::ParenthesizedElided(span) =>
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: *span,
},
};
gen_args_ctor.into_generic_args(self)
} else { self.arena.alloc(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(errors::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)]
1052 fn lower_assoc_item_constraint(
1053 &mut self,
1054 constraint: &AssocItemConstraint,
1055 itctx: ImplTraitContext,
1056 ) -> hir::AssocItemConstraint<'hir> {
1057 debug!(?constraint, ?itctx);
1058 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1060 let gen_args_ctor = match gen_args {
1061 GenericArgs::AngleBracketed(data) => {
1062 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1063 }
1064 GenericArgs::Parenthesized(data) => {
1065 if let Some(first_char) = constraint.ident.as_str().chars().next()
1066 && first_char.is_ascii_lowercase()
1067 {
1068 let err = match (&data.inputs[..], &data.output) {
1069 ([_, ..], FnRetTy::Default(_)) => {
1070 errors::BadReturnTypeNotation::Inputs { span: data.inputs_span }
1071 }
1072 ([], FnRetTy::Default(_)) => {
1073 errors::BadReturnTypeNotation::NeedsDots { span: data.inputs_span }
1074 }
1075 (_, FnRetTy::Ty(ty)) => {
1077 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1078 errors::BadReturnTypeNotation::Output {
1079 span,
1080 suggestion: errors::RTNSuggestion {
1081 output: span,
1082 input: data.inputs_span,
1083 },
1084 }
1085 }
1086 };
1087 let mut err = self.dcx().create_err(err);
1088 if !self.tcx.features().return_type_notation()
1089 && self.tcx.sess.is_nightly_build()
1090 {
1091 add_feature_diagnostics(
1092 &mut err,
1093 &self.tcx.sess,
1094 sym::return_type_notation,
1095 );
1096 }
1097 err.emit();
1098 GenericArgsCtor {
1099 args: Default::default(),
1100 constraints: &[],
1101 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1102 span: data.span,
1103 }
1104 } else {
1105 self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1106 self.lower_angle_bracketed_parameter_data(
1109 &data.as_angle_bracketed_args(),
1110 ParamMode::Explicit,
1111 itctx,
1112 )
1113 .0
1114 }
1115 }
1116 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1117 args: Default::default(),
1118 constraints: &[],
1119 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1120 span: *span,
1121 },
1122 };
1123 gen_args_ctor.into_generic_args(self)
1124 } else {
1125 self.arena.alloc(hir::GenericArgs::none())
1126 };
1127 let kind = match &constraint.kind {
1128 AssocItemConstraintKind::Equality { term } => {
1129 let term = match term {
1130 Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
1131 Term::Const(c) => self.lower_anon_const_to_const_arg_and_alloc(c).into(),
1132 };
1133 hir::AssocItemConstraintKind::Equality { term }
1134 }
1135 AssocItemConstraintKind::Bound { bounds } => {
1136 if self.is_in_dyn_type {
1138 let suggestion = match itctx {
1139 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1140 let bound_end_span = constraint
1141 .gen_args
1142 .as_ref()
1143 .map_or(constraint.ident.span, |args| args.span());
1144 if bound_end_span.eq_ctxt(constraint.span) {
1145 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1146 } else {
1147 None
1148 }
1149 }
1150 _ => None,
1151 };
1152
1153 let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1154 span: constraint.span,
1155 suggestion,
1156 });
1157 let err_ty =
1158 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1159 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1160 } else {
1161 let bounds = self.lower_param_bounds(
1162 bounds,
1163 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1164 itctx,
1165 );
1166 hir::AssocItemConstraintKind::Bound { bounds }
1167 }
1168 }
1169 };
1170
1171 hir::AssocItemConstraint {
1172 hir_id: self.lower_node_id(constraint.id),
1173 ident: self.lower_ident(constraint.ident),
1174 gen_args,
1175 kind,
1176 span: self.lower_span(constraint.span),
1177 }
1178 }
1179
1180 fn emit_bad_parenthesized_trait_in_assoc_ty(&self, data: &ParenthesizedArgs) {
1181 let sub = if data.inputs.is_empty() {
1183 let parentheses_span =
1184 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1185 AssocTyParenthesesSub::Empty { parentheses_span }
1186 }
1187 else {
1189 let open_param = data.inputs_span.shrink_to_lo().to(data
1191 .inputs
1192 .first()
1193 .unwrap()
1194 .span
1195 .shrink_to_lo());
1196 let close_param =
1198 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1199 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1200 };
1201 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub });
1202 }
1203
1204 #[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(1204u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["arg", "itctx"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn 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(hir::InferArg {
hir_id: self.lower_node_id(ty.id),
span: self.lower_span(ty.span),
});
}
match &ty.kind {
TyKind::Path(None, path) => {
if let Some(res) =
self.resolver.get_partial_res(ty.id).and_then(|partial_res|
partial_res.full_res()) {
if !res.matches_ns(Namespace::TypeNS) &&
path.is_potential_trivial_const_arg() {
{
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:1242",
"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(1242u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("lower_generic_arg: Lowering type argument as const argument: {0:?}",
ty) as &dyn Value))])
});
} else { ; }
};
let ct =
self.lower_const_path_to_const_arg(path, res, ty.id,
ty.span);
return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
}
}
}
_ => {}
}
GenericArg::Type(self.lower_ty_alloc(ty,
itctx).try_as_ambig_ty().unwrap())
}
ast::GenericArg::Const(ct) =>
GenericArg::Const(self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap()),
}
}
}
}#[instrument(level = "debug", skip(self))]
1205 fn lower_generic_arg(
1206 &mut self,
1207 arg: &ast::GenericArg,
1208 itctx: ImplTraitContext,
1209 ) -> hir::GenericArg<'hir> {
1210 match arg {
1211 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1212 lt,
1213 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1214 lt.ident.into(),
1215 )),
1216 ast::GenericArg::Type(ty) => {
1217 if ty.is_maybe_parenthesised_infer() {
1220 return GenericArg::Infer(hir::InferArg {
1221 hir_id: self.lower_node_id(ty.id),
1222 span: self.lower_span(ty.span),
1223 });
1224 }
1225
1226 match &ty.kind {
1227 TyKind::Path(None, path) => {
1234 if let Some(res) = self
1235 .resolver
1236 .get_partial_res(ty.id)
1237 .and_then(|partial_res| partial_res.full_res())
1238 {
1239 if !res.matches_ns(Namespace::TypeNS)
1240 && path.is_potential_trivial_const_arg()
1241 {
1242 debug!(
1243 "lower_generic_arg: Lowering type argument as const argument: {:?}",
1244 ty,
1245 );
1246
1247 let ct =
1248 self.lower_const_path_to_const_arg(path, res, ty.id, ty.span);
1249 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1250 }
1251 }
1252 }
1253 _ => {}
1254 }
1255 GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
1256 }
1257 ast::GenericArg::Const(ct) => GenericArg::Const(
1258 self.lower_anon_const_to_const_arg_and_alloc(ct).try_as_ambig_ct().unwrap(),
1259 ),
1260 }
1261 }
1262
1263 #[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(1263u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["t", "itctx"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&t)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn 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))]
1264 fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1265 self.arena.alloc(self.lower_ty(t, itctx))
1266 }
1267
1268 fn lower_path_ty(
1269 &mut self,
1270 t: &Ty,
1271 qself: &Option<Box<QSelf>>,
1272 path: &Path,
1273 param_mode: ParamMode,
1274 itctx: ImplTraitContext,
1275 ) -> hir::Ty<'hir> {
1276 if qself.is_none()
1282 && let Some(partial_res) = self.resolver.get_partial_res(t.id)
1283 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1284 {
1285 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1286 let bound = this.lower_poly_trait_ref(
1287 &PolyTraitRef {
1288 bound_generic_params: ThinVec::new(),
1289 modifiers: TraitBoundModifiers::NONE,
1290 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1291 span: t.span,
1292 parens: ast::Parens::No,
1293 },
1294 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1295 itctx,
1296 );
1297 let bounds = this.arena.alloc_from_iter([bound]);
1298 let lifetime_bound = this.elided_dyn_bound(t.span);
1299 (bounds, lifetime_bound)
1300 });
1301 let kind = hir::TyKind::TraitObject(
1302 bounds,
1303 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1304 );
1305 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1306 }
1307
1308 let id = self.lower_node_id(t.id);
1309 let qpath = self.lower_qpath(
1310 t.id,
1311 qself,
1312 path,
1313 param_mode,
1314 AllowReturnTypeNotation::Yes,
1315 itctx,
1316 None,
1317 );
1318 self.ty_path(id, t.span, qpath)
1319 }
1320
1321 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1322 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1323 }
1324
1325 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1326 self.ty(span, hir::TyKind::Tup(tys))
1327 }
1328
1329 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1330 let kind = match &t.kind {
1331 TyKind::Infer => hir::TyKind::Infer(()),
1332 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1333 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
1334 TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
1335 TyKind::Ref(region, mt) => {
1336 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1337 hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
1338 }
1339 TyKind::PinnedRef(region, mt) => {
1340 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1341 let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1342 let span = self.lower_span(t.span);
1343 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1344 let args = self.arena.alloc(hir::GenericArgs {
1345 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1346 constraints: &[],
1347 parenthesized: hir::GenericArgsParentheses::No,
1348 span_ext: span,
1349 });
1350 let path = self.make_lang_item_qpath(hir::LangItem::Pin, span, Some(args));
1351 hir::TyKind::Path(path)
1352 }
1353 TyKind::FnPtr(f) => {
1354 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1355 hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1356 generic_params,
1357 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1358 abi: self.lower_extern(f.ext),
1359 decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
1360 param_idents: self.lower_fn_params_to_idents(&f.decl),
1361 }))
1362 }
1363 TyKind::UnsafeBinder(f) => {
1364 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1365 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1366 generic_params,
1367 inner_ty: self.lower_ty_alloc(&f.inner_ty, itctx),
1368 }))
1369 }
1370 TyKind::Never => hir::TyKind::Never,
1371 TyKind::Tup(tys) => hir::TyKind::Tup(
1372 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty(ty, itctx))),
1373 ),
1374 TyKind::Paren(ty) => {
1375 return self.lower_ty(ty, itctx);
1376 }
1377 TyKind::Path(qself, path) => {
1378 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1379 }
1380 TyKind::ImplicitSelf => {
1381 let hir_id = self.next_id();
1382 let res = self.expect_full_res(t.id);
1383 let res = self.lower_res(res);
1384 hir::TyKind::Path(hir::QPath::Resolved(
1385 None,
1386 self.arena.alloc(hir::Path {
1387 res,
1388 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1389 Ident::with_dummy_span(kw::SelfUpper),
1390 hir_id,
1391 res
1392 )],
1393 span: self.lower_span(t.span),
1394 }),
1395 ))
1396 }
1397 TyKind::Array(ty, length) => hir::TyKind::Array(
1398 self.lower_ty_alloc(ty, itctx),
1399 self.lower_array_length_to_const_arg(length),
1400 ),
1401 TyKind::TraitObject(bounds, kind) => {
1402 let mut lifetime_bound = None;
1403 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1404 let bounds =
1405 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1406 GenericBound::Trait(ty) => {
1410 let trait_ref = this.lower_poly_trait_ref(
1411 ty,
1412 RelaxedBoundPolicy::Forbidden(
1413 RelaxedBoundForbiddenReason::TraitObjectTy,
1414 ),
1415 itctx,
1416 );
1417 Some(trait_ref)
1418 }
1419 GenericBound::Outlives(lifetime) => {
1420 if lifetime_bound.is_none() {
1421 lifetime_bound = Some(this.lower_lifetime(
1422 lifetime,
1423 LifetimeSource::Other,
1424 lifetime.ident.into(),
1425 ));
1426 }
1427 None
1428 }
1429 GenericBound::Use(_, span) => {
1431 this.dcx()
1432 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1433 None
1434 }
1435 }));
1436 let lifetime_bound =
1437 lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
1438 (bounds, lifetime_bound)
1439 });
1440 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1441 }
1442 TyKind::ImplTrait(def_node_id, bounds) => {
1443 let span = t.span;
1444 match itctx {
1445 ImplTraitContext::OpaqueTy { origin } => {
1446 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1447 }
1448 ImplTraitContext::Universal => {
1449 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1450 ast::GenericBound::Use(_, span) => Some(span),
1451 _ => None,
1452 }) {
1453 self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnApit { span });
1454 }
1455
1456 let def_id = self.local_def_id(*def_node_id);
1457 let name = self.tcx.item_name(def_id.to_def_id());
1458 let ident = Ident::new(name, span);
1459 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1460 *def_node_id,
1461 span,
1462 ident,
1463 bounds,
1464 );
1465 self.impl_trait_defs.push(param);
1466 if let Some(bounds) = bounds {
1467 self.impl_trait_bounds.push(bounds);
1468 }
1469 path
1470 }
1471 ImplTraitContext::InBinding => hir::TyKind::TraitAscription(
1472 self.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx),
1473 ),
1474 ImplTraitContext::FeatureGated(position, feature) => {
1475 let guar = self
1476 .tcx
1477 .sess
1478 .create_feature_err(
1479 MisplacedImplTrait {
1480 span: t.span,
1481 position: DiagArgFromDisplay(&position),
1482 },
1483 feature,
1484 )
1485 .emit();
1486 hir::TyKind::Err(guar)
1487 }
1488 ImplTraitContext::Disallowed(position) => {
1489 let guar = self.dcx().emit_err(MisplacedImplTrait {
1490 span: t.span,
1491 position: DiagArgFromDisplay(&position),
1492 });
1493 hir::TyKind::Err(guar)
1494 }
1495 }
1496 }
1497 TyKind::Pat(ty, pat) => {
1498 hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
1499 }
1500 TyKind::MacCall(_) => {
1501 ::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")
1502 }
1503 TyKind::CVarArgs => {
1504 let guar = self.dcx().span_delayed_bug(
1505 t.span,
1506 "`TyKind::CVarArgs` should have been handled elsewhere",
1507 );
1508 hir::TyKind::Err(guar)
1509 }
1510 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1511 };
1512
1513 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1514 }
1515
1516 fn lower_ty_direct_lifetime(
1517 &mut self,
1518 t: &Ty,
1519 region: Option<Lifetime>,
1520 ) -> &'hir hir::Lifetime {
1521 let (region, syntax) = match region {
1522 Some(region) => (region, region.ident.into()),
1523
1524 None => {
1525 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1526 self.resolver.get_lifetime_res(t.id)
1527 {
1528 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);
1529 start
1530 } else {
1531 self.next_node_id()
1532 };
1533 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1534 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1535 (region, LifetimeSyntax::Implicit)
1536 }
1537 };
1538 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1539 }
1540
1541 x;#[instrument(level = "debug", skip(self), ret)]
1573 fn lower_opaque_impl_trait(
1574 &mut self,
1575 span: Span,
1576 origin: hir::OpaqueTyOrigin<LocalDefId>,
1577 opaque_ty_node_id: NodeId,
1578 bounds: &GenericBounds,
1579 itctx: ImplTraitContext,
1580 ) -> hir::TyKind<'hir> {
1581 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1587
1588 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1589 this.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx)
1590 })
1591 }
1592
1593 fn lower_opaque_inner(
1594 &mut self,
1595 opaque_ty_node_id: NodeId,
1596 origin: hir::OpaqueTyOrigin<LocalDefId>,
1597 opaque_ty_span: Span,
1598 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1599 ) -> hir::TyKind<'hir> {
1600 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1601 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1602 {
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:1602",
"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(1602u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["opaque_ty_def_id",
"opaque_ty_hir_id"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&opaque_ty_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&opaque_ty_hir_id)
as &dyn Value))])
});
} else { ; }
};debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
1603
1604 let bounds = lower_item_bounds(self);
1605 let opaque_ty_def = hir::OpaqueTy {
1606 hir_id: opaque_ty_hir_id,
1607 def_id: opaque_ty_def_id,
1608 bounds,
1609 origin,
1610 span: self.lower_span(opaque_ty_span),
1611 };
1612 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1613
1614 hir::TyKind::OpaqueDef(opaque_ty_def)
1615 }
1616
1617 fn lower_precise_capturing_args(
1618 &mut self,
1619 precise_capturing_args: &[PreciseCapturingArg],
1620 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1621 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1622 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1623 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1624 ),
1625 PreciseCapturingArg::Arg(path, id) => {
1626 let [segment] = path.segments.as_slice() else {
1627 ::core::panicking::panic("explicit panic");panic!();
1628 };
1629 let res = self.resolver.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1630 partial_res.full_res().expect("no partial res expected for precise capture arg")
1631 });
1632 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1633 hir_id: self.lower_node_id(*id),
1634 ident: self.lower_ident(segment.ident),
1635 res: self.lower_res(res),
1636 })
1637 }
1638 }))
1639 }
1640
1641 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1642 self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1643 PatKind::Missing => None,
1644 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1645 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1646 _ => {
1647 self.dcx().span_delayed_bug(
1648 param.pat.span,
1649 "non-missing/ident/wild param pat must trigger an error",
1650 );
1651 None
1652 }
1653 }))
1654 }
1655
1656 #[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(1665u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["decl", "fn_node_id",
"fn_span", "kind", "coro"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_node_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn 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 inputs = &decl.inputs[..];
if c_variadic { 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.local_def_id(fn_node_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.local_def_id(fn_node_id),
in_trait_or_impl: None,
},
},
FnDeclKind::Trait =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.local_def_id(fn_node_id),
in_trait_or_impl: Some(hir::RpitContext::Trait),
},
},
FnDeclKind::Impl =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.local_def_id(fn_node_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)),
},
};
self.arena.alloc(hir::FnDecl {
inputs,
output,
c_variadic,
lifetime_elision_allowed: self.resolver.lifetime_elision_allowed.contains(&fn_node_id),
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,
}
}),
})
}
}
}#[instrument(level = "debug", skip(self))]
1666 fn lower_fn_decl(
1667 &mut self,
1668 decl: &FnDecl,
1669 fn_node_id: NodeId,
1670 fn_span: Span,
1671 kind: FnDeclKind,
1672 coro: Option<CoroutineKind>,
1673 ) -> &'hir hir::FnDecl<'hir> {
1674 let c_variadic = decl.c_variadic();
1675
1676 let mut inputs = &decl.inputs[..];
1680 if c_variadic {
1681 inputs = &inputs[..inputs.len() - 1];
1682 }
1683 let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
1684 let itctx = match kind {
1685 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
1686 ImplTraitContext::Universal
1687 }
1688 FnDeclKind::ExternFn => {
1689 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
1690 }
1691 FnDeclKind::Closure => {
1692 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
1693 }
1694 FnDeclKind::Pointer => {
1695 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
1696 }
1697 };
1698 self.lower_ty(¶m.ty, itctx)
1699 }));
1700
1701 let output = match coro {
1702 Some(coro) => {
1703 let fn_def_id = self.local_def_id(fn_node_id);
1704 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
1705 }
1706 None => match &decl.output {
1707 FnRetTy::Ty(ty) => {
1708 let itctx = match kind {
1709 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
1710 origin: hir::OpaqueTyOrigin::FnReturn {
1711 parent: self.local_def_id(fn_node_id),
1712 in_trait_or_impl: None,
1713 },
1714 },
1715 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
1716 origin: hir::OpaqueTyOrigin::FnReturn {
1717 parent: self.local_def_id(fn_node_id),
1718 in_trait_or_impl: Some(hir::RpitContext::Trait),
1719 },
1720 },
1721 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1722 origin: hir::OpaqueTyOrigin::FnReturn {
1723 parent: self.local_def_id(fn_node_id),
1724 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
1725 },
1726 },
1727 FnDeclKind::ExternFn => {
1728 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
1729 }
1730 FnDeclKind::Closure => {
1731 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
1732 }
1733 FnDeclKind::Pointer => {
1734 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
1735 }
1736 };
1737 hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
1738 }
1739 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
1740 },
1741 };
1742
1743 self.arena.alloc(hir::FnDecl {
1744 inputs,
1745 output,
1746 c_variadic,
1747 lifetime_elision_allowed: self.resolver.lifetime_elision_allowed.contains(&fn_node_id),
1748 implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
1749 let is_mutable_pat = matches!(
1750 arg.pat.kind,
1751 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
1752 );
1753
1754 match &arg.ty.kind {
1755 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
1756 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
1757 TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
1761 if mt.ty.kind.is_implicit_self() =>
1762 {
1763 match mt.mutbl {
1764 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1765 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
1766 }
1767 }
1768 _ => hir::ImplicitSelfKind::None,
1769 }
1770 }),
1771 })
1772 }
1773
1774 #[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(1782u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["output",
"fn_def_id", "coro", "fn_kind"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_kind)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::FnRetTy<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let span = self.lower_span(output.span());
let (opaque_ty_node_id, allowed_features) =
match coro {
CoroutineKind::Async { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::Gen { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
(return_impl_trait_id,
Some(Arc::clone(&self.allow_async_iterator)))
}
};
let opaque_ty_span =
self.mark_span_with_reason(DesugaringKind::Async, span,
allowed_features);
let in_trait_or_impl =
match fn_kind {
FnDeclKind::Trait => Some(hir::RpitContext::Trait),
FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
FnDeclKind::Fn | FnDeclKind::Inherent => None,
FnDeclKind::ExternFn | FnDeclKind::Closure |
FnDeclKind::Pointer =>
::core::panicking::panic("internal error: entered unreachable code"),
};
let opaque_ty_ref =
self.lower_opaque_inner(opaque_ty_node_id,
hir::OpaqueTyOrigin::AsyncFn {
parent: fn_def_id,
in_trait_or_impl,
}, opaque_ty_span,
|this|
{
let bound =
this.lower_coroutine_fn_output_type_to_bound(output, coro,
opaque_ty_span,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: fn_def_id,
in_trait_or_impl,
},
});
this.arena.alloc_from_iter([bound])
});
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}
}
}#[instrument(level = "debug", skip(self))]
1783 fn lower_coroutine_fn_ret_ty(
1784 &mut self,
1785 output: &FnRetTy,
1786 fn_def_id: LocalDefId,
1787 coro: CoroutineKind,
1788 fn_kind: FnDeclKind,
1789 ) -> hir::FnRetTy<'hir> {
1790 let span = self.lower_span(output.span());
1791
1792 let (opaque_ty_node_id, allowed_features) = match coro {
1793 CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
1794 CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
1795 CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
1796 (return_impl_trait_id, Some(Arc::clone(&self.allow_async_iterator)))
1797 }
1798 };
1799
1800 let opaque_ty_span =
1801 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
1802
1803 let in_trait_or_impl = match fn_kind {
1804 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
1805 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
1806 FnDeclKind::Fn | FnDeclKind::Inherent => None,
1807 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
1808 };
1809
1810 let opaque_ty_ref = self.lower_opaque_inner(
1811 opaque_ty_node_id,
1812 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
1813 opaque_ty_span,
1814 |this| {
1815 let bound = this.lower_coroutine_fn_output_type_to_bound(
1816 output,
1817 coro,
1818 opaque_ty_span,
1819 ImplTraitContext::OpaqueTy {
1820 origin: hir::OpaqueTyOrigin::FnReturn {
1821 parent: fn_def_id,
1822 in_trait_or_impl,
1823 },
1824 },
1825 );
1826 arena_vec![this; bound]
1827 },
1828 );
1829
1830 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
1831 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
1832 }
1833
1834 fn lower_coroutine_fn_output_type_to_bound(
1836 &mut self,
1837 output: &FnRetTy,
1838 coro: CoroutineKind,
1839 opaque_ty_span: Span,
1840 itctx: ImplTraitContext,
1841 ) -> hir::GenericBound<'hir> {
1842 let output_ty = match output {
1844 FnRetTy::Ty(ty) => {
1845 self.lower_ty_alloc(ty, itctx)
1849 }
1850 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
1851 };
1852
1853 let (assoc_ty_name, trait_lang_item) = match coro {
1855 CoroutineKind::Async { .. } => (sym::Output, hir::LangItem::Future),
1856 CoroutineKind::Gen { .. } => (sym::Item, hir::LangItem::Iterator),
1857 CoroutineKind::AsyncGen { .. } => (sym::Item, hir::LangItem::AsyncIterator),
1858 };
1859
1860 let bound_args = self.arena.alloc(hir::GenericArgs {
1861 args: &[],
1862 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)],
1863 parenthesized: hir::GenericArgsParentheses::No,
1864 span_ext: DUMMY_SP,
1865 });
1866
1867 hir::GenericBound::Trait(hir::PolyTraitRef {
1868 bound_generic_params: &[],
1869 modifiers: hir::TraitBoundModifiers::NONE,
1870 trait_ref: hir::TraitRef {
1871 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
1872 hir_ref_id: self.next_id(),
1873 },
1874 span: opaque_ty_span,
1875 })
1876 }
1877
1878 #[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(1878u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["tpb", "rbp",
"itctx"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&tpb)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn 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))]
1879 fn lower_param_bound(
1880 &mut self,
1881 tpb: &GenericBound,
1882 rbp: RelaxedBoundPolicy<'_>,
1883 itctx: ImplTraitContext,
1884 ) -> hir::GenericBound<'hir> {
1885 match tpb {
1886 GenericBound::Trait(p) => {
1887 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
1888 }
1889 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
1890 lifetime,
1891 LifetimeSource::OutlivesBound,
1892 lifetime.ident.into(),
1893 )),
1894 GenericBound::Use(args, span) => hir::GenericBound::Use(
1895 self.lower_precise_capturing_args(args),
1896 self.lower_span(*span),
1897 ),
1898 }
1899 }
1900
1901 fn lower_lifetime(
1902 &mut self,
1903 l: &Lifetime,
1904 source: LifetimeSource,
1905 syntax: LifetimeSyntax,
1906 ) -> &'hir hir::Lifetime {
1907 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
1908 }
1909
1910 fn lower_lifetime_hidden_in_path(
1911 &mut self,
1912 id: NodeId,
1913 span: Span,
1914 angle_brackets: AngleBrackets,
1915 ) -> &'hir hir::Lifetime {
1916 self.new_named_lifetime(
1917 id,
1918 id,
1919 Ident::new(kw::UnderscoreLifetime, span),
1920 LifetimeSource::Path { angle_brackets },
1921 LifetimeSyntax::Implicit,
1922 )
1923 }
1924
1925 #[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(1925u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["id", "new_id",
"ident", "source", "syntax"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&new_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&syntax)
as &dyn 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.resolver.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:1959",
"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(&["res"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&res) as
&dyn 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))]
1926 fn new_named_lifetime(
1927 &mut self,
1928 id: NodeId,
1929 new_id: NodeId,
1930 ident: Ident,
1931 source: LifetimeSource,
1932 syntax: LifetimeSyntax,
1933 ) -> &'hir hir::Lifetime {
1934 let res = if let Some(res) = self.resolver.get_lifetime_res(id) {
1935 match res {
1936 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
1937 LifetimeRes::Fresh { param, .. } => {
1938 assert_eq!(ident.name, kw::UnderscoreLifetime);
1939 let param = self.local_def_id(param);
1940 hir::LifetimeKind::Param(param)
1941 }
1942 LifetimeRes::Infer => {
1943 assert_eq!(ident.name, kw::UnderscoreLifetime);
1944 hir::LifetimeKind::Infer
1945 }
1946 LifetimeRes::Static { .. } => {
1947 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1948 hir::LifetimeKind::Static
1949 }
1950 LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
1951 LifetimeRes::ElidedAnchor { .. } => {
1952 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1953 }
1954 }
1955 } else {
1956 hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
1957 };
1958
1959 debug!(?res);
1960 self.arena.alloc(hir::Lifetime::new(
1961 self.lower_node_id(new_id),
1962 self.lower_ident(ident),
1963 res,
1964 source,
1965 syntax,
1966 ))
1967 }
1968
1969 fn lower_generic_params_mut(
1970 &mut self,
1971 params: &[GenericParam],
1972 source: hir::GenericParamSource,
1973 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
1974 params.iter().map(move |param| self.lower_generic_param(param, source))
1975 }
1976
1977 fn lower_generic_params(
1978 &mut self,
1979 params: &[GenericParam],
1980 source: hir::GenericParamSource,
1981 ) -> &'hir [hir::GenericParam<'hir>] {
1982 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
1983 }
1984
1985 #[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(1985u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["param", "source"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn 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_generic_param(¶m));
param
}
}
}#[instrument(level = "trace", skip(self))]
1986 fn lower_generic_param(
1987 &mut self,
1988 param: &GenericParam,
1989 source: hir::GenericParamSource,
1990 ) -> hir::GenericParam<'hir> {
1991 let (name, kind) = self.lower_generic_param_kind(param, source);
1992
1993 let hir_id = self.lower_node_id(param.id);
1994 let param_attrs = ¶m.attrs;
1995 let param_span = param.span();
1996 let param = hir::GenericParam {
1997 hir_id,
1998 def_id: self.local_def_id(param.id),
1999 name,
2000 span: self.lower_span(param.span()),
2001 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
2002 kind,
2003 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2004 source,
2005 };
2006 self.lower_attrs(hir_id, param_attrs, param_span, Target::from_generic_param(¶m));
2007 param
2008 }
2009
2010 fn lower_generic_param_kind(
2011 &mut self,
2012 param: &GenericParam,
2013 source: hir::GenericParamSource,
2014 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2015 match ¶m.kind {
2016 GenericParamKind::Lifetime => {
2017 let ident = self.lower_ident(param.ident);
2020 let param_name = if let Some(LifetimeRes::Error(..)) =
2021 self.resolver.get_lifetime_res(param.id)
2022 {
2023 ParamName::Error(ident)
2024 } else {
2025 ParamName::Plain(ident)
2026 };
2027 let kind =
2028 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2029
2030 (param_name, kind)
2031 }
2032 GenericParamKind::Type { default, .. } => {
2033 let default = default
2036 .as_ref()
2037 .filter(|_| match source {
2038 hir::GenericParamSource::Generics => true,
2039 hir::GenericParamSource::Binder => {
2040 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2041 span: param.span(),
2042 });
2043
2044 false
2045 }
2046 })
2047 .map(|def| {
2048 self.lower_ty_alloc(
2049 def,
2050 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2051 )
2052 });
2053
2054 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2055
2056 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2057 }
2058 GenericParamKind::Const { ty, span: _, default } => {
2059 let ty = self.lower_ty_alloc(
2060 ty,
2061 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2062 );
2063
2064 let default = default
2067 .as_ref()
2068 .filter(|_| match source {
2069 hir::GenericParamSource::Generics => true,
2070 hir::GenericParamSource::Binder => {
2071 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2072 span: param.span(),
2073 });
2074
2075 false
2076 }
2077 })
2078 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2079
2080 (
2081 hir::ParamName::Plain(self.lower_ident(param.ident)),
2082 hir::GenericParamKind::Const { ty, default },
2083 )
2084 }
2085 }
2086 }
2087
2088 fn lower_trait_ref(
2089 &mut self,
2090 modifiers: ast::TraitBoundModifiers,
2091 p: &TraitRef,
2092 itctx: ImplTraitContext,
2093 ) -> hir::TraitRef<'hir> {
2094 let path = match self.lower_qpath(
2095 p.ref_id,
2096 &None,
2097 &p.path,
2098 ParamMode::Explicit,
2099 AllowReturnTypeNotation::No,
2100 itctx,
2101 Some(modifiers),
2102 ) {
2103 hir::QPath::Resolved(None, path) => path,
2104 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2105 };
2106 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2107 }
2108
2109 #[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(2109u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["bound_generic_params",
"modifiers", "trait_ref", "span", "rbp", "itctx"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_generic_params)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&modifiers)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn 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))]
2110 fn lower_poly_trait_ref(
2111 &mut self,
2112 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2113 rbp: RelaxedBoundPolicy<'_>,
2114 itctx: ImplTraitContext,
2115 ) -> hir::PolyTraitRef<'hir> {
2116 let bound_generic_params =
2117 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2118 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2119 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2120
2121 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2122 self.validate_relaxed_bound(trait_ref, *span, rbp);
2123 }
2124
2125 hir::PolyTraitRef {
2126 bound_generic_params,
2127 modifiers,
2128 trait_ref,
2129 span: self.lower_span(*span),
2130 }
2131 }
2132
2133 fn validate_relaxed_bound(
2134 &self,
2135 trait_ref: hir::TraitRef<'_>,
2136 span: Span,
2137 rbp: RelaxedBoundPolicy<'_>,
2138 ) {
2139 match rbp {
2149 RelaxedBoundPolicy::Allowed => return,
2150 RelaxedBoundPolicy::AllowedIfOnTyParam(id, params) => {
2151 if let Some(res) = self.resolver.get_partial_res(id).and_then(|r| r.full_res())
2152 && let Res::Def(DefKind::TyParam, def_id) = res
2153 && params.iter().any(|p| def_id == self.local_def_id(p.id).to_def_id())
2154 {
2155 return;
2156 }
2157 }
2158 RelaxedBoundPolicy::Forbidden(reason) => {
2159 let gate = |context, subject| {
2160 let extended = self.tcx.features().more_maybe_bounds();
2161 let is_sized = trait_ref
2162 .trait_def_id()
2163 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, hir::LangItem::Sized));
2164
2165 if extended && !is_sized {
2166 return;
2167 }
2168
2169 let prefix = if extended { "`Sized` " } else { "" };
2170 let mut diag = self.dcx().struct_span_err(
2171 span,
2172 ::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}"),
2173 );
2174 if is_sized {
2175 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!(
2176 "{subject} are not implicitly bounded by `Sized`, \
2177 so there is nothing to relax"
2178 ));
2179 }
2180 diag.emit();
2181 };
2182
2183 match reason {
2184 RelaxedBoundForbiddenReason::TraitObjectTy => {
2185 gate("trait object types", "trait object types");
2186 return;
2187 }
2188 RelaxedBoundForbiddenReason::SuperTrait => {
2189 gate("supertrait bounds", "traits");
2190 return;
2191 }
2192 RelaxedBoundForbiddenReason::TraitAlias => {
2193 gate("trait alias bounds", "trait aliases");
2194 return;
2195 }
2196 RelaxedBoundForbiddenReason::AssocTyBounds
2197 | RelaxedBoundForbiddenReason::LateBoundVarsInScope => {}
2198 };
2199 }
2200 }
2201
2202 self.dcx()
2203 .struct_span_err(span, "this relaxed bound is not permitted here")
2204 .with_note(
2205 "in this context, relaxed bounds are only allowed on \
2206 type parameters defined on the closest item",
2207 )
2208 .emit();
2209 }
2210
2211 fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
2212 hir::MutTy { ty: self.lower_ty_alloc(&mt.ty, itctx), mutbl: mt.mutbl }
2213 }
2214
2215 x;#[instrument(level = "debug", skip(self), ret)]
2216 fn lower_param_bounds(
2217 &mut self,
2218 bounds: &[GenericBound],
2219 rbp: RelaxedBoundPolicy<'_>,
2220 itctx: ImplTraitContext,
2221 ) -> hir::GenericBounds<'hir> {
2222 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2223 }
2224
2225 fn lower_param_bounds_mut(
2226 &mut self,
2227 bounds: &[GenericBound],
2228 rbp: RelaxedBoundPolicy<'_>,
2229 itctx: ImplTraitContext,
2230 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2231 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp, itctx))
2232 }
2233
2234 x;#[instrument(level = "debug", skip(self), ret)]
2235 fn lower_universal_param_and_bounds(
2236 &mut self,
2237 node_id: NodeId,
2238 span: Span,
2239 ident: Ident,
2240 bounds: &[GenericBound],
2241 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2242 let def_id = self.local_def_id(node_id);
2244 let span = self.lower_span(span);
2245
2246 let param = hir::GenericParam {
2248 hir_id: self.lower_node_id(node_id),
2249 def_id,
2250 name: ParamName::Plain(self.lower_ident(ident)),
2251 pure_wrt_drop: false,
2252 span,
2253 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2254 colon_span: None,
2255 source: hir::GenericParamSource::Generics,
2256 };
2257
2258 let preds = self.lower_generic_bound_predicate(
2259 ident,
2260 node_id,
2261 &GenericParamKind::Type { default: None },
2262 bounds,
2263 None,
2264 span,
2265 RelaxedBoundPolicy::Allowed,
2266 ImplTraitContext::Universal,
2267 hir::PredicateOrigin::ImplTrait,
2268 );
2269
2270 let hir_id = self.next_id();
2271 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2272 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2273 None,
2274 self.arena.alloc(hir::Path {
2275 span,
2276 res,
2277 segments:
2278 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2279 }),
2280 ));
2281
2282 (param, preds, ty)
2283 }
2284
2285 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2288 let block = self.lower_block(b, false);
2289 self.expr_block(block)
2290 }
2291
2292 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2293 match c.value.peel_parens().kind {
2296 ExprKind::Underscore => {
2297 let ct_kind = hir::ConstArgKind::Infer(());
2298 self.arena.alloc(hir::ConstArg {
2299 hir_id: self.lower_node_id(c.id),
2300 kind: ct_kind,
2301 span: self.lower_span(c.value.span),
2302 })
2303 }
2304 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2305 }
2306 }
2307
2308 #[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(2311u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["path", "res",
"ty_id", "span"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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::ConstArg<'hir> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let is_trivial_path =
path.is_potential_trivial_const_arg() &&
#[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::ConstParam, _) => true,
_ => false,
};
let ct_kind =
if is_trivial_path || tcx.features().min_generic_const_args()
{
let qpath =
self.lower_qpath(ty_id, &None, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
hir::ConstArgKind::Path(qpath)
} 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,
DefPathData::LateAnonConst, span);
let hir_id = self.lower_node_id(node_id);
let path_expr =
Expr {
id: ty_id,
kind: ExprKind::Path(None, 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::ConstArgKind::Anon(ct)
};
self.arena.alloc(hir::ConstArg {
hir_id: self.next_id(),
kind: ct_kind,
span: self.lower_span(span),
})
}
}
}#[instrument(level = "debug", skip(self))]
2312 fn lower_const_path_to_const_arg(
2313 &mut self,
2314 path: &Path,
2315 res: Res<NodeId>,
2316 ty_id: NodeId,
2317 span: Span,
2318 ) -> &'hir hir::ConstArg<'hir> {
2319 let tcx = self.tcx;
2320
2321 let is_trivial_path = path.is_potential_trivial_const_arg()
2322 && matches!(res, Res::Def(DefKind::ConstParam, _));
2323 let ct_kind = if is_trivial_path || tcx.features().min_generic_const_args() {
2324 let qpath = self.lower_qpath(
2325 ty_id,
2326 &None,
2327 path,
2328 ParamMode::Explicit,
2329 AllowReturnTypeNotation::No,
2330 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2332 None,
2333 );
2334 hir::ConstArgKind::Path(qpath)
2335 } else {
2336 let node_id = self.next_node_id();
2338 let span = self.lower_span(span);
2339
2340 let def_id = self.create_def(
2345 node_id,
2346 None,
2347 DefKind::AnonConst,
2348 DefPathData::LateAnonConst,
2349 span,
2350 );
2351 let hir_id = self.lower_node_id(node_id);
2352
2353 let path_expr = Expr {
2354 id: ty_id,
2355 kind: ExprKind::Path(None, path.clone()),
2356 span,
2357 attrs: AttrVec::new(),
2358 tokens: None,
2359 };
2360
2361 let ct = self.with_new_scopes(span, |this| {
2362 self.arena.alloc(hir::AnonConst {
2363 def_id,
2364 hir_id,
2365 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2366 span,
2367 })
2368 });
2369 hir::ConstArgKind::Anon(ct)
2370 };
2371
2372 self.arena.alloc(hir::ConstArg {
2373 hir_id: self.next_id(),
2374 kind: ct_kind,
2375 span: self.lower_span(span),
2376 })
2377 }
2378
2379 fn lower_const_item_rhs(
2380 &mut self,
2381 rhs_kind: &ConstItemRhsKind,
2382 span: Span,
2383 ) -> hir::ConstItemRhs<'hir> {
2384 match rhs_kind {
2385 ConstItemRhsKind::Body { rhs: Some(body) } => {
2386 hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body)))
2387 }
2388 ConstItemRhsKind::Body { rhs: None } => {
2389 hir::ConstItemRhs::Body(self.lower_const_body(span, None))
2390 }
2391 ConstItemRhsKind::TypeConst { rhs: Some(anon) } => {
2392 hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon))
2393 }
2394 ConstItemRhsKind::TypeConst { rhs: None } => {
2395 let const_arg = ConstArg {
2396 hir_id: self.next_id(),
2397 kind: hir::ConstArgKind::Error(
2398 self.dcx().span_delayed_bug(DUMMY_SP, "no block"),
2399 ),
2400 span: DUMMY_SP,
2401 };
2402 hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg))
2403 }
2404 }
2405 }
2406
2407 x;#[instrument(level = "debug", skip(self), ret)]
2408 fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir> {
2409 let span = self.lower_span(expr.span);
2410
2411 let overly_complex_const = |this: &mut Self| {
2412 let e = this.dcx().struct_span_err(
2413 expr.span,
2414 "complex const arguments must be placed inside of a `const` block",
2415 );
2416
2417 ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e.emit()), span }
2418 };
2419
2420 match &expr.kind {
2421 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2422 let qpath = self.lower_qpath(
2423 func.id,
2424 qself,
2425 path,
2426 ParamMode::Explicit,
2427 AllowReturnTypeNotation::No,
2428 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2429 None,
2430 );
2431
2432 let lowered_args = self.arena.alloc_from_iter(args.iter().map(|arg| {
2433 let const_arg = self.lower_expr_to_const_arg_direct(arg);
2434 &*self.arena.alloc(const_arg)
2435 }));
2436
2437 ConstArg {
2438 hir_id: self.next_id(),
2439 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2440 span,
2441 }
2442 }
2443 ExprKind::Tup(exprs) => {
2444 let exprs = self.arena.alloc_from_iter(exprs.iter().map(|expr| {
2445 let expr = self.lower_expr_to_const_arg_direct(&expr);
2446 &*self.arena.alloc(expr)
2447 }));
2448
2449 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(exprs), span }
2450 }
2451 ExprKind::Path(qself, path) => {
2452 let qpath = self.lower_qpath(
2453 expr.id,
2454 qself,
2455 path,
2456 ParamMode::Explicit,
2457 AllowReturnTypeNotation::No,
2458 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2460 None,
2461 );
2462
2463 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath), span }
2464 }
2465 ExprKind::Struct(se) => {
2466 let path = self.lower_qpath(
2467 expr.id,
2468 &se.qself,
2469 &se.path,
2470 ParamMode::Explicit,
2474 AllowReturnTypeNotation::No,
2475 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2476 None,
2477 );
2478
2479 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2480 let hir_id = self.lower_node_id(f.id);
2481 self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField);
2485 let expr = self.lower_expr_to_const_arg_direct(&f.expr);
2486
2487 &*self.arena.alloc(hir::ConstArgExprField {
2488 hir_id,
2489 field: self.lower_ident(f.ident),
2490 expr: self.arena.alloc(expr),
2491 span: self.lower_span(f.span),
2492 })
2493 }));
2494
2495 ConstArg {
2496 hir_id: self.next_id(),
2497 kind: hir::ConstArgKind::Struct(path, fields),
2498 span,
2499 }
2500 }
2501 ExprKind::Array(elements) => {
2502 let lowered_elems = self.arena.alloc_from_iter(elements.iter().map(|element| {
2503 let const_arg = self.lower_expr_to_const_arg_direct(element);
2504 &*self.arena.alloc(const_arg)
2505 }));
2506 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
2507 span: self.lower_span(expr.span),
2508 elems: lowered_elems,
2509 });
2510
2511 ConstArg {
2512 hir_id: self.next_id(),
2513 kind: hir::ConstArgKind::Array(array_expr),
2514 span,
2515 }
2516 }
2517 ExprKind::Underscore => ConstArg {
2518 hir_id: self.lower_node_id(expr.id),
2519 kind: hir::ConstArgKind::Infer(()),
2520 span,
2521 },
2522 ExprKind::Block(block, _) => {
2523 if let [stmt] = block.stmts.as_slice()
2524 && let StmtKind::Expr(expr) = &stmt.kind
2525 && matches!(
2526 expr.kind,
2527 ExprKind::Block(..)
2528 | ExprKind::Path(..)
2529 | ExprKind::Struct(..)
2530 | ExprKind::Call(..)
2531 | ExprKind::Tup(..)
2532 | ExprKind::Array(..)
2533 | ExprKind::ConstBlock(..)
2534 )
2535 {
2536 return self.lower_expr_to_const_arg_direct(expr);
2537 }
2538
2539 overly_complex_const(self)
2540 }
2541 ExprKind::Lit(literal) => {
2542 let span = expr.span;
2543 let literal = self.lower_lit(literal, span);
2544
2545 ConstArg {
2546 hir_id: self.lower_node_id(expr.id),
2547 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
2548 span,
2549 }
2550 }
2551 ExprKind::Unary(UnOp::Neg, inner_expr)
2552 if let ExprKind::Lit(literal) = &inner_expr.kind =>
2553 {
2554 let span = expr.span;
2555 let literal = self.lower_lit(literal, span);
2556
2557 ConstArg {
2558 hir_id: self.lower_node_id(expr.id),
2559 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: true },
2560 span,
2561 }
2562 }
2563 ExprKind::ConstBlock(anon_const) => {
2564 let def_id = self.local_def_id(anon_const.id);
2565 assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
2566 self.lower_anon_const_to_const_arg(anon_const, span)
2567 }
2568 _ => overly_complex_const(self),
2569 }
2570 }
2571
2572 fn lower_anon_const_to_const_arg_and_alloc(
2575 &mut self,
2576 anon: &AnonConst,
2577 ) -> &'hir hir::ConstArg<'hir> {
2578 self.arena.alloc(self.lower_anon_const_to_const_arg(anon, anon.value.span))
2579 }
2580
2581 #[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(2581u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["anon", "span"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&anon)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn 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 tcx = self.tcx;
if tcx.features().min_generic_const_args() {
return match anon.mgca_disambiguation {
MgcaDisambiguation::AnonConst => {
let lowered_anon =
self.lower_anon_const_to_anon_const(anon, span);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
span: lowered_anon.span,
}
}
MgcaDisambiguation::Direct =>
self.lower_expr_to_const_arg_direct(&anon.value),
};
}
let expr =
if let ExprKind::Block(block, _) = &anon.value.kind &&
let [stmt] = block.stmts.as_slice() &&
let StmtKind::Expr(expr) = &stmt.kind &&
let ExprKind::Path(..) = &expr.kind {
expr
} else { &anon.value };
let maybe_res =
self.resolver.get_partial_res(expr.id).and_then(|partial_res|
partial_res.full_res());
if let ExprKind::Path(qself, path) = &expr.kind &&
path.is_potential_trivial_const_arg() &&
#[allow(non_exhaustive_omitted_patterns)] match maybe_res {
Some(Res::Def(DefKind::ConstParam, _)) => true,
_ => false,
} {
let qpath =
self.lower_qpath(expr.id, qself, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
return ConstArg {
hir_id: self.lower_node_id(anon.id),
kind: hir::ConstArgKind::Path(qpath),
span: self.lower_span(expr.span),
};
}
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(expr.span),
}
}
}
}#[instrument(level = "debug", skip(self))]
2582 fn lower_anon_const_to_const_arg(
2583 &mut self,
2584 anon: &AnonConst,
2585 span: Span,
2586 ) -> hir::ConstArg<'hir> {
2587 let tcx = self.tcx;
2588
2589 if tcx.features().min_generic_const_args() {
2595 return match anon.mgca_disambiguation {
2596 MgcaDisambiguation::AnonConst => {
2597 let lowered_anon = self.lower_anon_const_to_anon_const(anon, span);
2598 ConstArg {
2599 hir_id: self.next_id(),
2600 kind: hir::ConstArgKind::Anon(lowered_anon),
2601 span: lowered_anon.span,
2602 }
2603 }
2604 MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
2605 };
2606 }
2607
2608 let expr = if let ExprKind::Block(block, _) = &anon.value.kind
2611 && let [stmt] = block.stmts.as_slice()
2612 && let StmtKind::Expr(expr) = &stmt.kind
2613 && let ExprKind::Path(..) = &expr.kind
2614 {
2615 expr
2616 } else {
2617 &anon.value
2618 };
2619
2620 let maybe_res =
2621 self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2622 if let ExprKind::Path(qself, path) = &expr.kind
2623 && path.is_potential_trivial_const_arg()
2624 && matches!(maybe_res, Some(Res::Def(DefKind::ConstParam, _)))
2625 {
2626 let qpath = self.lower_qpath(
2627 expr.id,
2628 qself,
2629 path,
2630 ParamMode::Explicit,
2631 AllowReturnTypeNotation::No,
2632 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2633 None,
2634 );
2635
2636 return ConstArg {
2637 hir_id: self.lower_node_id(anon.id),
2638 kind: hir::ConstArgKind::Path(qpath),
2639 span: self.lower_span(expr.span),
2640 };
2641 }
2642
2643 let lowered_anon = self.lower_anon_const_to_anon_const(anon, anon.value.span);
2644 ConstArg {
2645 hir_id: self.next_id(),
2646 kind: hir::ConstArgKind::Anon(lowered_anon),
2647 span: self.lower_span(expr.span),
2648 }
2649 }
2650
2651 fn lower_anon_const_to_anon_const(
2654 &mut self,
2655 c: &AnonConst,
2656 span: Span,
2657 ) -> &'hir hir::AnonConst {
2658 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
2659 let def_id = this.local_def_id(c.id);
2660 let hir_id = this.lower_node_id(c.id);
2661 hir::AnonConst {
2662 def_id,
2663 hir_id,
2664 body: this.lower_const_body(c.value.span, Some(&c.value)),
2665 span: this.lower_span(span),
2666 }
2667 }))
2668 }
2669
2670 fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
2671 match u {
2672 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
2673 UserProvided => hir::UnsafeSource::UserProvided,
2674 }
2675 }
2676
2677 fn lower_trait_bound_modifiers(
2678 &mut self,
2679 modifiers: TraitBoundModifiers,
2680 ) -> hir::TraitBoundModifiers {
2681 let constness = match modifiers.constness {
2682 BoundConstness::Never => BoundConstness::Never,
2683 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
2684 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
2685 };
2686 let polarity = match modifiers.polarity {
2687 BoundPolarity::Positive => BoundPolarity::Positive,
2688 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
2689 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2690 };
2691 hir::TraitBoundModifiers { constness, polarity }
2692 }
2693
2694 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2697 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
2698 }
2699
2700 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
2701 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
2702 }
2703
2704 fn stmt_let_pat(
2705 &mut self,
2706 attrs: Option<&'hir [hir::Attribute]>,
2707 span: Span,
2708 init: Option<&'hir hir::Expr<'hir>>,
2709 pat: &'hir hir::Pat<'hir>,
2710 source: hir::LocalSource,
2711 ) -> hir::Stmt<'hir> {
2712 let hir_id = self.next_id();
2713 if let Some(a) = attrs {
2714 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
2715 self.attrs.insert(hir_id.local_id, a);
2716 }
2717 let local = hir::LetStmt {
2718 super_: None,
2719 hir_id,
2720 init,
2721 pat,
2722 els: None,
2723 source,
2724 span: self.lower_span(span),
2725 ty: None,
2726 };
2727 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2728 }
2729
2730 fn stmt_super_let_pat(
2731 &mut self,
2732 span: Span,
2733 pat: &'hir hir::Pat<'hir>,
2734 init: Option<&'hir hir::Expr<'hir>>,
2735 ) -> hir::Stmt<'hir> {
2736 let hir_id = self.next_id();
2737 let span = self.lower_span(span);
2738 let local = hir::LetStmt {
2739 super_: Some(span),
2740 hir_id,
2741 init,
2742 pat,
2743 els: None,
2744 source: hir::LocalSource::Normal,
2745 span,
2746 ty: None,
2747 };
2748 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2749 }
2750
2751 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
2752 self.block_all(expr.span, &[], Some(expr))
2753 }
2754
2755 fn block_all(
2756 &mut self,
2757 span: Span,
2758 stmts: &'hir [hir::Stmt<'hir>],
2759 expr: Option<&'hir hir::Expr<'hir>>,
2760 ) -> &'hir hir::Block<'hir> {
2761 let blk = hir::Block {
2762 stmts,
2763 expr,
2764 hir_id: self.next_id(),
2765 rules: hir::BlockCheckMode::DefaultBlock,
2766 span: self.lower_span(span),
2767 targeted_by_break: false,
2768 };
2769 self.arena.alloc(blk)
2770 }
2771
2772 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2773 let field = self.single_pat_field(span, pat);
2774 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field)
2775 }
2776
2777 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2778 let field = self.single_pat_field(span, pat);
2779 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowBreak, field)
2780 }
2781
2782 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2783 let field = self.single_pat_field(span, pat);
2784 self.pat_lang_item_variant(span, hir::LangItem::OptionSome, field)
2785 }
2786
2787 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
2788 self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[])
2789 }
2790
2791 fn single_pat_field(
2792 &mut self,
2793 span: Span,
2794 pat: &'hir hir::Pat<'hir>,
2795 ) -> &'hir [hir::PatField<'hir>] {
2796 let field = hir::PatField {
2797 hir_id: self.next_id(),
2798 ident: Ident::new(sym::integer(0), self.lower_span(span)),
2799 is_shorthand: false,
2800 pat,
2801 span: self.lower_span(span),
2802 };
2803 self.arena.alloc_from_iter([field])arena_vec![self; field]
2804 }
2805
2806 fn pat_lang_item_variant(
2807 &mut self,
2808 span: Span,
2809 lang_item: hir::LangItem,
2810 fields: &'hir [hir::PatField<'hir>],
2811 ) -> &'hir hir::Pat<'hir> {
2812 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2813 self.pat(span, hir::PatKind::Struct(path, fields, None))
2814 }
2815
2816 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
2817 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
2818 }
2819
2820 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
2821 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
2822 }
2823
2824 fn pat_ident_binding_mode(
2825 &mut self,
2826 span: Span,
2827 ident: Ident,
2828 bm: hir::BindingMode,
2829 ) -> (&'hir hir::Pat<'hir>, HirId) {
2830 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
2831 (self.arena.alloc(pat), hir_id)
2832 }
2833
2834 fn pat_ident_binding_mode_mut(
2835 &mut self,
2836 span: Span,
2837 ident: Ident,
2838 bm: hir::BindingMode,
2839 ) -> (hir::Pat<'hir>, HirId) {
2840 let hir_id = self.next_id();
2841
2842 (
2843 hir::Pat {
2844 hir_id,
2845 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
2846 span: self.lower_span(span),
2847 default_binding_modes: true,
2848 },
2849 hir_id,
2850 )
2851 }
2852
2853 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2854 self.arena.alloc(hir::Pat {
2855 hir_id: self.next_id(),
2856 kind,
2857 span: self.lower_span(span),
2858 default_binding_modes: true,
2859 })
2860 }
2861
2862 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
2863 hir::Pat {
2864 hir_id: self.next_id(),
2865 kind,
2866 span: self.lower_span(span),
2867 default_binding_modes: false,
2868 }
2869 }
2870
2871 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
2872 let kind = match qpath {
2873 hir::QPath::Resolved(None, path) => {
2874 match path.res {
2876 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
2877 let principal = hir::PolyTraitRef {
2878 bound_generic_params: &[],
2879 modifiers: hir::TraitBoundModifiers::NONE,
2880 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
2881 span: self.lower_span(span),
2882 };
2883
2884 hir_id = self.next_id();
2887 hir::TyKind::TraitObject(
2888 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
2889 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
2890 )
2891 }
2892 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
2893 }
2894 }
2895 _ => hir::TyKind::Path(qpath),
2896 };
2897
2898 hir::Ty { hir_id, kind, span: self.lower_span(span) }
2899 }
2900
2901 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
2906 let r = hir::Lifetime::new(
2907 self.next_id(),
2908 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
2909 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
2910 LifetimeSource::Other,
2911 LifetimeSyntax::Implicit,
2912 );
2913 {
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:2913",
"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(2913u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("elided_dyn_bound: r={0:?}",
r) as &dyn Value))])
});
} else { ; }
};debug!("elided_dyn_bound: r={:?}", r);
2914 self.arena.alloc(r)
2915 }
2916}
2917
2918struct GenericArgsCtor<'hir> {
2920 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
2921 constraints: &'hir [hir::AssocItemConstraint<'hir>],
2922 parenthesized: hir::GenericArgsParentheses,
2923 span: Span,
2924}
2925
2926impl<'hir> GenericArgsCtor<'hir> {
2927 fn is_empty(&self) -> bool {
2928 self.args.is_empty()
2929 && self.constraints.is_empty()
2930 && self.parenthesized == hir::GenericArgsParentheses::No
2931 }
2932
2933 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
2934 let ga = hir::GenericArgs {
2935 args: this.arena.alloc_from_iter(self.args),
2936 constraints: self.constraints,
2937 parenthesized: self.parenthesized,
2938 span_ext: this.lower_span(self.span),
2939 };
2940 this.arena.alloc(ga)
2941 }
2942}