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