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