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