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::errors::{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 errors;
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(_)) => {
errors::BadReturnTypeNotation::Inputs {
span: data.inputs_span,
}
}
([], FnRetTy::Default(_)) => {
errors::BadReturnTypeNotation::NeedsDots {
span: data.inputs_span,
}
}
(_, FnRetTy::Ty(ty)) => {
let span = data.inputs_span.shrink_to_hi().to(ty.span);
errors::BadReturnTypeNotation::Output {
span,
suggestion: errors::RTNSuggestion {
output: span,
input: data.inputs_span,
},
}
}
};
let mut err = self.dcx().create_err(err);
if !self.tcx.features().return_type_notation() &&
self.tcx.sess.is_nightly_build() {
add_feature_diagnostics(&mut err, &self.tcx.sess,
sym::return_type_notation);
}
err.emit();
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: data.span,
}
} else {
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
self.lower_angle_bracketed_parameter_data(&data.as_angle_bracketed_args(),
ParamMode::Explicit, itctx).0
}
}
GenericArgs::ParenthesizedElided(span) =>
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: *span,
},
};
gen_args_ctor.into_generic_args(self)
} else { hir::GenericArgs::NONE };
let kind =
match &constraint.kind {
AssocItemConstraintKind::Equality { term } => {
let term =
match term {
Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
Term::Const(c) =>
self.lower_anon_const_to_const_arg_and_alloc(c).into(),
};
hir::AssocItemConstraintKind::Equality { term }
}
AssocItemConstraintKind::Bound { bounds } => {
if self.is_in_dyn_type {
let suggestion =
match itctx {
ImplTraitContext::OpaqueTy { .. } |
ImplTraitContext::Universal => {
let bound_end_span =
constraint.gen_args.as_ref().map_or(constraint.ident.span,
|args| args.span());
if bound_end_span.eq_ctxt(constraint.span) {
Some(self.tcx.sess.source_map().next_point(bound_end_span))
} else { None }
}
_ => None,
};
let guar =
self.dcx().emit_err(errors::MisplacedAssocTyBinding {
span: constraint.span,
suggestion,
});
let err_ty =
&*self.arena.alloc(self.ty(constraint.span,
hir::TyKind::Err(guar)));
hir::AssocItemConstraintKind::Equality {
term: err_ty.into(),
}
} else {
let bounds =
self.lower_param_bounds(bounds,
RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
itctx);
hir::AssocItemConstraintKind::Bound { bounds }
}
}
};
hir::AssocItemConstraint {
hir_id: self.lower_node_id(constraint.id),
ident: self.lower_ident(constraint.ident),
gen_args,
kind,
span: self.lower_span(constraint.span),
}
}
}
}#[instrument(level = "debug", skip_all)]
1130 fn lower_assoc_item_constraint(
1131 &mut self,
1132 constraint: &AssocItemConstraint,
1133 itctx: ImplTraitContext,
1134 ) -> hir::AssocItemConstraint<'hir> {
1135 debug!(?constraint, ?itctx);
1136 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1138 let gen_args_ctor = match gen_args {
1139 GenericArgs::AngleBracketed(data) => {
1140 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1141 }
1142 GenericArgs::Parenthesized(data) => {
1143 if let Some(first_char) = constraint.ident.as_str().chars().next()
1144 && first_char.is_ascii_lowercase()
1145 {
1146 let err = match (&data.inputs[..], &data.output) {
1147 ([_, ..], FnRetTy::Default(_)) => {
1148 errors::BadReturnTypeNotation::Inputs { span: data.inputs_span }
1149 }
1150 ([], FnRetTy::Default(_)) => {
1151 errors::BadReturnTypeNotation::NeedsDots { span: data.inputs_span }
1152 }
1153 (_, FnRetTy::Ty(ty)) => {
1155 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1156 errors::BadReturnTypeNotation::Output {
1157 span,
1158 suggestion: errors::RTNSuggestion {
1159 output: span,
1160 input: data.inputs_span,
1161 },
1162 }
1163 }
1164 };
1165 let mut err = self.dcx().create_err(err);
1166 if !self.tcx.features().return_type_notation()
1167 && self.tcx.sess.is_nightly_build()
1168 {
1169 add_feature_diagnostics(
1170 &mut err,
1171 &self.tcx.sess,
1172 sym::return_type_notation,
1173 );
1174 }
1175 err.emit();
1176 GenericArgsCtor {
1177 args: Default::default(),
1178 constraints: &[],
1179 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1180 span: data.span,
1181 }
1182 } else {
1183 self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1184 self.lower_angle_bracketed_parameter_data(
1185 &data.as_angle_bracketed_args(),
1186 ParamMode::Explicit,
1187 itctx,
1188 )
1189 .0
1190 }
1191 }
1192 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1193 args: Default::default(),
1194 constraints: &[],
1195 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1196 span: *span,
1197 },
1198 };
1199 gen_args_ctor.into_generic_args(self)
1200 } else {
1201 hir::GenericArgs::NONE
1202 };
1203 let kind = match &constraint.kind {
1204 AssocItemConstraintKind::Equality { term } => {
1205 let term = match term {
1206 Term::Ty(ty) => self.lower_ty_alloc(ty, itctx).into(),
1207 Term::Const(c) => self.lower_anon_const_to_const_arg_and_alloc(c).into(),
1208 };
1209 hir::AssocItemConstraintKind::Equality { term }
1210 }
1211 AssocItemConstraintKind::Bound { bounds } => {
1212 if self.is_in_dyn_type {
1214 let suggestion = match itctx {
1215 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1216 let bound_end_span = constraint
1217 .gen_args
1218 .as_ref()
1219 .map_or(constraint.ident.span, |args| args.span());
1220 if bound_end_span.eq_ctxt(constraint.span) {
1221 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1222 } else {
1223 None
1224 }
1225 }
1226 _ => None,
1227 };
1228
1229 let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1230 span: constraint.span,
1231 suggestion,
1232 });
1233 let err_ty =
1234 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1235 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1236 } else {
1237 let bounds = self.lower_param_bounds(
1238 bounds,
1239 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1240 itctx,
1241 );
1242 hir::AssocItemConstraintKind::Bound { bounds }
1243 }
1244 }
1245 };
1246
1247 hir::AssocItemConstraint {
1248 hir_id: self.lower_node_id(constraint.id),
1249 ident: self.lower_ident(constraint.ident),
1250 gen_args,
1251 kind,
1252 span: self.lower_span(constraint.span),
1253 }
1254 }
1255
1256 fn emit_bad_parenthesized_trait_in_assoc_ty(&self, data: &ParenthesizedArgs) {
1257 let sub = if data.inputs.is_empty() {
1259 let parentheses_span =
1260 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1261 AssocTyParenthesesSub::Empty { parentheses_span }
1262 }
1263 else {
1265 let open_param = data.inputs_span.shrink_to_lo().to(data
1267 .inputs
1268 .first()
1269 .unwrap()
1270 .span
1271 .shrink_to_lo());
1272 let close_param =
1274 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1275 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1276 };
1277 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub });
1278 }
1279
1280 #[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(1280u32),
::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:1317",
"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(1317u32),
::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))]
1281 fn lower_generic_arg(
1282 &mut self,
1283 arg: &ast::GenericArg,
1284 itctx: ImplTraitContext,
1285 ) -> hir::GenericArg<'hir> {
1286 match arg {
1287 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1288 lt,
1289 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1290 lt.ident.into(),
1291 )),
1292 ast::GenericArg::Type(ty) => {
1293 if ty.is_maybe_parenthesised_infer() {
1296 return GenericArg::Infer(hir::InferArg {
1297 hir_id: self.lower_node_id(ty.id),
1298 span: self.lower_span(ty.span),
1299 });
1300 }
1301
1302 match &ty.kind {
1303 TyKind::Path(None, path) => {
1310 if let Some(res) = self
1311 .get_partial_res(ty.id)
1312 .and_then(|partial_res| partial_res.full_res())
1313 {
1314 if !res.matches_ns(Namespace::TypeNS)
1315 && path.is_potential_trivial_const_arg()
1316 {
1317 debug!(
1318 "lower_generic_arg: Lowering type argument as const argument: {:?}",
1319 ty,
1320 );
1321
1322 let ct =
1323 self.lower_const_path_to_const_arg(path, res, ty.id, ty.span);
1324 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1325 }
1326 }
1327 }
1328 _ => {}
1329 }
1330 GenericArg::Type(self.lower_ty_alloc(ty, itctx).try_as_ambig_ty().unwrap())
1331 }
1332 ast::GenericArg::Const(ct) => {
1333 let ct = self.lower_anon_const_to_const_arg_and_alloc(ct);
1334 match ct.try_as_ambig_ct() {
1335 Some(ct) => GenericArg::Const(ct),
1336 None => GenericArg::Infer(hir::InferArg { hir_id: ct.hir_id, span: ct.span }),
1337 }
1338 }
1339 }
1340 }
1341
1342 #[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(1342u32),
::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))]
1343 fn lower_ty_alloc(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1344 self.arena.alloc(self.lower_ty(t, itctx))
1345 }
1346
1347 fn lower_path_ty(
1348 &mut self,
1349 t: &Ty,
1350 qself: &Option<Box<QSelf>>,
1351 path: &Path,
1352 param_mode: ParamMode,
1353 itctx: ImplTraitContext,
1354 ) -> hir::Ty<'hir> {
1355 if qself.is_none()
1361 && let Some(partial_res) = self.get_partial_res(t.id)
1362 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1363 {
1364 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1365 let bound = this.lower_poly_trait_ref(
1366 &PolyTraitRef {
1367 bound_generic_params: ThinVec::new(),
1368 modifiers: TraitBoundModifiers::NONE,
1369 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1370 span: t.span,
1371 parens: ast::Parens::No,
1372 },
1373 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1374 itctx,
1375 );
1376 let bounds = this.arena.alloc_from_iter([bound]);
1377 let lifetime_bound = this.elided_dyn_bound(t.span);
1378 (bounds, lifetime_bound)
1379 });
1380 let kind = hir::TyKind::TraitObject(
1381 bounds,
1382 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1383 );
1384 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1385 }
1386
1387 let id = self.lower_node_id(t.id);
1388 let qpath = self.lower_qpath(
1389 t.id,
1390 qself,
1391 path,
1392 param_mode,
1393 AllowReturnTypeNotation::Yes,
1394 itctx,
1395 None,
1396 );
1397 self.ty_path(id, t.span, qpath)
1398 }
1399
1400 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1401 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1402 }
1403
1404 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1405 self.ty(span, hir::TyKind::Tup(tys))
1406 }
1407
1408 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1409 let kind = match &t.kind {
1410 TyKind::Infer => hir::TyKind::Infer(()),
1411 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1412 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty_alloc(ty, itctx)),
1413 TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
1414 TyKind::Ref(region, mt) => {
1415 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1416 hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
1417 }
1418 TyKind::PinnedRef(region, mt) => {
1419 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1420 let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1421 let span = self.lower_span(t.span);
1422 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1423 let args = self.arena.alloc(hir::GenericArgs {
1424 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1425 constraints: &[],
1426 parenthesized: hir::GenericArgsParentheses::No,
1427 span_ext: span,
1428 });
1429 let path = self.make_lang_item_qpath(hir::LangItem::Pin, span, Some(args));
1430 hir::TyKind::Path(path)
1431 }
1432 TyKind::FnPtr(f) => {
1433 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1434 hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1435 generic_params,
1436 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1437 abi: self.lower_extern(f.ext),
1438 decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
1439 param_idents: self.lower_fn_params_to_idents(&f.decl),
1440 }))
1441 }
1442 TyKind::UnsafeBinder(f) => {
1443 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1444 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1445 generic_params,
1446 inner_ty: self.lower_ty_alloc(&f.inner_ty, itctx),
1447 }))
1448 }
1449 TyKind::Never => hir::TyKind::Never,
1450 TyKind::Tup(tys) => hir::TyKind::Tup(
1451 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty(ty, itctx))),
1452 ),
1453 TyKind::Paren(ty) => {
1454 return self.lower_ty(ty, itctx);
1455 }
1456 TyKind::Path(qself, path) => {
1457 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1458 }
1459 TyKind::ImplicitSelf => {
1460 let hir_id = self.next_id();
1461 let res = self.expect_full_res(t.id);
1462 let res = self.lower_res(res);
1463 hir::TyKind::Path(hir::QPath::Resolved(
1464 None,
1465 self.arena.alloc(hir::Path {
1466 res,
1467 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1468 Ident::with_dummy_span(kw::SelfUpper),
1469 hir_id,
1470 res
1471 )],
1472 span: self.lower_span(t.span),
1473 }),
1474 ))
1475 }
1476 TyKind::Array(ty, length) => hir::TyKind::Array(
1477 self.lower_ty_alloc(ty, itctx),
1478 self.lower_array_length_to_const_arg(length),
1479 ),
1480 TyKind::TraitObject(bounds, kind) => {
1481 let mut lifetime_bound = None;
1482 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1483 let bounds =
1484 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1485 GenericBound::Trait(ty) => {
1489 let trait_ref = this.lower_poly_trait_ref(
1490 ty,
1491 RelaxedBoundPolicy::Forbidden(
1492 RelaxedBoundForbiddenReason::TraitObjectTy,
1493 ),
1494 itctx,
1495 );
1496 Some(trait_ref)
1497 }
1498 GenericBound::Outlives(lifetime) => {
1499 if lifetime_bound.is_none() {
1500 lifetime_bound = Some(this.lower_lifetime(
1501 lifetime,
1502 LifetimeSource::Other,
1503 lifetime.ident.into(),
1504 ));
1505 }
1506 None
1507 }
1508 GenericBound::Use(_, span) => {
1510 this.dcx()
1511 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1512 None
1513 }
1514 }));
1515 let lifetime_bound =
1516 lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
1517 (bounds, lifetime_bound)
1518 });
1519 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1520 }
1521 TyKind::ImplTrait(def_node_id, bounds) => {
1522 let span = t.span;
1523 match itctx {
1524 ImplTraitContext::OpaqueTy { origin } => {
1525 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1526 }
1527 ImplTraitContext::Universal => {
1528 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1529 ast::GenericBound::Use(_, span) => Some(span),
1530 _ => None,
1531 }) {
1532 self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnApit { span });
1533 }
1534
1535 let def_id = self.local_def_id(*def_node_id);
1536 let name = self.tcx.item_name(def_id.to_def_id());
1537 let ident = Ident::new(name, span);
1538 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1539 *def_node_id,
1540 span,
1541 ident,
1542 bounds,
1543 );
1544 self.impl_trait_defs.push(param);
1545 if let Some(bounds) = bounds {
1546 self.impl_trait_bounds.push(bounds);
1547 }
1548 path
1549 }
1550 ImplTraitContext::InBinding => hir::TyKind::TraitAscription(
1551 self.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx),
1552 ),
1553 ImplTraitContext::FeatureGated(position, feature) => {
1554 let guar = self
1555 .tcx
1556 .sess
1557 .create_feature_err(
1558 MisplacedImplTrait {
1559 span: t.span,
1560 position: DiagArgFromDisplay(&position),
1561 },
1562 feature,
1563 )
1564 .emit();
1565 hir::TyKind::Err(guar)
1566 }
1567 ImplTraitContext::Disallowed(position) => {
1568 let guar = self.dcx().emit_err(MisplacedImplTrait {
1569 span: t.span,
1570 position: DiagArgFromDisplay(&position),
1571 });
1572 hir::TyKind::Err(guar)
1573 }
1574 }
1575 }
1576 TyKind::Pat(ty, pat) => {
1577 hir::TyKind::Pat(self.lower_ty_alloc(ty, itctx), self.lower_ty_pat(pat, ty.span))
1578 }
1579 TyKind::FieldOf(ty, variant, field) => hir::TyKind::FieldOf(
1580 self.lower_ty_alloc(ty, itctx),
1581 self.arena.alloc(hir::TyFieldPath {
1582 variant: variant.map(|variant| self.lower_ident(variant)),
1583 field: self.lower_ident(*field),
1584 }),
1585 ),
1586 TyKind::MacCall(_) => {
1587 ::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")
1588 }
1589 TyKind::CVarArgs => {
1590 let guar = self.dcx().span_delayed_bug(
1591 t.span,
1592 "`TyKind::CVarArgs` should have been handled elsewhere",
1593 );
1594 hir::TyKind::Err(guar)
1595 }
1596 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1597 };
1598
1599 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1600 }
1601
1602 fn lower_ty_direct_lifetime(
1603 &mut self,
1604 t: &Ty,
1605 region: Option<Lifetime>,
1606 ) -> &'hir hir::Lifetime {
1607 let (region, syntax) = match region {
1608 Some(region) => (region, region.ident.into()),
1609
1610 None => {
1611 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1612 self.owner.get_lifetime_res(t.id)
1613 {
1614 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);
1615 start
1616 } else {
1617 self.next_node_id()
1618 };
1619 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1620 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1621 (region, LifetimeSyntax::Implicit)
1622 }
1623 };
1624 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1625 }
1626
1627 x;#[instrument(level = "debug", skip(self), ret)]
1659 fn lower_opaque_impl_trait(
1660 &mut self,
1661 span: Span,
1662 origin: hir::OpaqueTyOrigin<LocalDefId>,
1663 opaque_ty_node_id: NodeId,
1664 bounds: &GenericBounds,
1665 itctx: ImplTraitContext,
1666 ) -> hir::TyKind<'hir> {
1667 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1673
1674 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1675 this.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx)
1676 })
1677 }
1678
1679 fn lower_opaque_inner(
1680 &mut self,
1681 opaque_ty_node_id: NodeId,
1682 origin: hir::OpaqueTyOrigin<LocalDefId>,
1683 opaque_ty_span: Span,
1684 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1685 ) -> hir::TyKind<'hir> {
1686 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1687 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1688 {
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:1688",
"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(1688u32),
::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);
1689
1690 let bounds = lower_item_bounds(self);
1691 let opaque_ty_def = hir::OpaqueTy {
1692 hir_id: opaque_ty_hir_id,
1693 def_id: opaque_ty_def_id,
1694 bounds,
1695 origin,
1696 span: self.lower_span(opaque_ty_span),
1697 };
1698 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1699
1700 hir::TyKind::OpaqueDef(opaque_ty_def)
1701 }
1702
1703 fn lower_precise_capturing_args(
1704 &mut self,
1705 precise_capturing_args: &[PreciseCapturingArg],
1706 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1707 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1708 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1709 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1710 ),
1711 PreciseCapturingArg::Arg(path, id) => {
1712 let [segment] = path.segments.as_slice() else {
1713 ::core::panicking::panic("explicit panic");panic!();
1714 };
1715 let res = self.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1716 partial_res.full_res().expect("no partial res expected for precise capture arg")
1717 });
1718 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1719 hir_id: self.lower_node_id(*id),
1720 ident: self.lower_ident(segment.ident),
1721 res: self.lower_res(res),
1722 })
1723 }
1724 }))
1725 }
1726
1727 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1728 self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1729 PatKind::Missing => None,
1730 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1731 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1732 _ => {
1733 self.dcx().span_delayed_bug(
1734 param.pat.span,
1735 "non-missing/ident/wild param pat must trigger an error",
1736 );
1737 None
1738 }
1739 }))
1740 }
1741
1742 #[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(1751u32),
::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))]
1752 fn lower_fn_decl(
1753 &mut self,
1754 decl: &FnDecl,
1755 fn_node_id: NodeId,
1756 fn_span: Span,
1757 kind: FnDeclKind,
1758 coro: Option<CoroutineKind>,
1759 ) -> &'hir hir::FnDecl<'hir> {
1760 let c_variadic = decl.c_variadic();
1761
1762 let mut inputs = &decl.inputs[..];
1766 if decl.c_variadic() {
1767 inputs = &inputs[..inputs.len() - 1];
1768 }
1769 let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
1770 let itctx = match kind {
1771 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
1772 ImplTraitContext::Universal
1773 }
1774 FnDeclKind::ExternFn => {
1775 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
1776 }
1777 FnDeclKind::Closure => {
1778 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
1779 }
1780 FnDeclKind::Pointer => {
1781 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
1782 }
1783 };
1784 self.lower_ty(¶m.ty, itctx)
1785 }));
1786
1787 let output = match coro {
1788 Some(coro) => {
1789 let fn_def_id = self.owner.def_id;
1790 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
1791 }
1792 None => match &decl.output {
1793 FnRetTy::Ty(ty) => {
1794 let itctx = match kind {
1795 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
1796 origin: hir::OpaqueTyOrigin::FnReturn {
1797 parent: self.owner.def_id,
1798 in_trait_or_impl: None,
1799 },
1800 },
1801 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
1802 origin: hir::OpaqueTyOrigin::FnReturn {
1803 parent: self.owner.def_id,
1804 in_trait_or_impl: Some(hir::RpitContext::Trait),
1805 },
1806 },
1807 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1808 origin: hir::OpaqueTyOrigin::FnReturn {
1809 parent: self.owner.def_id,
1810 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
1811 },
1812 },
1813 FnDeclKind::ExternFn => {
1814 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
1815 }
1816 FnDeclKind::Closure => {
1817 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
1818 }
1819 FnDeclKind::Pointer => {
1820 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
1821 }
1822 };
1823 hir::FnRetTy::Return(self.lower_ty_alloc(ty, itctx))
1824 }
1825 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
1826 },
1827 };
1828
1829 let fn_decl_kind = hir::FnDeclFlags::default()
1830 .set_implicit_self(decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
1831 let is_mutable_pat = matches!(
1832 arg.pat.kind,
1833 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
1834 );
1835
1836 match &arg.ty.kind {
1837 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
1838 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
1839 TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
1843 if mt.ty.kind.is_implicit_self() =>
1844 {
1845 match mt.mutbl {
1846 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1847 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
1848 }
1849 }
1850 _ => hir::ImplicitSelfKind::None,
1851 }
1852 }))
1853 .set_lifetime_elision_allowed(
1854 self.owner.id == fn_node_id && self.owner.lifetime_elision_allowed,
1855 )
1856 .set_c_variadic(c_variadic);
1857
1858 self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
1859 }
1860
1861 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_coroutine_fn_ret_ty",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1869u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["output",
"fn_def_id", "coro", "fn_kind"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_kind)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::FnRetTy<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let span = self.lower_span(output.span());
let (opaque_ty_node_id, allowed_features) =
match coro {
CoroutineKind::Async { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::Gen { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
(return_impl_trait_id,
Some(Arc::clone(&self.allow_async_iterator)))
}
};
let opaque_ty_span =
self.mark_span_with_reason(DesugaringKind::Async, span,
allowed_features);
let in_trait_or_impl =
match fn_kind {
FnDeclKind::Trait => Some(hir::RpitContext::Trait),
FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
FnDeclKind::Fn | FnDeclKind::Inherent => None,
FnDeclKind::ExternFn | FnDeclKind::Closure |
FnDeclKind::Pointer =>
::core::panicking::panic("internal error: entered unreachable code"),
};
let opaque_ty_ref =
self.lower_opaque_inner(opaque_ty_node_id,
hir::OpaqueTyOrigin::AsyncFn {
parent: fn_def_id,
in_trait_or_impl,
}, opaque_ty_span,
|this|
{
let bound =
this.lower_coroutine_fn_output_type_to_bound(output, coro,
opaque_ty_span,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: fn_def_id,
in_trait_or_impl,
},
});
this.arena.alloc_from_iter([bound])
});
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}
}
}#[instrument(level = "debug", skip(self))]
1870 fn lower_coroutine_fn_ret_ty(
1871 &mut self,
1872 output: &FnRetTy,
1873 fn_def_id: LocalDefId,
1874 coro: CoroutineKind,
1875 fn_kind: FnDeclKind,
1876 ) -> hir::FnRetTy<'hir> {
1877 let span = self.lower_span(output.span());
1878
1879 let (opaque_ty_node_id, allowed_features) = match coro {
1880 CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
1881 CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
1882 CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
1883 (return_impl_trait_id, Some(Arc::clone(&self.allow_async_iterator)))
1884 }
1885 };
1886
1887 let opaque_ty_span =
1888 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
1889
1890 let in_trait_or_impl = match fn_kind {
1891 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
1892 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
1893 FnDeclKind::Fn | FnDeclKind::Inherent => None,
1894 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
1895 };
1896
1897 let opaque_ty_ref = self.lower_opaque_inner(
1898 opaque_ty_node_id,
1899 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
1900 opaque_ty_span,
1901 |this| {
1902 let bound = this.lower_coroutine_fn_output_type_to_bound(
1903 output,
1904 coro,
1905 opaque_ty_span,
1906 ImplTraitContext::OpaqueTy {
1907 origin: hir::OpaqueTyOrigin::FnReturn {
1908 parent: fn_def_id,
1909 in_trait_or_impl,
1910 },
1911 },
1912 );
1913 arena_vec![this; bound]
1914 },
1915 );
1916
1917 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
1918 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
1919 }
1920
1921 fn lower_coroutine_fn_output_type_to_bound(
1923 &mut self,
1924 output: &FnRetTy,
1925 coro: CoroutineKind,
1926 opaque_ty_span: Span,
1927 itctx: ImplTraitContext,
1928 ) -> hir::GenericBound<'hir> {
1929 let output_ty = match output {
1931 FnRetTy::Ty(ty) => {
1932 self.lower_ty_alloc(ty, itctx)
1936 }
1937 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
1938 };
1939
1940 let (assoc_ty_name, trait_lang_item) = match coro {
1942 CoroutineKind::Async { .. } => (sym::Output, hir::LangItem::Future),
1943 CoroutineKind::Gen { .. } => (sym::Item, hir::LangItem::Iterator),
1944 CoroutineKind::AsyncGen { .. } => (sym::Item, hir::LangItem::AsyncIterator),
1945 };
1946
1947 let bound_args = self.arena.alloc(hir::GenericArgs {
1948 args: &[],
1949 constraints: self.arena.alloc_from_iter([self.assoc_ty_binding(assoc_ty_name,
opaque_ty_span, output_ty)])arena_vec![self; self.assoc_ty_binding(assoc_ty_name, opaque_ty_span, output_ty)],
1950 parenthesized: hir::GenericArgsParentheses::No,
1951 span_ext: DUMMY_SP,
1952 });
1953
1954 hir::GenericBound::Trait(hir::PolyTraitRef {
1955 bound_generic_params: &[],
1956 modifiers: hir::TraitBoundModifiers::NONE,
1957 trait_ref: hir::TraitRef {
1958 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
1959 hir_ref_id: self.next_id(),
1960 },
1961 span: opaque_ty_span,
1962 })
1963 }
1964
1965 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_param_bound",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1965u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["tpb", "rbp",
"itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&tpb)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::GenericBound<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
match tpb {
GenericBound::Trait(p) => {
hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp,
itctx))
}
GenericBound::Outlives(lifetime) =>
hir::GenericBound::Outlives(self.lower_lifetime(lifetime,
LifetimeSource::OutlivesBound, lifetime.ident.into())),
GenericBound::Use(args, span) =>
hir::GenericBound::Use(self.lower_precise_capturing_args(args),
self.lower_span(*span)),
}
}
}
}#[instrument(level = "trace", skip(self))]
1966 fn lower_param_bound(
1967 &mut self,
1968 tpb: &GenericBound,
1969 rbp: RelaxedBoundPolicy,
1970 itctx: ImplTraitContext,
1971 ) -> hir::GenericBound<'hir> {
1972 match tpb {
1973 GenericBound::Trait(p) => {
1974 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
1975 }
1976 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
1977 lifetime,
1978 LifetimeSource::OutlivesBound,
1979 lifetime.ident.into(),
1980 )),
1981 GenericBound::Use(args, span) => hir::GenericBound::Use(
1982 self.lower_precise_capturing_args(args),
1983 self.lower_span(*span),
1984 ),
1985 }
1986 }
1987
1988 fn lower_lifetime(
1989 &mut self,
1990 l: &Lifetime,
1991 source: LifetimeSource,
1992 syntax: LifetimeSyntax,
1993 ) -> &'hir hir::Lifetime {
1994 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
1995 }
1996
1997 fn lower_lifetime_hidden_in_path(
1998 &mut self,
1999 id: NodeId,
2000 span: Span,
2001 angle_brackets: AngleBrackets,
2002 ) -> &'hir hir::Lifetime {
2003 self.new_named_lifetime(
2004 id,
2005 id,
2006 Ident::new(kw::UnderscoreLifetime, span),
2007 LifetimeSource::Path { angle_brackets },
2008 LifetimeSyntax::Implicit,
2009 )
2010 }
2011
2012 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("new_named_lifetime",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2012u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["id", "new_id",
"ident", "source", "syntax"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&new_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&syntax)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::Lifetime = loop {};
return __tracing_attr_fake_return;
}
{
let res =
if let Some(res) = self.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:2046",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2046u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&res) as
&dyn Value))])
});
} else { ; }
};
self.arena.alloc(hir::Lifetime::new(self.lower_node_id(new_id),
self.lower_ident(ident), res, source, syntax))
}
}
}#[instrument(level = "debug", skip(self))]
2013 fn new_named_lifetime(
2014 &mut self,
2015 id: NodeId,
2016 new_id: NodeId,
2017 ident: Ident,
2018 source: LifetimeSource,
2019 syntax: LifetimeSyntax,
2020 ) -> &'hir hir::Lifetime {
2021 let res = if let Some(res) = self.owner.get_lifetime_res(id) {
2022 match res {
2023 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
2024 LifetimeRes::Fresh { param, .. } => {
2025 assert_eq!(ident.name, kw::UnderscoreLifetime);
2026 let param = self.local_def_id(param);
2027 hir::LifetimeKind::Param(param)
2028 }
2029 LifetimeRes::Infer => {
2030 assert_eq!(ident.name, kw::UnderscoreLifetime);
2031 hir::LifetimeKind::Infer
2032 }
2033 LifetimeRes::Static { .. } => {
2034 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
2035 hir::LifetimeKind::Static
2036 }
2037 LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
2038 LifetimeRes::ElidedAnchor { .. } => {
2039 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
2040 }
2041 }
2042 } else {
2043 hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
2044 };
2045
2046 debug!(?res);
2047 self.arena.alloc(hir::Lifetime::new(
2048 self.lower_node_id(new_id),
2049 self.lower_ident(ident),
2050 res,
2051 source,
2052 syntax,
2053 ))
2054 }
2055
2056 fn lower_generic_params_mut(
2057 &mut self,
2058 params: &[GenericParam],
2059 source: hir::GenericParamSource,
2060 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
2061 params.iter().map(move |param| self.lower_generic_param(param, source))
2062 }
2063
2064 fn lower_generic_params(
2065 &mut self,
2066 params: &[GenericParam],
2067 source: hir::GenericParamSource,
2068 ) -> &'hir [hir::GenericParam<'hir>] {
2069 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
2070 }
2071
2072 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_generic_param",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2072u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["param", "source"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::GenericParam<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let (name, kind) = self.lower_generic_param_kind(param, source);
let hir_id = self.lower_node_id(param.id);
let param_attrs = ¶m.attrs;
let param_span = param.span();
let param =
hir::GenericParam {
hir_id,
def_id: self.local_def_id(param.id),
name,
span: self.lower_span(param.span()),
pure_wrt_drop: attr::contains_name(¶m.attrs,
sym::may_dangle),
kind,
colon_span: param.colon_span.map(|s| self.lower_span(s)),
source,
};
self.lower_attrs(hir_id, param_attrs, param_span,
Target::from_generic_param(¶m));
param
}
}
}#[instrument(level = "trace", skip(self))]
2073 fn lower_generic_param(
2074 &mut self,
2075 param: &GenericParam,
2076 source: hir::GenericParamSource,
2077 ) -> hir::GenericParam<'hir> {
2078 let (name, kind) = self.lower_generic_param_kind(param, source);
2079
2080 let hir_id = self.lower_node_id(param.id);
2081 let param_attrs = ¶m.attrs;
2082 let param_span = param.span();
2083 let param = hir::GenericParam {
2084 hir_id,
2085 def_id: self.local_def_id(param.id),
2086 name,
2087 span: self.lower_span(param.span()),
2088 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
2089 kind,
2090 colon_span: param.colon_span.map(|s| self.lower_span(s)),
2091 source,
2092 };
2093 self.lower_attrs(hir_id, param_attrs, param_span, Target::from_generic_param(¶m));
2094 param
2095 }
2096
2097 fn lower_generic_param_kind(
2098 &mut self,
2099 param: &GenericParam,
2100 source: hir::GenericParamSource,
2101 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2102 match ¶m.kind {
2103 GenericParamKind::Lifetime => {
2104 let ident = self.lower_ident(param.ident);
2107 let param_name =
2108 if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) {
2109 ParamName::Error(ident)
2110 } else {
2111 ParamName::Plain(ident)
2112 };
2113 let kind =
2114 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2115
2116 (param_name, kind)
2117 }
2118 GenericParamKind::Type { default, .. } => {
2119 let default = default
2122 .as_ref()
2123 .filter(|_| match source {
2124 hir::GenericParamSource::Generics => true,
2125 hir::GenericParamSource::Binder => {
2126 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2127 span: param.span(),
2128 });
2129
2130 false
2131 }
2132 })
2133 .map(|def| {
2134 self.lower_ty_alloc(
2135 def,
2136 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2137 )
2138 });
2139
2140 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2141
2142 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2143 }
2144 GenericParamKind::Const { ty, span: _, default } => {
2145 let ty = self.lower_ty_alloc(
2146 ty,
2147 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2148 );
2149
2150 let default = default
2153 .as_ref()
2154 .filter(|anon_const| match source {
2155 hir::GenericParamSource::Generics => true,
2156 hir::GenericParamSource::Binder => {
2157 let err = errors::GenericParamDefaultInBinder { span: param.span() };
2158 if expr::WillCreateDefIdsVisitor
2159 .visit_expr(&anon_const.value)
2160 .is_break()
2161 {
2162 self.dcx().emit_fatal(err)
2166 } else {
2167 self.dcx().emit_err(err);
2168 false
2169 }
2170 }
2171 })
2172 .map(|def| self.lower_anon_const_to_const_arg_and_alloc(def));
2173
2174 (
2175 hir::ParamName::Plain(self.lower_ident(param.ident)),
2176 hir::GenericParamKind::Const { ty, default },
2177 )
2178 }
2179 }
2180 }
2181
2182 fn lower_trait_ref(
2183 &mut self,
2184 modifiers: ast::TraitBoundModifiers,
2185 p: &TraitRef,
2186 itctx: ImplTraitContext,
2187 ) -> hir::TraitRef<'hir> {
2188 let path = match self.lower_qpath(
2189 p.ref_id,
2190 &None,
2191 &p.path,
2192 ParamMode::Explicit,
2193 AllowReturnTypeNotation::No,
2194 itctx,
2195 Some(modifiers),
2196 ) {
2197 hir::QPath::Resolved(None, path) => path,
2198 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2199 };
2200 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2201 }
2202
2203 #[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(2203u32),
::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))]
2204 fn lower_poly_trait_ref(
2205 &mut self,
2206 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2207 rbp: RelaxedBoundPolicy,
2208 itctx: ImplTraitContext,
2209 ) -> hir::PolyTraitRef<'hir> {
2210 let bound_generic_params =
2211 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2212 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2213 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2214
2215 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2216 self.validate_relaxed_bound(trait_ref, *span, rbp);
2217 }
2218
2219 hir::PolyTraitRef {
2220 bound_generic_params,
2221 modifiers,
2222 trait_ref,
2223 span: self.lower_span(*span),
2224 }
2225 }
2226
2227 fn validate_relaxed_bound(
2228 &self,
2229 trait_ref: hir::TraitRef<'_>,
2230 span: Span,
2231 rbp: RelaxedBoundPolicy,
2232 ) {
2233 match rbp {
2243 RelaxedBoundPolicy::Allowed => return,
2244 RelaxedBoundPolicy::Forbidden(reason) => {
2245 let gate = |context, subject| {
2246 let extended = self.tcx.features().more_maybe_bounds();
2247 let is_sized = trait_ref
2248 .trait_def_id()
2249 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, hir::LangItem::Sized));
2250
2251 if extended && !is_sized {
2252 return;
2253 }
2254
2255 let prefix = if extended { "`Sized` " } else { "" };
2256 let mut diag = self.dcx().struct_span_err(
2257 span,
2258 ::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}"),
2259 );
2260 if is_sized {
2261 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!(
2262 "{subject} are not implicitly bounded by `Sized`, \
2263 so there is nothing to relax"
2264 ));
2265 }
2266 diag.emit();
2267 };
2268
2269 match reason {
2270 RelaxedBoundForbiddenReason::TraitObjectTy => {
2271 gate("trait object types", "trait object types");
2272 return;
2273 }
2274 RelaxedBoundForbiddenReason::SuperTrait => {
2275 gate("supertrait bounds", "traits");
2276 return;
2277 }
2278 RelaxedBoundForbiddenReason::TraitAlias => {
2279 gate("trait alias bounds", "trait aliases");
2280 return;
2281 }
2282 RelaxedBoundForbiddenReason::AssocTyBounds
2283 | RelaxedBoundForbiddenReason::WhereBound => {}
2284 };
2285 }
2286 }
2287
2288 self.dcx()
2289 .struct_span_err(span, "this relaxed bound is not permitted here")
2290 .with_note(
2291 "in this context, relaxed bounds are only allowed on \
2292 type parameters defined on the closest item",
2293 )
2294 .emit();
2295 }
2296
2297 fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
2298 hir::MutTy { ty: self.lower_ty_alloc(&mt.ty, itctx), mutbl: mt.mutbl }
2299 }
2300
2301 x;#[instrument(level = "debug", skip(self), ret)]
2302 fn lower_param_bounds(
2303 &mut self,
2304 bounds: &[GenericBound],
2305 rbp: RelaxedBoundPolicy,
2306 itctx: ImplTraitContext,
2307 ) -> hir::GenericBounds<'hir> {
2308 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2309 }
2310
2311 fn lower_param_bounds_mut(
2312 &mut self,
2313 bounds: &[GenericBound],
2314 rbp: RelaxedBoundPolicy,
2315 itctx: ImplTraitContext,
2316 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2317 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp, itctx))
2318 }
2319
2320 x;#[instrument(level = "debug", skip(self), ret)]
2321 fn lower_universal_param_and_bounds(
2322 &mut self,
2323 node_id: NodeId,
2324 span: Span,
2325 ident: Ident,
2326 bounds: &[GenericBound],
2327 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2328 let def_id = self.local_def_id(node_id);
2330 let span = self.lower_span(span);
2331
2332 let param = hir::GenericParam {
2334 hir_id: self.lower_node_id(node_id),
2335 def_id,
2336 name: ParamName::Plain(self.lower_ident(ident)),
2337 pure_wrt_drop: false,
2338 span,
2339 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2340 colon_span: None,
2341 source: hir::GenericParamSource::Generics,
2342 };
2343
2344 let preds = self.lower_generic_bound_predicate(
2345 ident,
2346 node_id,
2347 &GenericParamKind::Type { default: None },
2348 bounds,
2349 None,
2350 span,
2351 RelaxedBoundPolicy::Allowed,
2352 ImplTraitContext::Universal,
2353 hir::PredicateOrigin::ImplTrait,
2354 );
2355
2356 let hir_id = self.next_id();
2357 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2358 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2359 None,
2360 self.arena.alloc(hir::Path {
2361 span,
2362 res,
2363 segments:
2364 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2365 }),
2366 ));
2367
2368 (param, preds, ty)
2369 }
2370
2371 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2374 let block = self.lower_block(b, false);
2375 self.expr_block(block)
2376 }
2377
2378 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2379 match c.value.peel_parens().kind {
2382 ExprKind::Underscore => {
2383 let ct_kind = hir::ConstArgKind::Infer(());
2384 self.arena.alloc(hir::ConstArg {
2385 hir_id: self.lower_node_id(c.id),
2386 kind: ct_kind,
2387 span: self.lower_span(c.value.span),
2388 })
2389 }
2390 _ => self.lower_anon_const_to_const_arg_and_alloc(c),
2391 }
2392 }
2393
2394 #[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(2397u32),
::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))]
2398 fn lower_const_path_to_const_arg(
2399 &mut self,
2400 path: &Path,
2401 res: Res<NodeId>,
2402 ty_id: NodeId,
2403 span: Span,
2404 ) -> &'hir hir::ConstArg<'hir> {
2405 let tcx = self.tcx;
2406
2407 let is_trivial_path = path.is_potential_trivial_const_arg()
2408 && matches!(res, Res::Def(DefKind::ConstParam, _));
2409 let ct_kind = if is_trivial_path || tcx.features().min_generic_const_args() {
2410 let qpath = self.lower_qpath(
2411 ty_id,
2412 &None,
2413 path,
2414 ParamMode::Explicit,
2415 AllowReturnTypeNotation::No,
2416 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2418 None,
2419 );
2420 hir::ConstArgKind::Path(qpath)
2421 } else {
2422 let node_id = self.next_node_id();
2424 let span = self.lower_span(span);
2425
2426 let def_id = self.create_def(node_id, None, DefKind::AnonConst, span);
2431 let hir_id = self.lower_node_id(node_id);
2432
2433 let path_expr = Expr {
2434 id: ty_id,
2435 kind: ExprKind::Path(None, path.clone()),
2436 span,
2437 attrs: AttrVec::new(),
2438 tokens: None,
2439 };
2440
2441 let ct = self.with_new_scopes(span, |this| {
2442 self.arena.alloc(hir::AnonConst {
2443 def_id,
2444 hir_id,
2445 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2446 span,
2447 })
2448 });
2449 hir::ConstArgKind::Anon(ct)
2450 };
2451
2452 self.arena.alloc(hir::ConstArg {
2453 hir_id: self.next_id(),
2454 kind: ct_kind,
2455 span: self.lower_span(span),
2456 })
2457 }
2458
2459 fn lower_const_item_rhs(
2460 &mut self,
2461 rhs_kind: &ConstItemRhsKind,
2462 span: Span,
2463 ) -> hir::ConstItemRhs<'hir> {
2464 match rhs_kind {
2465 ConstItemRhsKind::Body { rhs: Some(body) } => {
2466 hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body)))
2467 }
2468 ConstItemRhsKind::Body { rhs: None } => {
2469 hir::ConstItemRhs::Body(self.lower_const_body(span, None))
2470 }
2471 ConstItemRhsKind::TypeConst { rhs: Some(anon) } => {
2472 hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon))
2473 }
2474 ConstItemRhsKind::TypeConst { rhs: None } => {
2475 let const_arg = ConstArg {
2476 hir_id: self.next_id(),
2477 kind: hir::ConstArgKind::Error(
2478 self.dcx().span_delayed_bug(DUMMY_SP, "no block"),
2479 ),
2480 span: DUMMY_SP,
2481 };
2482 hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg))
2483 }
2484 }
2485 }
2486
2487 x;#[instrument(level = "debug", skip(self), ret)]
2488 fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir> {
2489 let span = self.lower_span(expr.span);
2490
2491 let overly_complex_const = |this: &mut Self| {
2492 let msg = "complex const arguments must be placed inside of a `const` block";
2493 let e = if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
2494 this.dcx().struct_span_fatal(expr.span, msg).emit()
2498 } else {
2499 this.dcx().struct_span_err(expr.span, msg).emit()
2500 };
2501
2502 ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(e), span }
2503 };
2504
2505 match &expr.kind {
2506 ExprKind::Call(func, args) if let ExprKind::Path(qself, path) = &func.kind => {
2507 let qpath = self.lower_qpath(
2508 func.id,
2509 qself,
2510 path,
2511 ParamMode::Explicit,
2512 AllowReturnTypeNotation::No,
2513 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2514 None,
2515 );
2516
2517 let lowered_args = self.arena.alloc_from_iter(args.iter().map(|arg| {
2518 let const_arg = self.lower_expr_to_const_arg_direct(arg);
2519 &*self.arena.alloc(const_arg)
2520 }));
2521
2522 ConstArg {
2523 hir_id: self.next_id(),
2524 kind: hir::ConstArgKind::TupleCall(qpath, lowered_args),
2525 span,
2526 }
2527 }
2528 ExprKind::Tup(exprs) => {
2529 let exprs = self.arena.alloc_from_iter(exprs.iter().map(|expr| {
2530 let expr = self.lower_expr_to_const_arg_direct(&expr);
2531 &*self.arena.alloc(expr)
2532 }));
2533
2534 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(exprs), span }
2535 }
2536 ExprKind::Path(qself, path) => {
2537 let qpath = self.lower_qpath(
2538 expr.id,
2539 qself,
2540 path,
2541 ParamMode::Explicit,
2542 AllowReturnTypeNotation::No,
2543 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2545 None,
2546 );
2547
2548 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath), span }
2549 }
2550 ExprKind::Struct(se) => {
2551 let path = self.lower_qpath(
2552 expr.id,
2553 &se.qself,
2554 &se.path,
2555 ParamMode::Explicit,
2559 AllowReturnTypeNotation::No,
2560 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2561 None,
2562 );
2563
2564 let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| {
2565 let hir_id = self.lower_node_id(f.id);
2566 self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField);
2570 let expr = self.lower_expr_to_const_arg_direct(&f.expr);
2571
2572 &*self.arena.alloc(hir::ConstArgExprField {
2573 hir_id,
2574 field: self.lower_ident(f.ident),
2575 expr: self.arena.alloc(expr),
2576 span: self.lower_span(f.span),
2577 })
2578 }));
2579
2580 ConstArg {
2581 hir_id: self.next_id(),
2582 kind: hir::ConstArgKind::Struct(path, fields),
2583 span,
2584 }
2585 }
2586 ExprKind::Array(elements) => {
2587 let lowered_elems = self.arena.alloc_from_iter(elements.iter().map(|element| {
2588 let const_arg = self.lower_expr_to_const_arg_direct(element);
2589 &*self.arena.alloc(const_arg)
2590 }));
2591 let array_expr = self.arena.alloc(hir::ConstArgArrayExpr {
2592 span: self.lower_span(expr.span),
2593 elems: lowered_elems,
2594 });
2595
2596 ConstArg {
2597 hir_id: self.next_id(),
2598 kind: hir::ConstArgKind::Array(array_expr),
2599 span,
2600 }
2601 }
2602 ExprKind::Underscore => ConstArg {
2603 hir_id: self.lower_node_id(expr.id),
2604 kind: hir::ConstArgKind::Infer(()),
2605 span,
2606 },
2607 ExprKind::Block(block, _) => {
2608 if let [stmt] = block.stmts.as_slice()
2609 && let StmtKind::Expr(expr) = &stmt.kind
2610 {
2611 return self.lower_expr_to_const_arg_direct(expr);
2612 }
2613
2614 overly_complex_const(self)
2615 }
2616 ExprKind::Lit(literal) => {
2617 let span = self.lower_span(expr.span);
2618 let literal = self.lower_lit(literal, span);
2619
2620 ConstArg {
2621 hir_id: self.lower_node_id(expr.id),
2622 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
2623 span,
2624 }
2625 }
2626 ExprKind::Unary(UnOp::Neg, inner_expr)
2627 if let ExprKind::Lit(literal) = &inner_expr.kind =>
2628 {
2629 let span = self.lower_span(expr.span);
2630 let literal = self.lower_lit(literal, span);
2631
2632 if !matches!(literal.node, LitKind::Int(..)) {
2633 let err =
2634 self.dcx().struct_span_err(expr.span, "negated literal must be an integer");
2635
2636 return ConstArg {
2637 hir_id: self.next_id(),
2638 kind: hir::ConstArgKind::Error(err.emit()),
2639 span,
2640 };
2641 }
2642
2643 ConstArg {
2644 hir_id: self.lower_node_id(expr.id),
2645 kind: hir::ConstArgKind::Literal { lit: literal.node, negated: true },
2646 span,
2647 }
2648 }
2649 ExprKind::ConstBlock(anon_const) => {
2650 let def_id = self.local_def_id(anon_const.id);
2651 assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
2652 self.lower_anon_const_to_const_arg(anon_const, span)
2653 }
2654 _ => overly_complex_const(self),
2655 }
2656 }
2657
2658 fn lower_anon_const_to_const_arg_and_alloc(
2661 &mut self,
2662 anon: &AnonConst,
2663 ) -> &'hir hir::ConstArg<'hir> {
2664 self.arena.alloc(self.lower_anon_const_to_const_arg(anon, anon.value.span))
2665 }
2666
2667 #[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(2667u32),
::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))]
2668 fn lower_anon_const_to_const_arg(
2669 &mut self,
2670 anon: &AnonConst,
2671 span: Span,
2672 ) -> hir::ConstArg<'hir> {
2673 let tcx = self.tcx;
2674
2675 if tcx.features().min_generic_const_args() {
2681 return match anon.mgca_disambiguation {
2682 MgcaDisambiguation::AnonConst => {
2683 let lowered_anon = self.lower_anon_const_to_anon_const(anon, span);
2684 ConstArg {
2685 hir_id: self.next_id(),
2686 kind: hir::ConstArgKind::Anon(lowered_anon),
2687 span: lowered_anon.span,
2688 }
2689 }
2690 MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
2691 };
2692 }
2693
2694 let expr = if let ExprKind::Block(block, _) = &anon.value.kind
2697 && let [stmt] = block.stmts.as_slice()
2698 && let StmtKind::Expr(expr) = &stmt.kind
2699 && let ExprKind::Path(..) = &expr.kind
2700 {
2701 expr
2702 } else {
2703 &anon.value
2704 };
2705
2706 let maybe_res =
2707 self.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2708 if let ExprKind::Path(qself, path) = &expr.kind
2709 && path.is_potential_trivial_const_arg()
2710 && matches!(maybe_res, Some(Res::Def(DefKind::ConstParam, _)))
2711 {
2712 let qpath = self.lower_qpath(
2713 expr.id,
2714 qself,
2715 path,
2716 ParamMode::Explicit,
2717 AllowReturnTypeNotation::No,
2718 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2719 None,
2720 );
2721
2722 return ConstArg {
2723 hir_id: self.lower_node_id(anon.id),
2724 kind: hir::ConstArgKind::Path(qpath),
2725 span: self.lower_span(expr.span),
2726 };
2727 }
2728
2729 let lowered_anon = self.lower_anon_const_to_anon_const(anon, anon.value.span);
2730 ConstArg {
2731 hir_id: self.next_id(),
2732 kind: hir::ConstArgKind::Anon(lowered_anon),
2733 span: self.lower_span(expr.span),
2734 }
2735 }
2736
2737 fn lower_anon_const_to_anon_const(
2740 &mut self,
2741 c: &AnonConst,
2742 span: Span,
2743 ) -> &'hir hir::AnonConst {
2744 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
2745 let def_id = this.local_def_id(c.id);
2746 let hir_id = this.lower_node_id(c.id);
2747 hir::AnonConst {
2748 def_id,
2749 hir_id,
2750 body: this.lower_const_body(c.value.span, Some(&c.value)),
2751 span: this.lower_span(span),
2752 }
2753 }))
2754 }
2755
2756 fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
2757 match u {
2758 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
2759 UserProvided => hir::UnsafeSource::UserProvided,
2760 }
2761 }
2762
2763 fn lower_trait_bound_modifiers(
2764 &mut self,
2765 modifiers: TraitBoundModifiers,
2766 ) -> hir::TraitBoundModifiers {
2767 let constness = match modifiers.constness {
2768 BoundConstness::Never => BoundConstness::Never,
2769 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
2770 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
2771 };
2772 let polarity = match modifiers.polarity {
2773 BoundPolarity::Positive => BoundPolarity::Positive,
2774 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
2775 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2776 };
2777 hir::TraitBoundModifiers { constness, polarity }
2778 }
2779
2780 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2783 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
2784 }
2785
2786 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
2787 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
2788 }
2789
2790 fn stmt_let_pat(
2791 &mut self,
2792 attrs: Option<&'hir [hir::Attribute]>,
2793 span: Span,
2794 init: Option<&'hir hir::Expr<'hir>>,
2795 pat: &'hir hir::Pat<'hir>,
2796 source: hir::LocalSource,
2797 ) -> hir::Stmt<'hir> {
2798 let hir_id = self.next_id();
2799 if let Some(a) = attrs {
2800 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
2801 self.attrs.insert(hir_id.local_id, a);
2802 }
2803 let local = hir::LetStmt {
2804 super_: None,
2805 hir_id,
2806 init,
2807 pat,
2808 els: None,
2809 source,
2810 span: self.lower_span(span),
2811 ty: None,
2812 };
2813 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2814 }
2815
2816 fn stmt_super_let_pat(
2817 &mut self,
2818 span: Span,
2819 pat: &'hir hir::Pat<'hir>,
2820 init: Option<&'hir hir::Expr<'hir>>,
2821 ) -> hir::Stmt<'hir> {
2822 let hir_id = self.next_id();
2823 let span = self.lower_span(span);
2824 let local = hir::LetStmt {
2825 super_: Some(span),
2826 hir_id,
2827 init,
2828 pat,
2829 els: None,
2830 source: hir::LocalSource::Normal,
2831 span,
2832 ty: None,
2833 };
2834 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2835 }
2836
2837 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
2838 self.block_all(expr.span, &[], Some(expr))
2839 }
2840
2841 fn block_all(
2842 &mut self,
2843 span: Span,
2844 stmts: &'hir [hir::Stmt<'hir>],
2845 expr: Option<&'hir hir::Expr<'hir>>,
2846 ) -> &'hir hir::Block<'hir> {
2847 let blk = hir::Block {
2848 stmts,
2849 expr,
2850 hir_id: self.next_id(),
2851 rules: hir::BlockCheckMode::DefaultBlock,
2852 span: self.lower_span(span),
2853 targeted_by_break: false,
2854 };
2855 self.arena.alloc(blk)
2856 }
2857
2858 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2859 let field = self.single_pat_field(span, pat);
2860 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field)
2861 }
2862
2863 fn pat_cf_break(&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::ControlFlowBreak, field)
2866 }
2867
2868 fn pat_some(&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::OptionSome, field)
2871 }
2872
2873 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
2874 self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[])
2875 }
2876
2877 fn single_pat_field(
2878 &mut self,
2879 span: Span,
2880 pat: &'hir hir::Pat<'hir>,
2881 ) -> &'hir [hir::PatField<'hir>] {
2882 let field = hir::PatField {
2883 hir_id: self.next_id(),
2884 ident: Ident::new(sym::integer(0), self.lower_span(span)),
2885 is_shorthand: false,
2886 pat,
2887 span: self.lower_span(span),
2888 };
2889 self.arena.alloc_from_iter([field])arena_vec![self; field]
2890 }
2891
2892 fn pat_lang_item_variant(
2893 &mut self,
2894 span: Span,
2895 lang_item: hir::LangItem,
2896 fields: &'hir [hir::PatField<'hir>],
2897 ) -> &'hir hir::Pat<'hir> {
2898 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2899 self.pat(span, hir::PatKind::Struct(path, fields, None))
2900 }
2901
2902 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
2903 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
2904 }
2905
2906 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
2907 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
2908 }
2909
2910 fn pat_ident_binding_mode(
2911 &mut self,
2912 span: Span,
2913 ident: Ident,
2914 bm: hir::BindingMode,
2915 ) -> (&'hir hir::Pat<'hir>, HirId) {
2916 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
2917 (self.arena.alloc(pat), hir_id)
2918 }
2919
2920 fn pat_ident_binding_mode_mut(
2921 &mut self,
2922 span: Span,
2923 ident: Ident,
2924 bm: hir::BindingMode,
2925 ) -> (hir::Pat<'hir>, HirId) {
2926 let hir_id = self.next_id();
2927
2928 (
2929 hir::Pat {
2930 hir_id,
2931 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
2932 span: self.lower_span(span),
2933 default_binding_modes: true,
2934 },
2935 hir_id,
2936 )
2937 }
2938
2939 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2940 self.arena.alloc(hir::Pat {
2941 hir_id: self.next_id(),
2942 kind,
2943 span: self.lower_span(span),
2944 default_binding_modes: true,
2945 })
2946 }
2947
2948 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
2949 hir::Pat {
2950 hir_id: self.next_id(),
2951 kind,
2952 span: self.lower_span(span),
2953 default_binding_modes: false,
2954 }
2955 }
2956
2957 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
2958 let kind = match qpath {
2959 hir::QPath::Resolved(None, path) => {
2960 match path.res {
2962 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
2963 let principal = hir::PolyTraitRef {
2964 bound_generic_params: &[],
2965 modifiers: hir::TraitBoundModifiers::NONE,
2966 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
2967 span: self.lower_span(span),
2968 };
2969
2970 hir_id = self.next_id();
2973 hir::TyKind::TraitObject(
2974 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
2975 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
2976 )
2977 }
2978 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
2979 }
2980 }
2981 _ => hir::TyKind::Path(qpath),
2982 };
2983
2984 hir::Ty { hir_id, kind, span: self.lower_span(span) }
2985 }
2986
2987 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
2992 let r = hir::Lifetime::new(
2993 self.next_id(),
2994 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
2995 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
2996 LifetimeSource::Other,
2997 LifetimeSyntax::Implicit,
2998 );
2999 {
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:2999",
"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(2999u32),
::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);
3000 self.arena.alloc(r)
3001 }
3002}
3003
3004struct GenericArgsCtor<'hir> {
3006 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
3007 constraints: &'hir [hir::AssocItemConstraint<'hir>],
3008 parenthesized: hir::GenericArgsParentheses,
3009 span: Span,
3010}
3011
3012impl<'hir> GenericArgsCtor<'hir> {
3013 fn is_empty(&self) -> bool {
3014 self.args.is_empty()
3015 && self.constraints.is_empty()
3016 && self.parenthesized == hir::GenericArgsParentheses::No
3017 }
3018
3019 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
3020 let ga = hir::GenericArgs {
3021 args: this.arena.alloc_from_iter(self.args),
3022 constraints: self.constraints,
3023 parenthesized: self.parenthesized,
3024 span_ext: this.lower_span(self.span),
3025 };
3026 this.arena.alloc(ga)
3027 }
3028}