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