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