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