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 =
self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
let res =
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 => hir::LifetimeKind::Error,
LifetimeRes::ElidedAnchor { .. } => {
{
::core::panicking::panic_fmt(format_args!("Unexpected `ElidedAnchar` {0:?} at {1:?}",
ident, 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:1956",
"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(1956u32),
::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 = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
1935 let res = 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 => hir::LifetimeKind::Error,
1951 LifetimeRes::ElidedAnchor { .. } => {
1952 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1953 }
1954 };
1955
1956 debug!(?res);
1957 self.arena.alloc(hir::Lifetime::new(
1958 self.lower_node_id(new_id),
1959 self.lower_ident(ident),
1960 res,
1961 source,
1962 syntax,
1963 ))
1964 }
1965
1966 fn lower_generic_params_mut(
1967 &mut self,
1968 params: &[GenericParam],
1969 source: hir::GenericParamSource,
1970 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
1971 params.iter().map(move |param| self.lower_generic_param(param, source))
1972 }
1973
1974 fn lower_generic_params(
1975 &mut self,
1976 params: &[GenericParam],
1977 source: hir::GenericParamSource,
1978 ) -> &'hir [hir::GenericParam<'hir>] {
1979 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
1980 }
1981
1982 #[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(1982u32),
::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))]
1983 fn lower_generic_param(
1984 &mut self,
1985 param: &GenericParam,
1986 source: hir::GenericParamSource,
1987 ) -> hir::GenericParam<'hir> {
1988 let (name, kind) = self.lower_generic_param_kind(param, source);
1989
1990 let hir_id = self.lower_node_id(param.id);
1991 let param_attrs = ¶m.attrs;
1992 let param_span = param.span();
1993 let param = hir::GenericParam {
1994 hir_id,
1995 def_id: self.local_def_id(param.id),
1996 name,
1997 span: self.lower_span(param.span()),
1998 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
1999 kind,
2000 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2001 source,
2002 };
2003 self.lower_attrs(hir_id, param_attrs, param_span, Target::from_generic_param(¶m));
2004 param
2005 }
2006
2007 fn lower_generic_param_kind(
2008 &mut self,
2009 param: &GenericParam,
2010 source: hir::GenericParamSource,
2011 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2012 match ¶m.kind {
2013 GenericParamKind::Lifetime => {
2014 let ident = self.lower_ident(param.ident);
2017 let param_name =
2018 if let Some(LifetimeRes::Error) = self.resolver.get_lifetime_res(param.id) {
2019 ParamName::Error(ident)
2020 } else {
2021 ParamName::Plain(ident)
2022 };
2023 let kind =
2024 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2025
2026 (param_name, kind)
2027 }
2028 GenericParamKind::Type { default, .. } => {
2029 let default = default
2032 .as_ref()
2033 .filter(|_| match source {
2034 hir::GenericParamSource::Generics => true,
2035 hir::GenericParamSource::Binder => {
2036 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2037 span: param.span(),
2038 });
2039
2040 false
2041 }
2042 })
2043 .map(|def| {
2044 self.lower_ty_alloc(
2045 def,
2046 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2047 )
2048 });
2049
2050 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2051
2052 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2053 }
2054 GenericParamKind::Const { ty, span: _, default } => {
2055 let ty = self.lower_ty_alloc(
2056 ty,
2057 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2058 );
2059
2060 let default = default
2063 .as_ref()
2064 .filter(|_| match source {
2065 hir::GenericParamSource::Generics => true,
2066 hir::GenericParamSource::Binder => {
2067 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2068 span: param.span(),
2069 });
2070
2071 false
2072 }
2073 })
2074 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2075
2076 (
2077 hir::ParamName::Plain(self.lower_ident(param.ident)),
2078 hir::GenericParamKind::Const { ty, default },
2079 )
2080 }
2081 }
2082 }
2083
2084 fn lower_trait_ref(
2085 &mut self,
2086 modifiers: ast::TraitBoundModifiers,
2087 p: &TraitRef,
2088 itctx: ImplTraitContext,
2089 ) -> hir::TraitRef<'hir> {
2090 let path = match self.lower_qpath(
2091 p.ref_id,
2092 &None,
2093 &p.path,
2094 ParamMode::Explicit,
2095 AllowReturnTypeNotation::No,
2096 itctx,
2097 Some(modifiers),
2098 ) {
2099 hir::QPath::Resolved(None, path) => path,
2100 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2101 };
2102 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2103 }
2104
2105 #[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(2105u32),
::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))]
2106 fn lower_poly_trait_ref(
2107 &mut self,
2108 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2109 rbp: RelaxedBoundPolicy<'_>,
2110 itctx: ImplTraitContext,
2111 ) -> hir::PolyTraitRef<'hir> {
2112 let bound_generic_params =
2113 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2114 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2115 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2116
2117 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2118 self.validate_relaxed_bound(trait_ref, *span, rbp);
2119 }
2120
2121 hir::PolyTraitRef {
2122 bound_generic_params,
2123 modifiers,
2124 trait_ref,
2125 span: self.lower_span(*span),
2126 }
2127 }
2128
2129 fn validate_relaxed_bound(
2130 &self,
2131 trait_ref: hir::TraitRef<'_>,
2132 span: Span,
2133 rbp: RelaxedBoundPolicy<'_>,
2134 ) {
2135 match rbp {
2145 RelaxedBoundPolicy::Allowed => return,
2146 RelaxedBoundPolicy::AllowedIfOnTyParam(id, params) => {
2147 if let Some(res) = self.resolver.get_partial_res(id).and_then(|r| r.full_res())
2148 && let Res::Def(DefKind::TyParam, def_id) = res
2149 && params.iter().any(|p| def_id == self.local_def_id(p.id).to_def_id())
2150 {
2151 return;
2152 }
2153 }
2154 RelaxedBoundPolicy::Forbidden(reason) => {
2155 let gate = |context, subject| {
2156 let extended = self.tcx.features().more_maybe_bounds();
2157 let is_sized = trait_ref
2158 .trait_def_id()
2159 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, hir::LangItem::Sized));
2160
2161 if extended && !is_sized {
2162 return;
2163 }
2164
2165 let prefix = if extended { "`Sized` " } else { "" };
2166 let mut diag = self.dcx().struct_span_err(
2167 span,
2168 ::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}"),
2169 );
2170 if is_sized {
2171 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!(
2172 "{subject} are not implicitly bounded by `Sized`, \
2173 so there is nothing to relax"
2174 ));
2175 }
2176 diag.emit();
2177 };
2178
2179 match reason {
2180 RelaxedBoundForbiddenReason::TraitObjectTy => {
2181 gate("trait object types", "trait object types");
2182 return;
2183 }
2184 RelaxedBoundForbiddenReason::SuperTrait => {
2185 gate("supertrait bounds", "traits");
2186 return;
2187 }
2188 RelaxedBoundForbiddenReason::TraitAlias => {
2189 gate("trait alias bounds", "trait aliases");
2190 return;
2191 }
2192 RelaxedBoundForbiddenReason::AssocTyBounds
2193 | RelaxedBoundForbiddenReason::LateBoundVarsInScope => {}
2194 };
2195 }
2196 }
2197
2198 self.dcx()
2199 .struct_span_err(span, "this relaxed bound is not permitted here")
2200 .with_note(
2201 "in this context, relaxed bounds are only allowed on \
2202 type parameters defined on the closest item",
2203 )
2204 .emit();
2205 }
2206
2207 fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
2208 hir::MutTy { ty: self.lower_ty_alloc(&mt.ty, itctx), mutbl: mt.mutbl }
2209 }
2210
2211 x;#[instrument(level = "debug", skip(self), ret)]
2212 fn lower_param_bounds(
2213 &mut self,
2214 bounds: &[GenericBound],
2215 rbp: RelaxedBoundPolicy<'_>,
2216 itctx: ImplTraitContext,
2217 ) -> hir::GenericBounds<'hir> {
2218 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2219 }
2220
2221 fn lower_param_bounds_mut(
2222 &mut self,
2223 bounds: &[GenericBound],
2224 rbp: RelaxedBoundPolicy<'_>,
2225 itctx: ImplTraitContext,
2226 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2227 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp, itctx))
2228 }
2229
2230 x;#[instrument(level = "debug", skip(self), ret)]
2231 fn lower_universal_param_and_bounds(
2232 &mut self,
2233 node_id: NodeId,
2234 span: Span,
2235 ident: Ident,
2236 bounds: &[GenericBound],
2237 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2238 let def_id = self.local_def_id(node_id);
2240 let span = self.lower_span(span);
2241
2242 let param = hir::GenericParam {
2244 hir_id: self.lower_node_id(node_id),
2245 def_id,
2246 name: ParamName::Plain(self.lower_ident(ident)),
2247 pure_wrt_drop: false,
2248 span,
2249 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2250 colon_span: None,
2251 source: hir::GenericParamSource::Generics,
2252 };
2253
2254 let preds = self.lower_generic_bound_predicate(
2255 ident,
2256 node_id,
2257 &GenericParamKind::Type { default: None },
2258 bounds,
2259 None,
2260 span,
2261 RelaxedBoundPolicy::Allowed,
2262 ImplTraitContext::Universal,
2263 hir::PredicateOrigin::ImplTrait,
2264 );
2265
2266 let hir_id = self.next_id();
2267 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2268 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2269 None,
2270 self.arena.alloc(hir::Path {
2271 span,
2272 res,
2273 segments:
2274 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2275 }),
2276 ));
2277
2278 (param, preds, ty)
2279 }
2280
2281 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2284 let block = self.lower_block(b, false);
2285 self.expr_block(block)
2286 }
2287
2288 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2289 match c.value.peel_parens().kind {
2292 ExprKind::Underscore => {
2293 let ct_kind = hir::ConstArgKind::Infer(());
2294 self.arena.alloc(hir::ConstArg {
2295 hir_id: self.lower_node_id(c.id),
2296 kind: ct_kind,
2297 span: self.lower_span(c.value.span),
2298 })
2299 }
2300 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2301 }
2302 }
2303
2304 #[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(2307u32),
::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))]
2308 fn lower_const_path_to_const_arg(
2309 &mut self,
2310 path: &Path,
2311 res: Res<NodeId>,
2312 ty_id: NodeId,
2313 span: Span,
2314 ) -> &'hir hir::ConstArg<'hir> {
2315 let tcx = self.tcx;
2316
2317 let is_trivial_path = path.is_potential_trivial_const_arg()
2318 && matches!(res, Res::Def(DefKind::ConstParam, _));
2319 let ct_kind = if is_trivial_path || tcx.features().min_generic_const_args() {
2320 let qpath = self.lower_qpath(
2321 ty_id,
2322 &None,
2323 path,
2324 ParamMode::Explicit,
2325 AllowReturnTypeNotation::No,
2326 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2328 None,
2329 );
2330 hir::ConstArgKind::Path(qpath)
2331 } else {
2332 let node_id = self.next_node_id();
2334 let span = self.lower_span(span);
2335
2336 let def_id = self.create_def(
2341 node_id,
2342 None,
2343 DefKind::AnonConst,
2344 DefPathData::LateAnonConst,
2345 span,
2346 );
2347 let hir_id = self.lower_node_id(node_id);
2348
2349 let path_expr = Expr {
2350 id: ty_id,
2351 kind: ExprKind::Path(None, path.clone()),
2352 span,
2353 attrs: AttrVec::new(),
2354 tokens: None,
2355 };
2356
2357 let ct = self.with_new_scopes(span, |this| {
2358 self.arena.alloc(hir::AnonConst {
2359 def_id,
2360 hir_id,
2361 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2362 span,
2363 })
2364 });
2365 hir::ConstArgKind::Anon(ct)
2366 };
2367
2368 self.arena.alloc(hir::ConstArg {
2369 hir_id: self.next_id(),
2370 kind: ct_kind,
2371 span: self.lower_span(span),
2372 })
2373 }
2374
2375 fn lower_const_item_rhs(
2376 &mut self,
2377 attrs: &[hir::Attribute],
2378 rhs: Option<&ConstItemRhs>,
2379 span: Span,
2380 ) -> hir::ConstItemRhs<'hir> {
2381 match rhs {
2382 Some(ConstItemRhs::TypeConst(anon)) => {
2383 hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon))
2384 }
2385 None if {
{
'done:
{
for i in attrs {
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(AttributeKind::TypeConst(_)) =>
{
break 'done Some(());
}
_ => {}
}
}
None
}
}.is_some()
}find_attr!(attrs, AttributeKind::TypeConst(_)) => {
2386 let const_arg = ConstArg {
2387 hir_id: self.next_id(),
2388 kind: hir::ConstArgKind::Error(
2389 self.dcx().span_delayed_bug(DUMMY_SP, "no block"),
2390 ),
2391 span: DUMMY_SP,
2392 };
2393 hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg))
2394 }
2395 Some(ConstItemRhs::Body(body)) => {
2396 hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body)))
2397 }
2398 None => hir::ConstItemRhs::Body(self.lower_const_body(span, None)),
2399 }
2400 }
2401
2402 x;#[instrument(level = "debug", skip(self), ret)]
2403 fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir> {
2404 let span = self.lower_span(expr.span);
2405
2406 let overly_complex_const = |this: &mut Self| {
2407 let e = this.dcx().struct_span_err(
2408 expr.span,
2409 "complex const arguments must be placed inside of a `const` block",
2410 );
2411
2412 ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e.emit()), span }
2413 };
2414
2415 match &expr.kind {
2416 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2417 let qpath = self.lower_qpath(
2418 func.id,
2419 qself,
2420 path,
2421 ParamMode::Explicit,
2422 AllowReturnTypeNotation::No,
2423 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2424 None,
2425 );
2426
2427 let lowered_args = self.arena.alloc_from_iter(args.iter().map(|arg| {
2428 let const_arg = if let ExprKind::ConstBlock(anon_const) = &arg.kind {
2429 let def_id = self.local_def_id(anon_const.id);
2430 let def_kind = self.tcx.def_kind(def_id);
2431 assert_eq!(DefKind::AnonConst, def_kind);
2432 self.lower_anon_const_to_const_arg(anon_const)
2433 } else {
2434 self.lower_expr_to_const_arg_direct(arg)
2435 };
2436
2437 &*self.arena.alloc(const_arg)
2438 }));
2439
2440 ConstArg {
2441 hir_id: self.next_id(),
2442 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2443 span,
2444 }
2445 }
2446 ExprKind::Tup(exprs) => {
2447 let exprs = self.arena.alloc_from_iter(exprs.iter().map(|expr| {
2448 let expr = if let ExprKind::ConstBlock(anon_const) = &expr.kind {
2449 let def_id = self.local_def_id(anon_const.id);
2450 let def_kind = self.tcx.def_kind(def_id);
2451 assert_eq!(DefKind::AnonConst, def_kind);
2452
2453 self.lower_anon_const_to_const_arg(anon_const)
2454 } else {
2455 self.lower_expr_to_const_arg_direct(&expr)
2456 };
2457
2458 &*self.arena.alloc(expr)
2459 }));
2460
2461 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(exprs), span }
2462 }
2463 ExprKind::Path(qself, path) => {
2464 let qpath = self.lower_qpath(
2465 expr.id,
2466 qself,
2467 path,
2468 ParamMode::Explicit,
2469 AllowReturnTypeNotation::No,
2470 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2472 None,
2473 );
2474
2475 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath), span }
2476 }
2477 ExprKind::Struct(se) => {
2478 let path = self.lower_qpath(
2479 expr.id,
2480 &se.qself,
2481 &se.path,
2482 ParamMode::Explicit,
2486 AllowReturnTypeNotation::No,
2487 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2488 None,
2489 );
2490
2491 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2492 let hir_id = self.lower_node_id(f.id);
2493 self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField);
2497
2498 let expr = if let ExprKind::ConstBlock(anon_const) = &f.expr.kind {
2499 let def_id = self.local_def_id(anon_const.id);
2500 let def_kind = self.tcx.def_kind(def_id);
2501 assert_eq!(DefKind::AnonConst, def_kind);
2502
2503 self.lower_anon_const_to_const_arg(anon_const)
2504 } else {
2505 self.lower_expr_to_const_arg_direct(&f.expr)
2506 };
2507
2508 &*self.arena.alloc(hir::ConstArgExprField {
2509 hir_id,
2510 field: self.lower_ident(f.ident),
2511 expr: self.arena.alloc(expr),
2512 span: self.lower_span(f.span),
2513 })
2514 }));
2515
2516 ConstArg {
2517 hir_id: self.next_id(),
2518 kind: hir::ConstArgKind::Struct(path, fields),
2519 span,
2520 }
2521 }
2522 ExprKind::Array(elements) => {
2523 let lowered_elems = self.arena.alloc_from_iter(elements.iter().map(|element| {
2524 let const_arg = if let ExprKind::ConstBlock(anon_const) = &element.kind {
2525 let def_id = self.local_def_id(anon_const.id);
2526 assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
2527 self.lower_anon_const_to_const_arg(anon_const)
2528 } else {
2529 self.lower_expr_to_const_arg_direct(element)
2530 };
2531 &*self.arena.alloc(const_arg)
2532 }));
2533 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
2534 span: self.lower_span(expr.span),
2535 elems: lowered_elems,
2536 });
2537
2538 ConstArg {
2539 hir_id: self.next_id(),
2540 kind: hir::ConstArgKind::Array(array_expr),
2541 span,
2542 }
2543 }
2544 ExprKind::Underscore => ConstArg {
2545 hir_id: self.lower_node_id(expr.id),
2546 kind: hir::ConstArgKind::Infer(()),
2547 span,
2548 },
2549 ExprKind::Block(block, _) => {
2550 if let [stmt] = block.stmts.as_slice()
2551 && let StmtKind::Expr(expr) = &stmt.kind
2552 && matches!(
2553 expr.kind,
2554 ExprKind::Block(..)
2555 | ExprKind::Path(..)
2556 | ExprKind::Struct(..)
2557 | ExprKind::Call(..)
2558 | ExprKind::Tup(..)
2559 | ExprKind::Array(..)
2560 )
2561 {
2562 return self.lower_expr_to_const_arg_direct(expr);
2563 }
2564
2565 overly_complex_const(self)
2566 }
2567 ExprKind::Lit(literal) => {
2568 let span = expr.span;
2569 let literal = self.lower_lit(literal, span);
2570
2571 ConstArg {
2572 hir_id: self.lower_node_id(expr.id),
2573 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
2574 span,
2575 }
2576 }
2577 ExprKind::Unary(UnOp::Neg, inner_expr)
2578 if let ExprKind::Lit(literal) = &inner_expr.kind =>
2579 {
2580 let span = expr.span;
2581 let literal = self.lower_lit(literal, span);
2582
2583 ConstArg {
2584 hir_id: self.lower_node_id(expr.id),
2585 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: true },
2586 span,
2587 }
2588 }
2589 _ => overly_complex_const(self),
2590 }
2591 }
2592
2593 fn lower_anon_const_to_const_arg_and_alloc(
2596 &mut self,
2597 anon: &AnonConst,
2598 ) -> &'hir hir::ConstArg<'hir> {
2599 self.arena.alloc(self.lower_anon_const_to_const_arg(anon))
2600 }
2601
2602 #[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(2602u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["anon"],
::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))])
})
} 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);
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);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
span: self.lower_span(expr.span),
}
}
}
}#[instrument(level = "debug", skip(self))]
2603 fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
2604 let tcx = self.tcx;
2605
2606 if tcx.features().min_generic_const_args() {
2612 return match anon.mgca_disambiguation {
2613 MgcaDisambiguation::AnonConst => {
2614 let lowered_anon = self.lower_anon_const_to_anon_const(anon);
2615 ConstArg {
2616 hir_id: self.next_id(),
2617 kind: hir::ConstArgKind::Anon(lowered_anon),
2618 span: lowered_anon.span,
2619 }
2620 }
2621 MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
2622 };
2623 }
2624
2625 let expr = if let ExprKind::Block(block, _) = &anon.value.kind
2628 && let [stmt] = block.stmts.as_slice()
2629 && let StmtKind::Expr(expr) = &stmt.kind
2630 && let ExprKind::Path(..) = &expr.kind
2631 {
2632 expr
2633 } else {
2634 &anon.value
2635 };
2636
2637 let maybe_res =
2638 self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2639 if let ExprKind::Path(qself, path) = &expr.kind
2640 && path.is_potential_trivial_const_arg()
2641 && matches!(maybe_res, Some(Res::Def(DefKind::ConstParam, _)))
2642 {
2643 let qpath = self.lower_qpath(
2644 expr.id,
2645 qself,
2646 path,
2647 ParamMode::Explicit,
2648 AllowReturnTypeNotation::No,
2649 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2650 None,
2651 );
2652
2653 return ConstArg {
2654 hir_id: self.lower_node_id(anon.id),
2655 kind: hir::ConstArgKind::Path(qpath),
2656 span: self.lower_span(expr.span),
2657 };
2658 }
2659
2660 let lowered_anon = self.lower_anon_const_to_anon_const(anon);
2661 ConstArg {
2662 hir_id: self.next_id(),
2663 kind: hir::ConstArgKind::Anon(lowered_anon),
2664 span: self.lower_span(expr.span),
2665 }
2666 }
2667
2668 fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2671 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
2672 let def_id = this.local_def_id(c.id);
2673 let hir_id = this.lower_node_id(c.id);
2674 hir::AnonConst {
2675 def_id,
2676 hir_id,
2677 body: this.lower_const_body(c.value.span, Some(&c.value)),
2678 span: this.lower_span(c.value.span),
2679 }
2680 }))
2681 }
2682
2683 fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
2684 match u {
2685 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
2686 UserProvided => hir::UnsafeSource::UserProvided,
2687 }
2688 }
2689
2690 fn lower_trait_bound_modifiers(
2691 &mut self,
2692 modifiers: TraitBoundModifiers,
2693 ) -> hir::TraitBoundModifiers {
2694 let constness = match modifiers.constness {
2695 BoundConstness::Never => BoundConstness::Never,
2696 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
2697 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
2698 };
2699 let polarity = match modifiers.polarity {
2700 BoundPolarity::Positive => BoundPolarity::Positive,
2701 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
2702 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2703 };
2704 hir::TraitBoundModifiers { constness, polarity }
2705 }
2706
2707 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2710 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
2711 }
2712
2713 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
2714 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
2715 }
2716
2717 fn stmt_let_pat(
2718 &mut self,
2719 attrs: Option<&'hir [hir::Attribute]>,
2720 span: Span,
2721 init: Option<&'hir hir::Expr<'hir>>,
2722 pat: &'hir hir::Pat<'hir>,
2723 source: hir::LocalSource,
2724 ) -> hir::Stmt<'hir> {
2725 let hir_id = self.next_id();
2726 if let Some(a) = attrs {
2727 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
2728 self.attrs.insert(hir_id.local_id, a);
2729 }
2730 let local = hir::LetStmt {
2731 super_: None,
2732 hir_id,
2733 init,
2734 pat,
2735 els: None,
2736 source,
2737 span: self.lower_span(span),
2738 ty: None,
2739 };
2740 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2741 }
2742
2743 fn stmt_super_let_pat(
2744 &mut self,
2745 span: Span,
2746 pat: &'hir hir::Pat<'hir>,
2747 init: Option<&'hir hir::Expr<'hir>>,
2748 ) -> hir::Stmt<'hir> {
2749 let hir_id = self.next_id();
2750 let span = self.lower_span(span);
2751 let local = hir::LetStmt {
2752 super_: Some(span),
2753 hir_id,
2754 init,
2755 pat,
2756 els: None,
2757 source: hir::LocalSource::Normal,
2758 span,
2759 ty: None,
2760 };
2761 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2762 }
2763
2764 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
2765 self.block_all(expr.span, &[], Some(expr))
2766 }
2767
2768 fn block_all(
2769 &mut self,
2770 span: Span,
2771 stmts: &'hir [hir::Stmt<'hir>],
2772 expr: Option<&'hir hir::Expr<'hir>>,
2773 ) -> &'hir hir::Block<'hir> {
2774 let blk = hir::Block {
2775 stmts,
2776 expr,
2777 hir_id: self.next_id(),
2778 rules: hir::BlockCheckMode::DefaultBlock,
2779 span: self.lower_span(span),
2780 targeted_by_break: false,
2781 };
2782 self.arena.alloc(blk)
2783 }
2784
2785 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2786 let field = self.single_pat_field(span, pat);
2787 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field)
2788 }
2789
2790 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2791 let field = self.single_pat_field(span, pat);
2792 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowBreak, field)
2793 }
2794
2795 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2796 let field = self.single_pat_field(span, pat);
2797 self.pat_lang_item_variant(span, hir::LangItem::OptionSome, field)
2798 }
2799
2800 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
2801 self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[])
2802 }
2803
2804 fn single_pat_field(
2805 &mut self,
2806 span: Span,
2807 pat: &'hir hir::Pat<'hir>,
2808 ) -> &'hir [hir::PatField<'hir>] {
2809 let field = hir::PatField {
2810 hir_id: self.next_id(),
2811 ident: Ident::new(sym::integer(0), self.lower_span(span)),
2812 is_shorthand: false,
2813 pat,
2814 span: self.lower_span(span),
2815 };
2816 self.arena.alloc_from_iter([field])arena_vec![self; field]
2817 }
2818
2819 fn pat_lang_item_variant(
2820 &mut self,
2821 span: Span,
2822 lang_item: hir::LangItem,
2823 fields: &'hir [hir::PatField<'hir>],
2824 ) -> &'hir hir::Pat<'hir> {
2825 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2826 self.pat(span, hir::PatKind::Struct(path, fields, None))
2827 }
2828
2829 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
2830 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
2831 }
2832
2833 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
2834 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
2835 }
2836
2837 fn pat_ident_binding_mode(
2838 &mut self,
2839 span: Span,
2840 ident: Ident,
2841 bm: hir::BindingMode,
2842 ) -> (&'hir hir::Pat<'hir>, HirId) {
2843 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
2844 (self.arena.alloc(pat), hir_id)
2845 }
2846
2847 fn pat_ident_binding_mode_mut(
2848 &mut self,
2849 span: Span,
2850 ident: Ident,
2851 bm: hir::BindingMode,
2852 ) -> (hir::Pat<'hir>, HirId) {
2853 let hir_id = self.next_id();
2854
2855 (
2856 hir::Pat {
2857 hir_id,
2858 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
2859 span: self.lower_span(span),
2860 default_binding_modes: true,
2861 },
2862 hir_id,
2863 )
2864 }
2865
2866 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2867 self.arena.alloc(hir::Pat {
2868 hir_id: self.next_id(),
2869 kind,
2870 span: self.lower_span(span),
2871 default_binding_modes: true,
2872 })
2873 }
2874
2875 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
2876 hir::Pat {
2877 hir_id: self.next_id(),
2878 kind,
2879 span: self.lower_span(span),
2880 default_binding_modes: false,
2881 }
2882 }
2883
2884 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
2885 let kind = match qpath {
2886 hir::QPath::Resolved(None, path) => {
2887 match path.res {
2889 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
2890 let principal = hir::PolyTraitRef {
2891 bound_generic_params: &[],
2892 modifiers: hir::TraitBoundModifiers::NONE,
2893 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
2894 span: self.lower_span(span),
2895 };
2896
2897 hir_id = self.next_id();
2900 hir::TyKind::TraitObject(
2901 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
2902 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
2903 )
2904 }
2905 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
2906 }
2907 }
2908 _ => hir::TyKind::Path(qpath),
2909 };
2910
2911 hir::Ty { hir_id, kind, span: self.lower_span(span) }
2912 }
2913
2914 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
2919 let r = hir::Lifetime::new(
2920 self.next_id(),
2921 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
2922 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
2923 LifetimeSource::Other,
2924 LifetimeSyntax::Implicit,
2925 );
2926 {
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:2926",
"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(2926u32),
::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);
2927 self.arena.alloc(r)
2928 }
2929}
2930
2931struct GenericArgsCtor<'hir> {
2933 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
2934 constraints: &'hir [hir::AssocItemConstraint<'hir>],
2935 parenthesized: hir::GenericArgsParentheses,
2936 span: Span,
2937}
2938
2939impl<'hir> GenericArgsCtor<'hir> {
2940 fn is_empty(&self) -> bool {
2941 self.args.is_empty()
2942 && self.constraints.is_empty()
2943 && self.parenthesized == hir::GenericArgsParentheses::No
2944 }
2945
2946 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
2947 let ga = hir::GenericArgs {
2948 args: this.arena.alloc_from_iter(self.args),
2949 constraints: self.constraints,
2950 parenthesized: self.parenthesized,
2951 span_ext: this.lower_span(self.span),
2952 };
2953 this.arena.alloc(ga)
2954 }
2955}