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