1mod bounds;
19mod cmse;
20mod dyn_trait;
21pub mod errors;
22pub mod generics;
23
24use std::{assert_matches, slice};
25
26use rustc_abi::FIRST_VARIANT;
27use rustc_ast::LitKind;
28use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
29use rustc_data_structures::sso::SsoHashSet;
30use rustc_data_structures::thin_vec::ThinVec;
31use rustc_errors::codes::*;
32use rustc_errors::{
33 Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, StashKey,
34 struct_span_code_err,
35};
36use rustc_hir::attrs::lang_items::LangItem;
37use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
38use rustc_hir::def_id::{DefId, LocalDefId};
39use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId};
40use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
41use rustc_infer::traits::DynCompatibilityViolation;
42use rustc_lint_defs::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
43use rustc_macros::{TypeFoldable, TypeVisitable};
44use rustc_middle::middle::stability::AllowUnstable;
45use rustc_middle::ty::{
46 self, Const, FnSigKind, GenericArgKind, GenericArgsRef, GenericParamDefKind, LitToConstInput,
47 Ty, TyCtxt, TypeSuperFoldable, TypeVisitableExt, TypingMode, Unnormalized, Upcast,
48 const_lit_matches_ty, fold_regions,
49};
50use rustc_session::diagnostics::feature_err;
51use rustc_span::def_id::ModId;
52use rustc_span::{DUMMY_SP, Ident, Span, bug, kw, span_bug, sym};
53use rustc_trait_selection::infer::InferCtxtExt;
54use rustc_trait_selection::traits::{self, FulfillmentError};
55use tracing::{debug, instrument};
56
57use crate::check::check_abi;
58use crate::check_c_variadic_abi;
59use crate::diagnostics::{self, BadReturnTypeNotation, NoFieldOnType, NoVariantNamed};
60use crate::hir_ty_lowering::errors::{
61 GenericsArgsErrExtend, eq_ctxt_suggestion_span, prohibit_assoc_item_constraint,
62};
63use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
64use crate::middle::resolve_bound_vars as rbv;
65
66#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for ImpliedBoundsContext<'tcx> {
}
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for ImpliedBoundsContext<'tcx> {
#[inline]
fn clone(&self) -> ImpliedBoundsContext<'tcx> {
let _: ::core::clone::AssertParamIsClone<LocalDefId>;
let _:
::core::clone::AssertParamIsClone<&'tcx [hir::WherePredicate<'tcx>]>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for ImpliedBoundsContext<'tcx> { }Copy)]
69pub(crate) enum ImpliedBoundsContext<'tcx> {
70 TraitDef(LocalDefId),
73 TyParam(LocalDefId, &'tcx [hir::WherePredicate<'tcx>]),
75 AssociatedTypeOrImplTrait,
77}
78
79#[derive(#[automatically_derived]
impl ::core::fmt::Debug for GenericPathSegment {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"GenericPathSegment", &self.0, &&self.1)
}
}Debug)]
81pub struct GenericPathSegment(pub DefId, pub usize);
82
83#[derive(#[automatically_derived]
impl ::core::marker::Copy for PredicateFilter { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for PredicateFilter { }
#[automatically_derived]
impl ::core::clone::Clone for PredicateFilter {
#[inline]
fn clone(&self) -> PredicateFilter {
let _: ::core::clone::AssertParamIsClone<Ident>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for PredicateFilter {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
PredicateFilter::All =>
::core::fmt::Formatter::write_str(f, "All"),
PredicateFilter::SelfOnly =>
::core::fmt::Formatter::write_str(f, "SelfOnly"),
PredicateFilter::SelfTraitThatDefines(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"SelfTraitThatDefines", &__self_0),
PredicateFilter::SelfAndAssociatedTypeBounds =>
::core::fmt::Formatter::write_str(f,
"SelfAndAssociatedTypeBounds"),
PredicateFilter::ConstIfConst =>
::core::fmt::Formatter::write_str(f, "ConstIfConst"),
PredicateFilter::SelfConstIfConst =>
::core::fmt::Formatter::write_str(f, "SelfConstIfConst"),
}
}
}Debug)]
84pub enum PredicateFilter {
85 All,
87
88 SelfOnly,
90
91 SelfTraitThatDefines(Ident),
95
96 SelfAndAssociatedTypeBounds,
100
101 ConstIfConst,
103
104 SelfConstIfConst,
106}
107
108#[derive(#[automatically_derived]
impl<'a> ::core::fmt::Debug for RegionInferReason<'a> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RegionInferReason::ExplicitObjectLifetime =>
::core::fmt::Formatter::write_str(f,
"ExplicitObjectLifetime"),
RegionInferReason::ObjectLifetimeDefault(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ObjectLifetimeDefault", &__self_0),
RegionInferReason::Param(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Param",
&__self_0),
RegionInferReason::RegionPredicate =>
::core::fmt::Formatter::write_str(f, "RegionPredicate"),
RegionInferReason::Reference =>
::core::fmt::Formatter::write_str(f, "Reference"),
RegionInferReason::OutlivesBound =>
::core::fmt::Formatter::write_str(f, "OutlivesBound"),
}
}
}Debug)]
109pub enum RegionInferReason<'a> {
110 ExplicitObjectLifetime,
112 ObjectLifetimeDefault(Span),
114 Param(&'a ty::GenericParamDef),
116 RegionPredicate,
117 Reference,
118 OutlivesBound,
119}
120
121#[derive(#[automatically_derived]
impl ::core::marker::Copy for InherentAssocCandidate { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for InherentAssocCandidate { }
#[automatically_derived]
impl ::core::clone::Clone for InherentAssocCandidate {
#[inline]
fn clone(&self) -> InherentAssocCandidate {
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<ModId>;
*self
}
}Clone, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for InherentAssocCandidate {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
InherentAssocCandidate {
impl_: __binding_0,
assoc_item: __binding_1,
scope: __binding_2 } => {
InherentAssocCandidate {
impl_: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
assoc_item: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
scope: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_2,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
InherentAssocCandidate {
impl_: __binding_0,
assoc_item: __binding_1,
scope: __binding_2 } => {
InherentAssocCandidate {
impl_: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
assoc_item: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
scope: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_2,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for InherentAssocCandidate {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
InherentAssocCandidate {
impl_: ref __binding_0,
assoc_item: ref __binding_1,
scope: ref __binding_2 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_2,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable, #[automatically_derived]
impl ::core::fmt::Debug for InherentAssocCandidate {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"InherentAssocCandidate", "impl_", &self.impl_, "assoc_item",
&self.assoc_item, "scope", &&self.scope)
}
}Debug)]
122pub struct InherentAssocCandidate {
123 pub impl_: DefId,
124 pub assoc_item: DefId,
125 pub scope: ModId,
126}
127
128pub struct ResolvedStructPath<'tcx> {
129 pub res: Result<Res, ErrorGuaranteed>,
130 pub ty: Ty<'tcx>,
131}
132
133pub trait HirTyLowerer<'tcx> {
138 fn tcx(&self) -> TyCtxt<'tcx>;
139
140 fn dcx(&self) -> DiagCtxtHandle<'_>;
141
142 fn item_def_id(&self) -> LocalDefId;
144
145 fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> ty::Region<'tcx>;
147
148 fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
150
151 fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx>;
153
154 fn register_trait_ascription_bounds(
155 &self,
156 bounds: Vec<(ty::Clause<'tcx>, Span)>,
157 hir_id: HirId,
158 span: Span,
159 );
160
161 fn probe_ty_param_bounds(
176 &self,
177 span: Span,
178 def_id: LocalDefId,
179 assoc_ident: Ident,
180 ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]>;
181
182 fn select_inherent_assoc_candidates(
183 &self,
184 span: Span,
185 self_ty: Ty<'tcx>,
186 candidates: Vec<InherentAssocCandidate>,
187 ) -> (Vec<InherentAssocCandidate>, ThinVec<FulfillmentError<'tcx>>);
188
189 fn lower_assoc_item_path(
202 &self,
203 span: Span,
204 item_def_id: DefId,
205 item_segment: &hir::PathSegment<'_>,
206 poly_trait_ref: ty::PolyTraitRef<'tcx>,
207 ) -> Result<(DefId, GenericArgsRef<'tcx>), ErrorGuaranteed>;
208
209 fn lower_fn_sig(
210 &self,
211 decl: &hir::FnDecl<'_>,
212 generics: Option<&hir::Generics<'_>>,
213 hir_id: HirId,
214 hir_ty: Option<&hir::Ty<'_>>,
215 ) -> (Vec<Ty<'tcx>>, Ty<'tcx>);
216
217 fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
224
225 fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
227
228 fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
230
231 fn lowerer(&self) -> &dyn HirTyLowerer<'tcx>
236 where
237 Self: Sized,
238 {
239 self
240 }
241
242 fn dyn_compatibility_violations(&self, trait_def_id: DefId) -> Vec<DynCompatibilityViolation>;
245}
246
247enum AssocItemQSelf {
251 Trait(DefId),
252 TyParam(LocalDefId, Span),
253 SelfTyAlias,
254}
255
256impl AssocItemQSelf {
257 fn to_string(&self, tcx: TyCtxt<'_>) -> String {
258 match *self {
259 Self::Trait(def_id) => tcx.def_path_str(def_id),
260 Self::TyParam(def_id, _) => tcx.hir_ty_param_name(def_id).to_string(),
261 Self::SelfTyAlias => kw::SelfUpper.to_string(),
262 }
263 }
264}
265
266#[derive(#[automatically_derived]
impl ::core::fmt::Debug for LowerTypeRelativePathMode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
LowerTypeRelativePathMode::Type(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Type",
&__self_0),
LowerTypeRelativePathMode::Const =>
::core::fmt::Formatter::write_str(f, "Const"),
}
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LowerTypeRelativePathMode { }
#[automatically_derived]
impl ::core::clone::Clone for LowerTypeRelativePathMode {
#[inline]
fn clone(&self) -> LowerTypeRelativePathMode {
let _: ::core::clone::AssertParamIsClone<PermitVariants>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LowerTypeRelativePathMode { }Copy)]
267enum LowerTypeRelativePathMode {
268 Type(PermitVariants),
269 Const,
270}
271
272impl LowerTypeRelativePathMode {
273 fn assoc_tag(self) -> ty::AssocTag {
274 match self {
275 Self::Type(_) => ty::AssocTag::Type,
276 Self::Const => ty::AssocTag::Const,
277 }
278 }
279
280 fn def_kind_for_diagnostics(self) -> DefKind {
282 match self {
283 Self::Type(_) => DefKind::AssocTy,
284 Self::Const => DefKind::AssocConst,
285 }
286 }
287
288 fn permit_variants(self) -> PermitVariants {
289 match self {
290 Self::Type(permit_variants) => permit_variants,
291 Self::Const => PermitVariants::No,
294 }
295 }
296}
297
298#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PermitVariants {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
PermitVariants::Yes => "Yes",
PermitVariants::No => "No",
})
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for PermitVariants { }
#[automatically_derived]
impl ::core::clone::Clone for PermitVariants {
#[inline]
fn clone(&self) -> PermitVariants { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for PermitVariants { }Copy)]
300pub enum PermitVariants {
301 Yes,
302 No,
303}
304
305#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for TypeRelativePath<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
TypeRelativePath::AssocItem(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AssocItem", &__self_0),
TypeRelativePath::Variant { adt: __self_0, variant_did: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Variant", "adt", __self_0, "variant_did", &__self_1),
TypeRelativePath::Ctor { ctor_def_id: __self_0, args: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Ctor",
"ctor_def_id", __self_0, "args", &__self_1),
}
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for TypeRelativePath<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for TypeRelativePath<'tcx> {
#[inline]
fn clone(&self) -> TypeRelativePath<'tcx> {
let _: ::core::clone::AssertParamIsClone<ty::AliasTerm<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Ty<'tcx>>;
let _: ::core::clone::AssertParamIsClone<DefId>;
let _: ::core::clone::AssertParamIsClone<GenericArgsRef<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::marker::Copy for TypeRelativePath<'tcx> { }Copy)]
306enum TypeRelativePath<'tcx> {
307 AssocItem(ty::AliasTerm<'tcx>),
308 Variant { adt: Ty<'tcx>, variant_did: DefId },
309 Ctor { ctor_def_id: DefId, args: GenericArgsRef<'tcx> },
310}
311
312#[derive(#[automatically_derived]
impl ::core::marker::Copy for ExplicitLateBound { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ExplicitLateBound { }
#[automatically_derived]
impl ::core::clone::Clone for ExplicitLateBound {
#[inline]
fn clone(&self) -> ExplicitLateBound { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for ExplicitLateBound { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ExplicitLateBound {
#[inline]
fn eq(&self, other: &ExplicitLateBound) -> 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 ExplicitLateBound {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ExplicitLateBound::Yes => "Yes",
ExplicitLateBound::No => "No",
})
}
}Debug)]
322pub enum ExplicitLateBound {
323 Yes,
324 No,
325}
326
327#[derive(#[automatically_derived]
impl ::core::fmt::Debug for IsMethodCall {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
IsMethodCall::Yes => "Yes",
IsMethodCall::No => "No",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for IsMethodCall { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for IsMethodCall { }
#[automatically_derived]
impl ::core::clone::Clone for IsMethodCall {
#[inline]
fn clone(&self) -> IsMethodCall { *self }
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for IsMethodCall { }
#[automatically_derived]
impl ::core::cmp::PartialEq for IsMethodCall {
#[inline]
fn eq(&self, other: &IsMethodCall) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
328pub enum IsMethodCall {
329 Yes,
330 No,
331}
332
333#[derive(#[automatically_derived]
impl ::core::fmt::Debug for GenericArgPosition {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
GenericArgPosition::Type =>
::core::fmt::Formatter::write_str(f, "Type"),
GenericArgPosition::Value(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Value",
&__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for GenericArgPosition { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for GenericArgPosition { }
#[automatically_derived]
impl ::core::clone::Clone for GenericArgPosition {
#[inline]
fn clone(&self) -> GenericArgPosition {
let _: ::core::clone::AssertParamIsClone<IsMethodCall>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for GenericArgPosition { }
#[automatically_derived]
impl ::core::cmp::PartialEq for GenericArgPosition {
#[inline]
fn eq(&self, other: &GenericArgPosition) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(GenericArgPosition::Value(__self_0),
GenericArgPosition::Value(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
336pub(crate) enum GenericArgPosition {
337 Type,
338 Value(IsMethodCall),
339}
340
341#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for OverlappingAsssocItemConstraints {
}
#[automatically_derived]
impl ::core::clone::Clone for OverlappingAsssocItemConstraints {
#[inline]
fn clone(&self) -> OverlappingAsssocItemConstraints { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for OverlappingAsssocItemConstraints { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for OverlappingAsssocItemConstraints {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
OverlappingAsssocItemConstraints::Allowed => "Allowed",
OverlappingAsssocItemConstraints::Forbidden => "Forbidden",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for OverlappingAsssocItemConstraints
{
}
#[automatically_derived]
impl ::core::cmp::PartialEq for OverlappingAsssocItemConstraints {
#[inline]
fn eq(&self, other: &OverlappingAsssocItemConstraints) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
345pub(crate) enum OverlappingAsssocItemConstraints {
346 Allowed,
347 Forbidden,
348}
349
350#[derive(#[automatically_derived]
impl ::core::clone::Clone for GenericArgCountMismatch {
#[inline]
fn clone(&self) -> GenericArgCountMismatch {
GenericArgCountMismatch {
reported: ::core::clone::Clone::clone(&self.reported),
invalid_args: ::core::clone::Clone::clone(&self.invalid_args),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for GenericArgCountMismatch {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"GenericArgCountMismatch", "reported", &self.reported,
"invalid_args", &&self.invalid_args)
}
}Debug)]
353pub struct GenericArgCountMismatch {
354 pub reported: ErrorGuaranteed,
355 pub invalid_args: Vec<usize>,
357}
358
359#[derive(#[automatically_derived]
impl ::core::clone::Clone for GenericArgCountResult {
#[inline]
fn clone(&self) -> GenericArgCountResult {
GenericArgCountResult {
explicit_late_bound: ::core::clone::Clone::clone(&self.explicit_late_bound),
correct: ::core::clone::Clone::clone(&self.correct),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for GenericArgCountResult {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"GenericArgCountResult", "explicit_late_bound",
&self.explicit_late_bound, "correct", &&self.correct)
}
}Debug)]
362pub struct GenericArgCountResult {
363 pub explicit_late_bound: ExplicitLateBound,
364 pub correct: Result<(), GenericArgCountMismatch>,
365}
366
367pub trait GenericArgsLowerer<'a, 'tcx> {
372 fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'a>>, bool);
373
374 fn provided_kind(
375 &mut self,
376 preceding_args: &[ty::GenericArg<'tcx>],
377 param: &ty::GenericParamDef,
378 arg: &GenericArg<'_>,
379 ) -> ty::GenericArg<'tcx>;
380
381 fn inferred_kind(
382 &mut self,
383 preceding_args: &[ty::GenericArg<'tcx>],
384 param: &ty::GenericParamDef,
385 infer_args: bool,
386 ) -> ty::GenericArg<'tcx>;
387}
388
389enum ForbidParamContext {
391 ConstArgument,
393 EnumDiscriminant,
395}
396
397struct ForbidParamUsesFolder<'tcx> {
398 tcx: TyCtxt<'tcx>,
399 anon_const_def_id: LocalDefId,
400 span: Span,
401 is_self_alias: bool,
402 context: ForbidParamContext,
403}
404
405impl<'tcx> ForbidParamUsesFolder<'tcx> {
406 fn error(&self) -> ErrorGuaranteed {
407 let msg = match self.context {
408 ForbidParamContext::EnumDiscriminant if self.is_self_alias => {
409 "generic `Self` types are not permitted in enum discriminant values"
410 }
411 ForbidParamContext::EnumDiscriminant => {
412 "generic parameters may not be used in enum discriminant values"
413 }
414 ForbidParamContext::ConstArgument if self.is_self_alias => {
415 "generic `Self` types are currently not permitted in anonymous constants"
416 }
417 ForbidParamContext::ConstArgument => {
418 if self.tcx.features().generic_const_args() {
419 "generic parameters in const blocks are not allowed; use a named `const` item instead"
420 } else {
421 "generic parameters may not be used in const operations"
422 }
423 }
424 };
425 let mut diag = self.tcx.dcx().struct_span_err(self.span, msg);
426 if self.is_self_alias && #[allow(non_exhaustive_omitted_patterns)] match self.context {
ForbidParamContext::ConstArgument => true,
_ => false,
}matches!(self.context, ForbidParamContext::ConstArgument) {
427 let anon_const_hir_id: HirId = HirId::make_owner(self.anon_const_def_id);
428 let parent_impl = self.tcx.hir_parent_owner_iter(anon_const_hir_id).find_map(
429 |(_, node)| match node {
430 hir::OwnerNode::Item(hir::Item {
431 kind: hir::ItemKind::Impl(impl_), ..
432 }) => Some(impl_),
433 _ => None,
434 },
435 );
436 if let Some(impl_) = parent_impl {
437 diag.span_note(impl_.self_ty.span, "not a concrete type");
438 }
439 }
440 if #[allow(non_exhaustive_omitted_patterns)] match self.context {
ForbidParamContext::ConstArgument => true,
_ => false,
}matches!(self.context, ForbidParamContext::ConstArgument) {
441 if self.tcx.features().generic_const_args() {
442 diag.help("consider factoring the expression into a `type const` item and use it as the const argument instead");
443 } else if self.tcx.features().min_generic_const_args() {
444 diag.help("add `#![feature(generic_const_args)]` and extract the expression into a `type const` item");
445 } else if self.tcx.sess.is_nightly_build() {
446 diag.help(
447 "add `#![feature(generic_const_exprs)]` to allow generic const expressions",
448 );
449 diag.help("alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item");
450 }
451 }
452 diag.emit()
453 }
454}
455
456impl<'tcx> ty::TypeFolder<TyCtxt<'tcx>> for ForbidParamUsesFolder<'tcx> {
457 fn cx(&self) -> TyCtxt<'tcx> {
458 self.tcx
459 }
460
461 fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
462 if #[allow(non_exhaustive_omitted_patterns)] match t.kind() {
ty::Param(..) => true,
_ => false,
}matches!(t.kind(), ty::Param(..)) {
463 return Ty::new_error(self.tcx, self.error());
464 }
465 t.super_fold_with(self)
466 }
467
468 fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
469 if #[allow(non_exhaustive_omitted_patterns)] match c.kind() {
ty::ConstKind::Param(..) => true,
_ => false,
}matches!(c.kind(), ty::ConstKind::Param(..)) {
470 return Const::new_error(self.tcx, self.error());
471 }
472 c.super_fold_with(self)
473 }
474
475 fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
476 if #[allow(non_exhaustive_omitted_patterns)] match r.kind() {
ty::RegionKind::ReEarlyParam(..) | ty::RegionKind::ReLateParam(..) =>
true,
_ => false,
}matches!(r.kind(), ty::RegionKind::ReEarlyParam(..) | ty::RegionKind::ReLateParam(..)) {
477 return ty::Region::new_error(self.tcx, self.error());
478 }
479 r
480 }
481}
482
483impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
484 pub fn check_param_res_if_mcg_for_instantiate_value_path(
488 &self,
489 res: Res,
490 span: Span,
491 ) -> Result<(), ErrorGuaranteed> {
492 let tcx = self.tcx();
493 let parent_def_id = self.item_def_id();
494 if let Res::Def(DefKind::ConstParam, _) = res
498 && let Some(context) = self.anon_const_forbids_generic_params()
499 {
500 let folder = ForbidParamUsesFolder {
501 tcx,
502 anon_const_def_id: parent_def_id,
503 span,
504 is_self_alias: false,
505 context,
506 };
507 return Err(folder.error());
508 }
509 Ok(())
510 }
511
512 fn anon_const_forbids_generic_params(&self) -> Option<ForbidParamContext> {
520 let tcx = self.tcx();
521 let item_def_id = self.item_def_id();
522
523 let anon_const_def_id = tcx.typeck_root_def_id_local(item_def_id);
527
528 if tcx.def_kind(anon_const_def_id) != DefKind::AnonConst {
529 return None;
530 }
531
532 match tcx.anon_const_kind(anon_const_def_id) {
533 ty::AnonConstKind::MCG => Some(ForbidParamContext::ConstArgument),
534 ty::AnonConstKind::NonTypeSystemAnon => {
535 if tcx.generics_of(anon_const_def_id).count() == 0 {
539 Some(ForbidParamContext::EnumDiscriminant)
540 } else {
541 None
542 }
543 }
544 ty::AnonConstKind::NonTypeSystemInline
545 | ty::AnonConstKind::GCE
546 | ty::AnonConstKind::RepeatExprCount => None,
547 }
548 }
549
550 #[must_use = "need to use transformed output"]
556 fn check_param_uses_if_mcg<T>(&self, term: T, span: Span, is_self_alias: bool) -> T
557 where
558 T: ty::TypeFoldable<TyCtxt<'tcx>>,
559 {
560 let tcx = self.tcx();
561 if let Some(context) = self.anon_const_forbids_generic_params()
562 && (term.has_param() || term.has_escaping_bound_vars())
564 {
565 let anon_const_def_id = self.item_def_id();
566 let mut folder =
567 ForbidParamUsesFolder { tcx, anon_const_def_id, span, is_self_alias, context };
568 term.fold_with(&mut folder)
569 } else {
570 term
571 }
572 }
573
574 {}
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_lifetime",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(575u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetime")
}> =
::tracing::__macro_support::FieldName::new("lifetime");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("reason")
}> =
::tracing::__macro_support::FieldName::new("reason");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetime)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&reason)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: ty::Region<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(resolved) =
self.tcx().named_bound_var(lifetime.hir_id) {
let region = self.lower_resolved_lifetime(resolved);
self.check_param_uses_if_mcg(region, lifetime.ident.span,
false)
} else { self.re_infer(lifetime.ident.span, reason) }
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:575",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(575u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
576 pub fn lower_lifetime(
577 &self,
578 lifetime: &hir::Lifetime,
579 reason: RegionInferReason<'_>,
580 ) -> ty::Region<'tcx> {
581 if let Some(resolved) = self.tcx().named_bound_var(lifetime.hir_id) {
582 let region = self.lower_resolved_lifetime(resolved);
583 self.check_param_uses_if_mcg(region, lifetime.ident.span, false)
584 } else {
585 self.re_infer(lifetime.ident.span, reason)
586 }
587 }
588
589 {}
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_resolved_lifetime",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(590u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("resolved")
}> =
::tracing::__macro_support::FieldName::new("resolved");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&resolved)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: ty::Region<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
match resolved {
rbv::ResolvedArg::StaticLifetime => tcx.lifetimes.re_static,
rbv::ResolvedArg::LateBound(debruijn, index, def_id) => {
let br =
ty::BoundRegion {
var: ty::BoundVar::from_u32(index),
kind: ty::BoundRegionKind::Named(def_id.to_def_id()),
};
ty::Region::new_bound(tcx, debruijn, br)
}
rbv::ResolvedArg::EarlyBound(def_id) => {
let name = tcx.hir_ty_param_name(def_id);
let item_def_id = tcx.hir_ty_param_owner(def_id);
let generics = tcx.generics_of(item_def_id);
let index =
generics.param_def_id_to_index[&def_id.to_def_id()];
ty::Region::new_early_param(tcx,
ty::EarlyParamRegion { index, name })
}
rbv::ResolvedArg::Free(scope, id) => {
ty::Region::new_late_param(tcx, scope.to_def_id(),
ty::LateParamRegionKind::Named(id.to_def_id()))
}
rbv::ResolvedArg::Error(guar) =>
ty::Region::new_error(tcx, guar),
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:590",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(590u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
591 fn lower_resolved_lifetime(&self, resolved: rbv::ResolvedArg) -> ty::Region<'tcx> {
592 let tcx = self.tcx();
593
594 match resolved {
595 rbv::ResolvedArg::StaticLifetime => tcx.lifetimes.re_static,
596
597 rbv::ResolvedArg::LateBound(debruijn, index, def_id) => {
598 let br = ty::BoundRegion {
599 var: ty::BoundVar::from_u32(index),
600 kind: ty::BoundRegionKind::Named(def_id.to_def_id()),
601 };
602 ty::Region::new_bound(tcx, debruijn, br)
603 }
604
605 rbv::ResolvedArg::EarlyBound(def_id) => {
606 let name = tcx.hir_ty_param_name(def_id);
607 let item_def_id = tcx.hir_ty_param_owner(def_id);
608 let generics = tcx.generics_of(item_def_id);
609 let index = generics.param_def_id_to_index[&def_id.to_def_id()];
610 ty::Region::new_early_param(tcx, ty::EarlyParamRegion { index, name })
611 }
612
613 rbv::ResolvedArg::Free(scope, id) => {
614 ty::Region::new_late_param(
615 tcx,
616 scope.to_def_id(),
617 ty::LateParamRegionKind::Named(id.to_def_id()),
618 )
619
620 }
622
623 rbv::ResolvedArg::Error(guar) => ty::Region::new_error(tcx, guar),
624 }
625 }
626
627 pub fn lower_generic_args_of_path_segment(
628 &self,
629 span: Span,
630 def_id: DefId,
631 item_segment: &hir::PathSegment<'_>,
632 ) -> GenericArgsRef<'tcx> {
633 let (args, _) = self.lower_generic_args_of_path(span, def_id, &[], item_segment, None);
634 if let Some(c) = item_segment.args().constraints.first() {
635 prohibit_assoc_item_constraint(self, c, Some((def_id, item_segment, span)));
636 }
637 args
638 }
639
640 {}
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_args_of_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(674u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("parent_args")
}> =
::tracing::__macro_support::FieldName::new("parent_args");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("segment")
}> =
::tracing::__macro_support::FieldName::new("segment");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_args)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
(GenericArgsRef<'tcx>, GenericArgCountResult) = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let generics = tcx.generics_of(def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:689",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(689u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("generics")
}> =
::tracing::__macro_support::FieldName::new("generics");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generics)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if generics.has_self {
if generics.parent.is_some() {
if !!parent_args.is_empty() {
::core::panicking::panic("assertion failed: !parent_args.is_empty()")
}
} else {
if !self_ty.is_some() {
::core::panicking::panic("assertion failed: self_ty.is_some()")
};
}
} else {
if !self_ty.is_none() {
::core::panicking::panic("assertion failed: self_ty.is_none()")
};
}
let arg_count =
check_generic_arg_count(self, def_id, segment, generics,
GenericArgPosition::Type, self_ty.is_some());
if generics.is_own_empty() {
return (tcx.mk_args(parent_args), arg_count);
}
struct GenericArgsCtxt<'a, 'tcx> {
lowerer: &'a dyn HirTyLowerer<'tcx>,
def_id: DefId,
generic_args: &'a GenericArgs<'a>,
span: Span,
infer_args: bool,
create_synth_args: bool,
incorrect_args: &'a Result<(), GenericArgCountMismatch>,
}
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for
GenericArgsCtxt<'a, 'tcx> {
fn args_for_def_id(&mut self, did: DefId)
-> (Option<&'a GenericArgs<'a>>, bool) {
if did == self.def_id {
(Some(self.generic_args), self.infer_args)
} else { (None, false) }
}
fn provided_kind(&mut self,
preceding_args: &[ty::GenericArg<'tcx>],
param: &ty::GenericParamDef, arg: &GenericArg<'_>)
-> ty::GenericArg<'tcx> {
let tcx = self.lowerer.tcx();
if let Err(incorrect) = self.incorrect_args {
if incorrect.invalid_args.contains(&(param.index as usize))
{
return param.to_error(tcx);
}
}
let handle_ty_args =
|has_default, ty: &hir::Ty<'_>|
{
if has_default {
tcx.check_optional_stability(param.def_id,
Some(arg.hir_id()), arg.span(), None, AllowUnstable::No,
|_, _| {});
}
self.lowerer.lower_ty(ty).into()
};
match (¶m.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) =>
{
self.lowerer.lower_lifetime(lt,
RegionInferReason::Param(param)).into()
}
(&GenericParamDefKind::Type { has_default, .. },
GenericArg::Type(ty)) => {
handle_ty_args(has_default, ty.as_unambig_ty())
}
(&GenericParamDefKind::Type { has_default, .. },
GenericArg::Infer(inf)) => {
handle_ty_args(has_default, &inf.to_ty())
}
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct))
=>
self.lowerer.lower_const_arg(ct.as_unambig_ct(),
tcx.type_of(param.def_id).instantiate(tcx,
preceding_args).skip_norm_wip()).into(),
(&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf))
=> {
self.lowerer.ct_infer(Some(param), inf.span).into()
}
(kind, arg) =>
bug_impl(Some(self.span),
format_args!("mismatched path argument for kind {0:?}: found arg {1:?}",
kind, arg), Location::caller()),
}
}
fn inferred_kind(&mut self,
preceding_args: &[ty::GenericArg<'tcx>],
param: &ty::GenericParamDef, infer_args: bool)
-> ty::GenericArg<'tcx> {
let tcx = self.lowerer.tcx();
if let Err(incorrect) = self.incorrect_args {
if incorrect.invalid_args.contains(&(param.index as usize))
{
return param.to_error(tcx);
}
}
match param.kind {
GenericParamDefKind::Lifetime => {
self.lowerer.re_infer(self.span,
RegionInferReason::Param(param)).into()
}
GenericParamDefKind::Type { has_default, synthetic } => {
if !infer_args && has_default {
if let Some(prev) =
preceding_args.iter().find_map(|arg|
match arg.kind() {
GenericArgKind::Type(ty) => ty.error_reported().err(),
_ => None,
}) {
return Ty::new_error(tcx, prev).into();
}
tcx.at(self.span).type_of(param.def_id).instantiate(tcx,
preceding_args).skip_norm_wip().into()
} else if self.create_synth_args && synthetic {
Ty::new_param(tcx, param.index, param.name).into()
} else if infer_args {
self.lowerer.ty_infer(Some(param), self.span).into()
} else { Ty::new_misc_error(tcx).into() }
}
GenericParamDefKind::Const { has_default, .. } => {
let ty =
tcx.at(self.span).type_of(param.def_id).instantiate(tcx,
preceding_args).skip_norm_wip();
if let Err(guar) = ty.error_reported() {
return ty::Const::new_error(tcx, guar).into();
}
if !infer_args && has_default {
tcx.const_param_default(param.def_id).instantiate(tcx,
preceding_args).skip_norm_wip().into()
} else if infer_args {
self.lowerer.ct_infer(Some(param), self.span).into()
} else { ty::Const::new_misc_error(tcx).into() }
}
}
}
}
let mut args_ctx =
GenericArgsCtxt {
lowerer: self,
def_id,
span,
generic_args: segment.args(),
infer_args: segment.infer_args,
create_synth_args: segment.delegation_child_segment,
incorrect_args: &arg_count.correct,
};
let args =
lower_generic_args(self, def_id, parent_args,
self_ty.is_some(), self_ty, &arg_count, &mut args_ctx);
(args, arg_count)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:674",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(674u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self, span), ret)]
675 pub(crate) fn lower_generic_args_of_path(
676 &self,
677 span: Span,
678 def_id: DefId,
679 parent_args: &[ty::GenericArg<'tcx>],
680 segment: &hir::PathSegment<'_>,
681 self_ty: Option<Ty<'tcx>>,
682 ) -> (GenericArgsRef<'tcx>, GenericArgCountResult) {
683 let tcx = self.tcx();
688 let generics = tcx.generics_of(def_id);
689 debug!(?generics);
690
691 if generics.has_self {
692 if generics.parent.is_some() {
693 assert!(!parent_args.is_empty())
696 } else {
697 assert!(self_ty.is_some());
699 }
700 } else {
701 assert!(self_ty.is_none());
702 }
703
704 let arg_count = check_generic_arg_count(
705 self,
706 def_id,
707 segment,
708 generics,
709 GenericArgPosition::Type,
710 self_ty.is_some(),
711 );
712
713 if generics.is_own_empty() {
718 return (tcx.mk_args(parent_args), arg_count);
719 }
720
721 struct GenericArgsCtxt<'a, 'tcx> {
722 lowerer: &'a dyn HirTyLowerer<'tcx>,
723 def_id: DefId,
724 generic_args: &'a GenericArgs<'a>,
725 span: Span,
726 infer_args: bool,
727 create_synth_args: bool,
728 incorrect_args: &'a Result<(), GenericArgCountMismatch>,
729 }
730
731 impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
732 fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'a>>, bool) {
733 if did == self.def_id {
734 (Some(self.generic_args), self.infer_args)
735 } else {
736 (None, false)
738 }
739 }
740
741 fn provided_kind(
742 &mut self,
743 preceding_args: &[ty::GenericArg<'tcx>],
744 param: &ty::GenericParamDef,
745 arg: &GenericArg<'_>,
746 ) -> ty::GenericArg<'tcx> {
747 let tcx = self.lowerer.tcx();
748
749 if let Err(incorrect) = self.incorrect_args {
750 if incorrect.invalid_args.contains(&(param.index as usize)) {
751 return param.to_error(tcx);
752 }
753 }
754
755 let handle_ty_args = |has_default, ty: &hir::Ty<'_>| {
756 if has_default {
757 tcx.check_optional_stability(
758 param.def_id,
759 Some(arg.hir_id()),
760 arg.span(),
761 None,
762 AllowUnstable::No,
763 |_, _| {
764 },
770 );
771 }
772 self.lowerer.lower_ty(ty).into()
773 };
774
775 match (¶m.kind, arg) {
776 (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
777 self.lowerer.lower_lifetime(lt, RegionInferReason::Param(param)).into()
778 }
779 (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
780 handle_ty_args(has_default, ty.as_unambig_ty())
782 }
783 (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Infer(inf)) => {
784 handle_ty_args(has_default, &inf.to_ty())
785 }
786 (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => self
787 .lowerer
788 .lower_const_arg(
790 ct.as_unambig_ct(),
791 tcx.type_of(param.def_id)
792 .instantiate(tcx, preceding_args)
793 .skip_norm_wip(),
794 )
795 .into(),
796 (&GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
797 self.lowerer.ct_infer(Some(param), inf.span).into()
798 }
799 (kind, arg) => span_bug!(
800 self.span,
801 "mismatched path argument for kind {kind:?}: found arg {arg:?}"
802 ),
803 }
804 }
805
806 fn inferred_kind(
807 &mut self,
808 preceding_args: &[ty::GenericArg<'tcx>],
809 param: &ty::GenericParamDef,
810 infer_args: bool,
811 ) -> ty::GenericArg<'tcx> {
812 let tcx = self.lowerer.tcx();
813
814 if let Err(incorrect) = self.incorrect_args {
815 if incorrect.invalid_args.contains(&(param.index as usize)) {
816 return param.to_error(tcx);
817 }
818 }
819 match param.kind {
820 GenericParamDefKind::Lifetime => {
821 self.lowerer.re_infer(self.span, RegionInferReason::Param(param)).into()
822 }
823 GenericParamDefKind::Type { has_default, synthetic } => {
824 if !infer_args && has_default {
825 if let Some(prev) =
827 preceding_args.iter().find_map(|arg| match arg.kind() {
828 GenericArgKind::Type(ty) => ty.error_reported().err(),
829 _ => None,
830 })
831 {
832 return Ty::new_error(tcx, prev).into();
834 }
835 tcx.at(self.span)
836 .type_of(param.def_id)
837 .instantiate(tcx, preceding_args)
838 .skip_norm_wip()
839 .into()
840 } else if self.create_synth_args && synthetic {
841 Ty::new_param(tcx, param.index, param.name).into()
842 } else if infer_args {
843 self.lowerer.ty_infer(Some(param), self.span).into()
844 } else {
845 Ty::new_misc_error(tcx).into()
847 }
848 }
849 GenericParamDefKind::Const { has_default, .. } => {
850 let ty = tcx
851 .at(self.span)
852 .type_of(param.def_id)
853 .instantiate(tcx, preceding_args)
854 .skip_norm_wip();
855 if let Err(guar) = ty.error_reported() {
856 return ty::Const::new_error(tcx, guar).into();
857 }
858 if !infer_args && has_default {
859 tcx.const_param_default(param.def_id)
860 .instantiate(tcx, preceding_args)
861 .skip_norm_wip()
862 .into()
863 } else if infer_args {
864 self.lowerer.ct_infer(Some(param), self.span).into()
865 } else {
866 ty::Const::new_misc_error(tcx).into()
868 }
869 }
870 }
871 }
872 }
873
874 let mut args_ctx = GenericArgsCtxt {
875 lowerer: self,
876 def_id,
877 span,
878 generic_args: segment.args(),
879 infer_args: segment.infer_args,
880 create_synth_args: segment.delegation_child_segment,
881 incorrect_args: &arg_count.correct,
882 };
883
884 let args = lower_generic_args(
885 self,
886 def_id,
887 parent_args,
888 self_ty.is_some(),
889 self_ty,
890 &arg_count,
891 &mut args_ctx,
892 );
893
894 (args, arg_count)
895 }
896
897 {}
#[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_args_of_assoc_item",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(897u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_def_id")
}> =
::tracing::__macro_support::FieldName::new("item_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_segment")
}> =
::tracing::__macro_support::FieldName::new("item_segment");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("parent_args")
}> =
::tracing::__macro_support::FieldName::new("parent_args");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_segment)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&parent_args)
as &dyn ::tracing::field::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: GenericArgsRef<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let (args, _) =
self.lower_generic_args_of_path(span, item_def_id,
parent_args, item_segment, None);
if let Some(c) = item_segment.args().constraints.first() {
prohibit_assoc_item_constraint(self, c,
Some((item_def_id, item_segment, span)));
}
args
}
}
}#[instrument(level = "debug", skip(self))]
898 pub fn lower_generic_args_of_assoc_item(
899 &self,
900 span: Span,
901 item_def_id: DefId,
902 item_segment: &hir::PathSegment<'_>,
903 parent_args: GenericArgsRef<'tcx>,
904 ) -> GenericArgsRef<'tcx> {
905 let (args, _) =
906 self.lower_generic_args_of_path(span, item_def_id, parent_args, item_segment, None);
907 if let Some(c) = item_segment.args().constraints.first() {
908 prohibit_assoc_item_constraint(self, c, Some((item_def_id, item_segment, span)));
909 }
910 args
911 }
912
913 pub fn lower_impl_trait_ref(
917 &self,
918 trait_ref: &hir::TraitRef<'tcx>,
919 self_ty: Ty<'tcx>,
920 ) -> ty::TraitRef<'tcx> {
921 let [leading_segments @ .., segment] = trait_ref.path.segments else { bug_impl(None, format_args!("impossible case reached"), Location::caller())bug!() };
922
923 let _ = self.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
924
925 self.lower_mono_trait_ref(
926 trait_ref.path.span,
927 trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),
928 self_ty,
929 segment,
930 true,
931 )
932 }
933
934 {}
#[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_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(957u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bound_generic_params")
}> =
::tracing::__macro_support::FieldName::new("bound_generic_params");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("constness")
}> =
::tracing::__macro_support::FieldName::new("constness");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("polarity")
}> =
::tracing::__macro_support::FieldName::new("polarity");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("predicate_filter")
}> =
::tracing::__macro_support::FieldName::new("predicate_filter");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("overlapping_assoc_item_constraints")
}> =
::tracing::__macro_support::FieldName::new("overlapping_assoc_item_constraints");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_generic_params)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constness)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&polarity)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&predicate_filter)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&overlapping_assoc_item_constraints)
as &dyn ::tracing::field::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: GenericArgCountResult = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let _ = bound_generic_params;
let trait_def_id =
trait_ref.trait_def_id().unwrap_or_else(||
FatalError.raise());
let transient =
match polarity {
hir::BoundPolarity::Positive => {
tcx.is_lang_item(trait_def_id, LangItem::PointeeSized)
}
hir::BoundPolarity::Negative(_) => false,
hir::BoundPolarity::Maybe(_) => {
self.require_bound_to_relax_default_trait(trait_ref, span);
true
}
};
let bounds = if transient { &mut Vec::new() } else { bounds };
let polarity =
match polarity {
hir::BoundPolarity::Positive | hir::BoundPolarity::Maybe(_)
=> {
ty::ClausePolarity::Positive
}
hir::BoundPolarity::Negative(_) =>
ty::ClausePolarity::Negative,
};
let [leading_segments @ .., segment] =
trait_ref.path.segments else {
bug_impl(None, format_args!("impossible case reached"),
Location::caller())
};
let _ =
self.prohibit_generic_args(leading_segments.iter(),
GenericsArgsErrExtend::None);
self.report_internal_fn_trait(span, trait_def_id, segment, false);
let (generic_args, arg_count) =
self.lower_generic_args_of_path(trait_ref.path.span,
trait_def_id, &[], segment, Some(self_ty));
let constraints = segment.args().constraints;
if transient &&
(!generic_args[1..].is_empty() || !constraints.is_empty()) {
self.dcx().span_delayed_bug(span,
"transient bound should not have args or constraints");
}
let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1037",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1037u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bound_vars")
}> =
::tracing::__macro_support::FieldName::new("bound_vars");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_vars)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let poly_trait_ref =
ty::Binder::bind_with_vars(ty::TraitRef::new_from_args(tcx,
trait_def_id, generic_args), bound_vars);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1044",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1044u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("poly_trait_ref")
}> =
::tracing::__macro_support::FieldName::new("poly_trait_ref");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&poly_trait_ref)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
match predicate_filter {
PredicateFilter::All | PredicateFilter::SelfOnly |
PredicateFilter::SelfTraitThatDefines(..) |
PredicateFilter::SelfAndAssociatedTypeBounds => {
let bound =
poly_trait_ref.map_bound(|trait_ref|
{
ty::ClauseKind::Trait(ty::TraitClause {
trait_ref,
polarity,
})
});
let bound = (bound.upcast(tcx), span);
if tcx.is_lang_item(trait_def_id, LangItem::Sized) {
bounds.insert(0, bound);
} else { bounds.push(bound); }
}
PredicateFilter::ConstIfConst |
PredicateFilter::SelfConstIfConst => {}
}
if let hir::BoundConstness::Always(span) |
hir::BoundConstness::Maybe(span) = constness &&
!tcx.is_const_trait(trait_def_id) {
let (def_span, suggestion, suggestion_pre) =
match (trait_def_id.as_local(), tcx.sess.is_nightly_build())
{
(Some(trait_def_id), true) => {
let span = tcx.hir_expect_item(trait_def_id).vis_span;
let span =
tcx.sess.source_map().span_extend_while_whitespace(span);
(None, Some(span.shrink_to_hi()),
if self.tcx().features().const_trait_impl() {
""
} else {
"enable `#![feature(const_trait_impl)]` in your crate and "
})
}
(None, _) | (_, false) =>
(Some(tcx.def_span(trait_def_id)), None, ""),
};
self.dcx().emit_err(crate::diagnostics::ConstBoundForNonConstTrait {
span,
modifier: constness.as_str(),
def_span,
trait_name: tcx.def_path_str(trait_def_id),
suggestion,
suggestion_pre,
});
} else {
match predicate_filter {
PredicateFilter::SelfTraitThatDefines(..) => {}
PredicateFilter::All | PredicateFilter::SelfOnly |
PredicateFilter::SelfAndAssociatedTypeBounds => {
match constness {
hir::BoundConstness::Always(_) => {
if polarity == ty::ClausePolarity::Positive {
bounds.push((poly_trait_ref.to_host_effect_clause(tcx,
ty::BoundConstness::Const), span));
}
}
hir::BoundConstness::Maybe(_) => {}
hir::BoundConstness::Never => {}
}
}
PredicateFilter::ConstIfConst |
PredicateFilter::SelfConstIfConst => {
match constness {
hir::BoundConstness::Maybe(_) => {
if polarity == ty::ClausePolarity::Positive {
bounds.push((poly_trait_ref.to_host_effect_clause(tcx,
ty::BoundConstness::Maybe), span));
}
}
hir::BoundConstness::Always(_) | hir::BoundConstness::Never
=> {}
}
}
}
}
let mut dup_constraints =
(overlapping_assoc_item_constraints ==
OverlappingAsssocItemConstraints::Forbidden).then_some(FxIndexMap::default());
for constraint in constraints {
if polarity == ty::ClausePolarity::Negative {
self.dcx().span_delayed_bug(constraint.span,
"negative trait bounds should not have assoc item constraints");
break;
}
let _: Result<_, ErrorGuaranteed> =
self.lower_assoc_item_constraint(trait_ref.hir_ref_id,
poly_trait_ref, constraint, bounds,
dup_constraints.as_mut(), constraint.span,
predicate_filter);
}
arg_count
}
}
}#[instrument(level = "debug", skip(self, bounds))]
958 pub(crate) fn lower_poly_trait_ref(
959 &self,
960 &hir::PolyTraitRef {
961 bound_generic_params,
962 modifiers: hir::TraitBoundModifiers { constness, polarity },
963 trait_ref,
964 span,
965 }: &hir::PolyTraitRef<'_>,
966 self_ty: Ty<'tcx>,
967 bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
968 predicate_filter: PredicateFilter,
969 overlapping_assoc_item_constraints: OverlappingAsssocItemConstraints,
970 ) -> GenericArgCountResult {
971 let tcx = self.tcx();
972
973 let _ = bound_generic_params;
976
977 let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
978
979 let transient = match polarity {
984 hir::BoundPolarity::Positive => {
985 tcx.is_lang_item(trait_def_id, LangItem::PointeeSized)
991 }
992 hir::BoundPolarity::Negative(_) => false,
993 hir::BoundPolarity::Maybe(_) => {
994 self.require_bound_to_relax_default_trait(trait_ref, span);
995 true
996 }
997 };
998 let bounds = if transient { &mut Vec::new() } else { bounds };
999
1000 let polarity = match polarity {
1001 hir::BoundPolarity::Positive | hir::BoundPolarity::Maybe(_) => {
1002 ty::ClausePolarity::Positive
1003 }
1004 hir::BoundPolarity::Negative(_) => ty::ClausePolarity::Negative,
1005 };
1006
1007 let [leading_segments @ .., segment] = trait_ref.path.segments else { bug!() };
1008
1009 let _ = self.prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
1010 self.report_internal_fn_trait(span, trait_def_id, segment, false);
1011
1012 let (generic_args, arg_count) = self.lower_generic_args_of_path(
1013 trait_ref.path.span,
1014 trait_def_id,
1015 &[],
1016 segment,
1017 Some(self_ty),
1018 );
1019
1020 let constraints = segment.args().constraints;
1021
1022 if transient && (!generic_args[1..].is_empty() || !constraints.is_empty()) {
1023 self.dcx()
1033 .span_delayed_bug(span, "transient bound should not have args or constraints");
1034 }
1035
1036 let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
1037 debug!(?bound_vars);
1038
1039 let poly_trait_ref = ty::Binder::bind_with_vars(
1040 ty::TraitRef::new_from_args(tcx, trait_def_id, generic_args),
1041 bound_vars,
1042 );
1043
1044 debug!(?poly_trait_ref);
1045
1046 match predicate_filter {
1048 PredicateFilter::All
1049 | PredicateFilter::SelfOnly
1050 | PredicateFilter::SelfTraitThatDefines(..)
1051 | PredicateFilter::SelfAndAssociatedTypeBounds => {
1052 let bound = poly_trait_ref.map_bound(|trait_ref| {
1053 ty::ClauseKind::Trait(ty::TraitClause { trait_ref, polarity })
1054 });
1055 let bound = (bound.upcast(tcx), span);
1056 if tcx.is_lang_item(trait_def_id, LangItem::Sized) {
1062 bounds.insert(0, bound);
1063 } else {
1064 bounds.push(bound);
1065 }
1066 }
1067 PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
1068 }
1069
1070 if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
1071 && !tcx.is_const_trait(trait_def_id)
1072 {
1073 let (def_span, suggestion, suggestion_pre) =
1074 match (trait_def_id.as_local(), tcx.sess.is_nightly_build()) {
1075 (Some(trait_def_id), true) => {
1076 let span = tcx.hir_expect_item(trait_def_id).vis_span;
1077 let span = tcx.sess.source_map().span_extend_while_whitespace(span);
1078
1079 (
1080 None,
1081 Some(span.shrink_to_hi()),
1082 if self.tcx().features().const_trait_impl() {
1083 ""
1084 } else {
1085 "enable `#![feature(const_trait_impl)]` in your crate and "
1086 },
1087 )
1088 }
1089 (None, _) | (_, false) => (Some(tcx.def_span(trait_def_id)), None, ""),
1090 };
1091 self.dcx().emit_err(crate::diagnostics::ConstBoundForNonConstTrait {
1092 span,
1093 modifier: constness.as_str(),
1094 def_span,
1095 trait_name: tcx.def_path_str(trait_def_id),
1096 suggestion,
1097 suggestion_pre,
1098 });
1099 } else {
1100 match predicate_filter {
1101 PredicateFilter::SelfTraitThatDefines(..) => {}
1103 PredicateFilter::All
1104 | PredicateFilter::SelfOnly
1105 | PredicateFilter::SelfAndAssociatedTypeBounds => {
1106 match constness {
1107 hir::BoundConstness::Always(_) => {
1108 if polarity == ty::ClausePolarity::Positive {
1109 bounds.push((
1110 poly_trait_ref
1111 .to_host_effect_clause(tcx, ty::BoundConstness::Const),
1112 span,
1113 ));
1114 }
1115 }
1116 hir::BoundConstness::Maybe(_) => {
1117 }
1122 hir::BoundConstness::Never => {}
1123 }
1124 }
1125 PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {
1132 match constness {
1133 hir::BoundConstness::Maybe(_) => {
1134 if polarity == ty::ClausePolarity::Positive {
1135 bounds.push((
1136 poly_trait_ref
1137 .to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1138 span,
1139 ));
1140 }
1141 }
1142 hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}
1143 }
1144 }
1145 }
1146 }
1147
1148 let mut dup_constraints = (overlapping_assoc_item_constraints
1149 == OverlappingAsssocItemConstraints::Forbidden)
1150 .then_some(FxIndexMap::default());
1151
1152 for constraint in constraints {
1153 if polarity == ty::ClausePolarity::Negative {
1157 self.dcx().span_delayed_bug(
1158 constraint.span,
1159 "negative trait bounds should not have assoc item constraints",
1160 );
1161 break;
1162 }
1163
1164 let _: Result<_, ErrorGuaranteed> = self.lower_assoc_item_constraint(
1166 trait_ref.hir_ref_id,
1167 poly_trait_ref,
1168 constraint,
1169 bounds,
1170 dup_constraints.as_mut(),
1171 constraint.span,
1172 predicate_filter,
1173 );
1174 }
1176
1177 arg_count
1178 }
1179
1180 fn lower_mono_trait_ref(
1184 &self,
1185 span: Span,
1186 trait_def_id: DefId,
1187 self_ty: Ty<'tcx>,
1188 trait_segment: &hir::PathSegment<'_>,
1189 is_impl: bool,
1190 ) -> ty::TraitRef<'tcx> {
1191 self.report_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
1192
1193 let (generic_args, _) =
1194 self.lower_generic_args_of_path(span, trait_def_id, &[], trait_segment, Some(self_ty));
1195 if let Some(c) = trait_segment.args().constraints.first() {
1196 prohibit_assoc_item_constraint(self, c, Some((trait_def_id, trait_segment, span)));
1197 }
1198 ty::TraitRef::new_from_args(self.tcx(), trait_def_id, generic_args)
1199 }
1200
1201 fn probe_trait_that_defines_assoc_item(
1202 &self,
1203 trait_def_id: DefId,
1204 assoc_tag: ty::AssocTag,
1205 assoc_ident: Ident,
1206 ) -> bool {
1207 self.tcx()
1208 .associated_items(trait_def_id)
1209 .find_by_ident_and_kind(self.tcx(), assoc_ident, assoc_tag, trait_def_id)
1210 .is_some()
1211 }
1212
1213 fn lower_path_segment(
1214 &self,
1215 span: Span,
1216 def_id: DefId,
1217 item_segment: &hir::PathSegment<'_>,
1218 ) -> Ty<'tcx> {
1219 let tcx = self.tcx();
1220 let args = self.lower_generic_args_of_path_segment(span, def_id, item_segment);
1221
1222 if let DefKind::TyAlias = tcx.def_kind(def_id)
1223 && tcx.type_alias_is_checked(def_id)
1224 {
1225 let alias_ty = ty::AliasTy::new_from_args(tcx, ty::Free { def_id }, args);
1229 Ty::new_alias(tcx, ty::IsRigid::No, alias_ty)
1230 } else {
1231 tcx.at(span).type_of(def_id).instantiate(tcx, args).skip_norm_wip()
1232 }
1233 }
1234
1235 {}
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("probe_single_ty_param_bound_for_assoc_item",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1242u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> = 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 /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1251",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1251u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty_param_def_id")
}> =
::tracing::__macro_support::FieldName::new("ty_param_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("assoc_ident")
}> =
::tracing::__macro_support::FieldName::new("assoc_ident");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty_param_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_ident)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let tcx = self.tcx();
let predicates =
&self.probe_ty_param_bounds(span, ty_param_def_id,
assoc_ident);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1255",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1255u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("predicates={0:#?}",
predicates) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.probe_single_bound_for_assoc_item(||
{
let trait_refs =
predicates.iter_identity_copied().map(Unnormalized::skip_norm_wip).filter_map(|(p,
_)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref)));
traits::transitive_bounds_that_define_assoc_item(tcx,
trait_refs, assoc_ident)
}, AssocItemQSelf::TyParam(ty_param_def_id, ty_param_span),
assoc_tag, assoc_ident, span, None)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1242",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1242u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1243 fn probe_single_ty_param_bound_for_assoc_item(
1244 &self,
1245 ty_param_def_id: LocalDefId,
1246 ty_param_span: Span,
1247 assoc_tag: ty::AssocTag,
1248 assoc_ident: Ident,
1249 span: Span,
1250 ) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> {
1251 debug!(?ty_param_def_id, ?assoc_ident, ?span);
1252 let tcx = self.tcx();
1253
1254 let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_ident);
1255 debug!("predicates={:#?}", predicates);
1256
1257 self.probe_single_bound_for_assoc_item(
1258 || {
1259 let trait_refs = predicates
1260 .iter_identity_copied()
1261 .map(Unnormalized::skip_norm_wip)
1262 .filter_map(|(p, _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref)));
1263 traits::transitive_bounds_that_define_assoc_item(tcx, trait_refs, assoc_ident)
1264 },
1265 AssocItemQSelf::TyParam(ty_param_def_id, ty_param_span),
1266 assoc_tag,
1267 assoc_ident,
1268 span,
1269 None,
1270 )
1271 }
1272
1273 fn collapse_candidates_to_subtrait_pick(
1283 &self,
1284 matching_candidates: &[ty::PolyTraitRef<'tcx>],
1285 ) -> Option<ty::PolyTraitRef<'tcx>> {
1286 if !self.tcx().features().supertrait_item_shadowing() {
1287 return None;
1288 }
1289
1290 let mut child_trait = matching_candidates[0];
1291 let mut supertraits: SsoHashSet<_> =
1292 traits::supertrait_def_ids(self.tcx(), child_trait.def_id()).collect();
1293
1294 let mut remaining_candidates: Vec<_> = matching_candidates[1..].iter().copied().collect();
1295 while !remaining_candidates.is_empty() {
1296 let mut made_progress = false;
1297 let mut next_round = ::alloc::vec::Vec::new()vec![];
1298
1299 for remaining_trait in remaining_candidates {
1300 if supertraits.contains(&remaining_trait.def_id()) {
1301 made_progress = true;
1302 continue;
1303 }
1304
1305 let remaining_trait_supertraits: SsoHashSet<_> =
1311 traits::supertrait_def_ids(self.tcx(), remaining_trait.def_id()).collect();
1312 if remaining_trait_supertraits.contains(&child_trait.def_id()) {
1313 child_trait = remaining_trait;
1314 supertraits = remaining_trait_supertraits;
1315 made_progress = true;
1316 continue;
1317 }
1318
1319 next_round.push(remaining_trait);
1326 }
1327
1328 if made_progress {
1329 remaining_candidates = next_round;
1331 } else {
1332 return None;
1335 }
1336 }
1337
1338 Some(child_trait)
1339 }
1340
1341 {}
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("probe_single_bound_for_assoc_item",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1346u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("assoc_tag")
}> =
::tracing::__macro_support::FieldName::new("assoc_tag");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("assoc_ident")
}> =
::tracing::__macro_support::FieldName::new("assoc_ident");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_tag)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&assoc_ident)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed> = loop {};
return __tracing_attr_fake_return;
}
{
let mut matching_candidates =
all_candidates().filter(|r|
{
self.probe_trait_that_defines_assoc_item(r.def_id(),
assoc_tag, assoc_ident)
});
let Some(bound1) =
matching_candidates.next() else {
return Err(self.report_unresolved_assoc_item(all_candidates,
qself, assoc_tag, assoc_ident, span, constraint));
};
if let Some(bound2) = matching_candidates.next() {
let all_matching_candidates: Vec<_> =
[bound1,
bound2].into_iter().chain(matching_candidates).collect();
if let Some(bound) =
self.collapse_candidates_to_subtrait_pick(&all_matching_candidates)
{
return Ok(bound);
}
return Err(self.report_ambiguous_assoc_item(&all_matching_candidates,
qself, assoc_tag, assoc_ident, span, constraint));
}
Ok(bound1)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1346",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1346u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self, all_candidates, qself, constraint), ret)]
1347 fn probe_single_bound_for_assoc_item<I>(
1348 &self,
1349 all_candidates: impl Fn() -> I,
1350 qself: AssocItemQSelf,
1351 assoc_tag: ty::AssocTag,
1352 assoc_ident: Ident,
1353 span: Span,
1354 constraint: Option<&hir::AssocItemConstraint<'_>>,
1355 ) -> Result<ty::PolyTraitRef<'tcx>, ErrorGuaranteed>
1356 where
1357 I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
1358 {
1359 let mut matching_candidates = all_candidates().filter(|r| {
1360 self.probe_trait_that_defines_assoc_item(r.def_id(), assoc_tag, assoc_ident)
1361 });
1362
1363 let Some(bound1) = matching_candidates.next() else {
1364 return Err(self.report_unresolved_assoc_item(
1365 all_candidates,
1366 qself,
1367 assoc_tag,
1368 assoc_ident,
1369 span,
1370 constraint,
1371 ));
1372 };
1373
1374 if let Some(bound2) = matching_candidates.next() {
1375 let all_matching_candidates: Vec<_> =
1376 [bound1, bound2].into_iter().chain(matching_candidates).collect();
1377 if let Some(bound) = self.collapse_candidates_to_subtrait_pick(&all_matching_candidates)
1378 {
1379 return Ok(bound);
1380 }
1381
1382 return Err(self.report_ambiguous_assoc_item(
1383 &all_matching_candidates,
1384 qself,
1385 assoc_tag,
1386 assoc_ident,
1387 span,
1388 constraint,
1389 ));
1390 }
1391
1392 Ok(bound1)
1393 }
1394
1395 {}
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_type_relative_ty_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1421u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
match self.lower_type_relative_path(self_ty, hir_self_ty,
segment, qpath_hir_id, span,
LowerTypeRelativePathMode::Type(permit_variants))? {
TypeRelativePath::AssocItem(alias_term) => {
let alias_ty = alias_term.expect_ty();
let def_id =
match alias_ty.kind {
ty::AliasTyKind::Projection { def_id } => def_id,
ty::AliasTyKind::Inherent { def_id } => def_id,
kind =>
bug_impl(None,
format_args!("expected projection or inherent alias, got {0:?}",
kind), Location::caller()),
};
let ty = alias_ty.to_ty(tcx, ty::IsRigid::No);
let ty = self.check_param_uses_if_mcg(ty, span, false);
Ok((ty, tcx.def_kind(def_id), def_id))
}
TypeRelativePath::Variant { adt, variant_did } => {
let adt = self.check_param_uses_if_mcg(adt, span, false);
Ok((adt, DefKind::Variant, variant_did))
}
TypeRelativePath::Ctor { .. } => {
let e =
tcx.dcx().span_err(span,
"expected type, found tuple constructor");
Err(e)
}
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1421",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1421u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1422 pub fn lower_type_relative_ty_path(
1423 &self,
1424 self_ty: Ty<'tcx>,
1425 hir_self_ty: &hir::Ty<'_>,
1426 segment: &hir::PathSegment<'_>,
1427 qpath_hir_id: HirId,
1428 span: Span,
1429 permit_variants: PermitVariants,
1430 ) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> {
1431 let tcx = self.tcx();
1432 match self.lower_type_relative_path(
1433 self_ty,
1434 hir_self_ty,
1435 segment,
1436 qpath_hir_id,
1437 span,
1438 LowerTypeRelativePathMode::Type(permit_variants),
1439 )? {
1440 TypeRelativePath::AssocItem(alias_term) => {
1441 let alias_ty = alias_term.expect_ty();
1442 let def_id = match alias_ty.kind {
1443 ty::AliasTyKind::Projection { def_id } => def_id,
1444 ty::AliasTyKind::Inherent { def_id } => def_id,
1445 kind => bug!("expected projection or inherent alias, got {kind:?}"),
1446 };
1447 let ty = alias_ty.to_ty(tcx, ty::IsRigid::No);
1448 let ty = self.check_param_uses_if_mcg(ty, span, false);
1449 Ok((ty, tcx.def_kind(def_id), def_id))
1450 }
1451 TypeRelativePath::Variant { adt, variant_did } => {
1452 let adt = self.check_param_uses_if_mcg(adt, span, false);
1453 Ok((adt, DefKind::Variant, variant_did))
1454 }
1455 TypeRelativePath::Ctor { .. } => {
1456 let e = tcx.dcx().span_err(span, "expected type, found tuple constructor");
1457 Err(e)
1458 }
1459 }
1460 }
1461
1462 {}
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_type_relative_const_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1463u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Result<Const<'tcx>, ErrorGuaranteed> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
match self.lower_type_relative_path(self_ty, hir_self_ty,
segment, qpath_hir_id, span,
LowerTypeRelativePathMode::Const)? {
TypeRelativePath::AssocItem(alias_term) => {
let alias_ct = alias_term.expect_ct();
if let Some(def_id) = alias_ct.kind.opt_def_id() {
self.check_const_item_in_type_system(def_id, span)?;
}
let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct);
let ct = self.check_param_uses_if_mcg(ct, span, false);
Ok(ct)
}
TypeRelativePath::Ctor { ctor_def_id, args } =>
match tcx.def_kind(ctor_def_id) {
DefKind::Ctor(_, CtorKind::Fn) =>
Ok(ty::Const::zero_sized(tcx,
tcx.type_of(ctor_def_id).instantiate(tcx,
args).skip_norm_wip())),
DefKind::Ctor(ctor_of, CtorKind::Const) => {
Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of,
args))
}
_ =>
::core::panicking::panic("internal error: entered unreachable code"),
},
TypeRelativePath::Variant { .. } => {
bug_impl(Some(span),
format_args!("unexpected variant res for type associated const path"),
Location::caller())
}
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1463",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1463u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1464 fn lower_type_relative_const_path(
1465 &self,
1466 self_ty: Ty<'tcx>,
1467 hir_self_ty: &hir::Ty<'_>,
1468 segment: &hir::PathSegment<'_>,
1469 qpath_hir_id: HirId,
1470 span: Span,
1471 ) -> Result<Const<'tcx>, ErrorGuaranteed> {
1472 let tcx = self.tcx();
1473 match self.lower_type_relative_path(
1474 self_ty,
1475 hir_self_ty,
1476 segment,
1477 qpath_hir_id,
1478 span,
1479 LowerTypeRelativePathMode::Const,
1480 )? {
1481 TypeRelativePath::AssocItem(alias_term) => {
1482 let alias_ct = alias_term.expect_ct();
1483 if let Some(def_id) = alias_ct.kind.opt_def_id() {
1484 self.check_const_item_in_type_system(def_id, span)?;
1485 }
1486 let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct);
1487 let ct = self.check_param_uses_if_mcg(ct, span, false);
1488 Ok(ct)
1489 }
1490 TypeRelativePath::Ctor { ctor_def_id, args } => match tcx.def_kind(ctor_def_id) {
1491 DefKind::Ctor(_, CtorKind::Fn) => Ok(ty::Const::zero_sized(
1492 tcx,
1493 tcx.type_of(ctor_def_id).instantiate(tcx, args).skip_norm_wip(),
1494 )),
1495 DefKind::Ctor(ctor_of, CtorKind::Const) => {
1496 Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of, args))
1497 }
1498 _ => unreachable!(),
1499 },
1500 TypeRelativePath::Variant { .. } => {
1503 span_bug!(span, "unexpected variant res for type associated const path")
1504 }
1505 }
1506 }
1507
1508 {}
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_type_relative_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1509u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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:
Result<TypeRelativePath<'tcx>, ErrorGuaranteed> = 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 /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1519",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1519u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("segment.ident")
}> =
::tracing::__macro_support::FieldName::new("segment.ident");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment.ident)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let tcx = self.tcx();
let mut variant_def_id = None;
if let Some(adt_def) = self.probe_adt(span, self_ty) {
if adt_def.is_enum() {
let variant_def =
adt_def.variants().iter().find(|vd|
tcx.hygienic_eq(segment.ident, vd.ident(tcx),
adt_def.did()));
if let Some(variant_def) = variant_def {
if #[allow(non_exhaustive_omitted_patterns)] match mode {
LowerTypeRelativePathMode::Const => true,
_ => false,
} && let Some((_, ctor_def_id)) = variant_def.ctor {
tcx.check_stability(variant_def.def_id, Some(qpath_hir_id),
span, None);
let _ =
self.prohibit_generic_args(slice::from_ref(segment).iter(),
GenericsArgsErrExtend::EnumVariant {
qself: hir_self_ty,
assoc_segment: segment,
adt_def,
});
let ty::Adt(_, enum_args) =
self_ty.kind() else {
::core::panicking::panic("internal error: entered unreachable code")
};
return Ok(TypeRelativePath::Ctor {
ctor_def_id,
args: enum_args,
});
}
if let PermitVariants::Yes = mode.permit_variants() {
tcx.check_stability(variant_def.def_id, Some(qpath_hir_id),
span, None);
let _ =
self.prohibit_generic_args(slice::from_ref(segment).iter(),
GenericsArgsErrExtend::EnumVariant {
qself: hir_self_ty,
assoc_segment: segment,
adt_def,
});
return Ok(TypeRelativePath::Variant {
adt: self_ty,
variant_did: variant_def.def_id,
});
} else { variant_def_id = Some(variant_def.def_id); }
}
}
if let Some(alias_term) =
self.probe_inherent_assoc_item(segment, adt_def.did(),
self_ty, qpath_hir_id, span, mode.assoc_tag())? {
return Ok(TypeRelativePath::AssocItem(alias_term));
}
}
let (item_def_id, bound) =
self.resolve_type_relative_path(self_ty, hir_self_ty,
mode.assoc_tag(), segment, qpath_hir_id, span,
variant_def_id)?;
let (item_def_id, args) =
self.lower_assoc_item_path(span, item_def_id, segment,
bound)?;
if let Some(variant_def_id) = variant_def_id {
tcx.emit_node_span_lint(AMBIGUOUS_ASSOCIATED_ITEMS,
qpath_hir_id, span,
errors::AmbiguityBetweenVariantAndAssocItem {
variant_def_id,
item_def_id,
span,
segment_ident: segment.ident,
bound_def_id: bound.def_id(),
self_ty,
tcx,
mode,
});
}
Ok(TypeRelativePath::AssocItem(ty::AliasTerm::new_from_def_id(tcx,
item_def_id, args,
ty::AliasConstInherentArgsKind::WithSelf)))
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1509",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1509u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip_all, ret)]
1510 fn lower_type_relative_path(
1511 &self,
1512 self_ty: Ty<'tcx>,
1513 hir_self_ty: &hir::Ty<'_>,
1514 segment: &hir::PathSegment<'_>,
1515 qpath_hir_id: HirId,
1516 span: Span,
1517 mode: LowerTypeRelativePathMode,
1518 ) -> Result<TypeRelativePath<'tcx>, ErrorGuaranteed> {
1519 debug!(%self_ty, ?segment.ident);
1520 let tcx = self.tcx();
1521
1522 let mut variant_def_id = None;
1524 if let Some(adt_def) = self.probe_adt(span, self_ty) {
1525 if adt_def.is_enum() {
1526 let variant_def = adt_def
1527 .variants()
1528 .iter()
1529 .find(|vd| tcx.hygienic_eq(segment.ident, vd.ident(tcx), adt_def.did()));
1530 if let Some(variant_def) = variant_def {
1531 if matches!(mode, LowerTypeRelativePathMode::Const)
1534 && let Some((_, ctor_def_id)) = variant_def.ctor
1535 {
1536 tcx.check_stability(variant_def.def_id, Some(qpath_hir_id), span, None);
1537 let _ = self.prohibit_generic_args(
1538 slice::from_ref(segment).iter(),
1539 GenericsArgsErrExtend::EnumVariant {
1540 qself: hir_self_ty,
1541 assoc_segment: segment,
1542 adt_def,
1543 },
1544 );
1545 let ty::Adt(_, enum_args) = self_ty.kind() else { unreachable!() };
1546 return Ok(TypeRelativePath::Ctor { ctor_def_id, args: enum_args });
1547 }
1548 if let PermitVariants::Yes = mode.permit_variants() {
1549 tcx.check_stability(variant_def.def_id, Some(qpath_hir_id), span, None);
1550 let _ = self.prohibit_generic_args(
1551 slice::from_ref(segment).iter(),
1552 GenericsArgsErrExtend::EnumVariant {
1553 qself: hir_self_ty,
1554 assoc_segment: segment,
1555 adt_def,
1556 },
1557 );
1558 return Ok(TypeRelativePath::Variant {
1559 adt: self_ty,
1560 variant_did: variant_def.def_id,
1561 });
1562 } else {
1563 variant_def_id = Some(variant_def.def_id);
1564 }
1565 }
1566 }
1567
1568 if let Some(alias_term) = self.probe_inherent_assoc_item(
1570 segment,
1571 adt_def.did(),
1572 self_ty,
1573 qpath_hir_id,
1574 span,
1575 mode.assoc_tag(),
1576 )? {
1577 return Ok(TypeRelativePath::AssocItem(alias_term));
1578 }
1579 }
1580
1581 let (item_def_id, bound) = self.resolve_type_relative_path(
1582 self_ty,
1583 hir_self_ty,
1584 mode.assoc_tag(),
1585 segment,
1586 qpath_hir_id,
1587 span,
1588 variant_def_id,
1589 )?;
1590
1591 let (item_def_id, args) = self.lower_assoc_item_path(span, item_def_id, segment, bound)?;
1592
1593 if let Some(variant_def_id) = variant_def_id {
1594 tcx.emit_node_span_lint(
1595 AMBIGUOUS_ASSOCIATED_ITEMS,
1596 qpath_hir_id,
1597 span,
1598 errors::AmbiguityBetweenVariantAndAssocItem {
1599 variant_def_id,
1600 item_def_id,
1601 span,
1602 segment_ident: segment.ident,
1603 bound_def_id: bound.def_id(),
1604 self_ty,
1605 tcx,
1606 mode,
1607 },
1608 );
1609 }
1610
1611 Ok(TypeRelativePath::AssocItem(ty::AliasTerm::new_from_def_id(
1612 tcx,
1613 item_def_id,
1614 args,
1615 ty::AliasConstInherentArgsKind::WithSelf,
1616 )))
1617 }
1618
1619 fn resolve_type_relative_path(
1621 &self,
1622 self_ty: Ty<'tcx>,
1623 hir_self_ty: &hir::Ty<'_>,
1624 assoc_tag: ty::AssocTag,
1625 segment: &hir::PathSegment<'_>,
1626 qpath_hir_id: HirId,
1627 span: Span,
1628 variant_def_id: Option<DefId>,
1629 ) -> Result<(DefId, ty::PolyTraitRef<'tcx>), ErrorGuaranteed> {
1630 let tcx = self.tcx();
1631
1632 let self_ty_res = match hir_self_ty.kind {
1633 hir::TyKind::Path(hir::QPath::Resolved(_, path)) => path.res,
1634 _ => Res::Err,
1635 };
1636
1637 let bound = match (self_ty.kind(), self_ty_res) {
1639 (_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => {
1640 let trait_ref = tcx.impl_trait_ref(impl_def_id);
1643
1644 self.probe_single_bound_for_assoc_item(
1645 || {
1646 let trait_ref =
1647 ty::Binder::dummy(trait_ref.instantiate_identity().skip_norm_wip());
1648 traits::supertraits(tcx, trait_ref)
1649 },
1650 AssocItemQSelf::SelfTyAlias,
1651 assoc_tag,
1652 segment.ident,
1653 span,
1654 None,
1655 )?
1656 }
1657 (
1658 &ty::Param(_),
1659 Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did),
1660 ) => self.probe_single_ty_param_bound_for_assoc_item(
1661 param_did.expect_local(),
1662 hir_self_ty.span,
1663 assoc_tag,
1664 segment.ident,
1665 span,
1666 )?,
1667 _ => {
1668 return Err(self.report_unresolved_type_relative_path(
1669 self_ty,
1670 hir_self_ty,
1671 assoc_tag,
1672 segment.ident,
1673 qpath_hir_id,
1674 span,
1675 variant_def_id,
1676 ));
1677 }
1678 };
1679
1680 let assoc_item = self
1681 .probe_assoc_item(segment.ident, assoc_tag, qpath_hir_id, span, bound.def_id())
1682 .expect("failed to find associated item");
1683
1684 Ok((assoc_item.def_id, bound))
1685 }
1686
1687 fn probe_inherent_assoc_item(
1689 &self,
1690 segment: &hir::PathSegment<'_>,
1691 adt_did: DefId,
1692 self_ty: Ty<'tcx>,
1693 block: HirId,
1694 span: Span,
1695 assoc_tag: ty::AssocTag,
1696 ) -> Result<Option<ty::AliasTerm<'tcx>>, ErrorGuaranteed> {
1697 let tcx = self.tcx();
1698
1699 if !tcx.features().inherent_associated_types() {
1700 match assoc_tag {
1701 ty::AssocTag::Type => return Ok(None),
1706 ty::AssocTag::Const => {
1707 return Err(feature_err(
1711 &tcx.sess,
1712 sym::inherent_associated_types,
1713 span,
1714 "inherent associated types are unstable",
1715 )
1716 .emit());
1717 }
1718 ty::AssocTag::Fn => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1719 }
1720 }
1721
1722 let name = segment.ident;
1723 let candidates: Vec<_> = tcx
1724 .inherent_impls(adt_did)
1725 .iter()
1726 .filter_map(|&impl_| {
1727 let (item, scope) = self.probe_assoc_item_unchecked(name, assoc_tag, impl_)?;
1728 Some(InherentAssocCandidate { impl_, assoc_item: item.def_id, scope })
1729 })
1730 .collect();
1731
1732 if candidates.is_empty() {
1737 return Ok(None);
1738 }
1739
1740 let (applicable_candidates, fulfillment_errors) =
1741 self.select_inherent_assoc_candidates(span, self_ty, candidates.clone());
1742
1743 let InherentAssocCandidate { impl_, assoc_item, scope: def_scope } =
1745 match &applicable_candidates[..] {
1746 &[] => Err(self.report_unresolved_inherent_assoc_item(
1747 name,
1748 self_ty,
1749 candidates,
1750 fulfillment_errors,
1751 span,
1752 assoc_tag,
1753 )),
1754
1755 &[applicable_candidate] => Ok(applicable_candidate),
1756
1757 &[_, ..] => Err(self.report_ambiguous_inherent_assoc_item(
1758 name,
1759 candidates.into_iter().map(|cand| cand.assoc_item).collect(),
1760 span,
1761 )),
1762 }?;
1763
1764 self.check_assoc_item(assoc_item, name, def_scope, block, span);
1767
1768 let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_);
1772 let args = self.lower_generic_args_of_assoc_item(span, assoc_item, segment, parent_args);
1773 let args = tcx.mk_args_from_iter(
1774 std::iter::once(ty::GenericArg::from(self_ty))
1775 .chain(args.into_iter().skip(parent_args.len())),
1776 );
1777
1778 let kind = match assoc_tag {
1779 ty::AssocTag::Type => ty::AliasTermKind::InherentTy { def_id: assoc_item },
1780 ty::AssocTag::Const => ty::AliasTermKind::InherentConstSelf { def_id: assoc_item },
1781 ty::AssocTag::Fn => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1782 };
1783
1784 Ok(Some(ty::AliasTerm::new_from_args(tcx, kind, args)))
1785 }
1786
1787 fn probe_assoc_item(
1791 &self,
1792 ident: Ident,
1793 assoc_tag: ty::AssocTag,
1794 block: HirId,
1795 span: Span,
1796 scope: DefId,
1797 ) -> Option<ty::AssocItem> {
1798 let (item, scope) = self.probe_assoc_item_unchecked(ident, assoc_tag, scope)?;
1799 self.check_assoc_item(item.def_id, ident, scope, block, span);
1800 Some(item)
1801 }
1802
1803 fn probe_assoc_item_unchecked(
1808 &self,
1809 ident: Ident,
1810 assoc_tag: ty::AssocTag,
1811 scope: DefId,
1812 ) -> Option<(ty::AssocItem, ModId)> {
1813 let tcx = self.tcx();
1814
1815 let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, self.item_def_id());
1816 let item = tcx
1820 .associated_items(scope)
1821 .filter_by_name_unhygienic(ident.name)
1822 .find(|i| i.tag() == assoc_tag && i.ident(tcx).normalize_to_macros_2_0() == ident)?;
1823
1824 Some((*item, def_scope))
1825 }
1826
1827 fn check_assoc_item(
1829 &self,
1830 item_def_id: DefId,
1831 ident: Ident,
1832 scope: ModId,
1833 block: HirId,
1834 span: Span,
1835 ) {
1836 let tcx = self.tcx();
1837
1838 if !tcx.visibility(item_def_id).is_accessible_from(scope, tcx) {
1839 self.dcx().emit_err(crate::diagnostics::AssocItemIsPrivate {
1840 span,
1841 kind: tcx.def_descr(item_def_id),
1842 name: ident,
1843 defined_here_label: tcx.def_span(item_def_id),
1844 });
1845 }
1846
1847 tcx.check_stability(item_def_id, Some(block), span, None);
1848 }
1849
1850 fn probe_traits_that_match_assoc_ty(
1851 &self,
1852 qself_ty: Ty<'tcx>,
1853 assoc_ident: Ident,
1854 ) -> Vec<String> {
1855 let tcx = self.tcx();
1856
1857 let infcx_;
1860 let infcx = if let Some(infcx) = self.infcx() {
1861 infcx
1862 } else {
1863 if !!qself_ty.has_infer() {
::core::panicking::panic("assertion failed: !qself_ty.has_infer()")
};assert!(!qself_ty.has_infer());
1864 infcx_ = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
1865 &infcx_
1866 };
1867
1868 tcx.all_traits_including_private()
1869 .filter(|trait_def_id| {
1870 tcx.associated_items(*trait_def_id)
1872 .in_definition_order()
1873 .any(|i| {
1874 i.is_type()
1875 && !i.is_impl_trait_in_trait()
1876 && i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
1877 })
1878 && tcx.visibility(*trait_def_id)
1880 .is_accessible_from(self.item_def_id(), tcx)
1881 && tcx.all_impls(*trait_def_id)
1882 .any(|impl_def_id| {
1883 let header = tcx.impl_trait_header(impl_def_id);
1884 let trait_ref = header.trait_ref.instantiate(tcx, infcx.fresh_args_for_item(DUMMY_SP, impl_def_id)).skip_norm_wip();
1885
1886 let value = fold_regions(tcx, qself_ty, |_, _| tcx.lifetimes.re_erased);
1887 if value.has_escaping_bound_vars() {
1889 return false;
1890 }
1891 infcx
1892 .can_eq(
1893 ty::ParamEnv::empty(),
1894 trait_ref.self_ty(),
1895 value,
1896 ) && header.polarity != ty::ImplPolarity::Negative
1897 })
1898 })
1899 .map(|trait_def_id| tcx.def_path_str(trait_def_id))
1900 .collect()
1901 }
1902
1903 {}
#[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_resolved_assoc_ty_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1904u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} 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: Ty<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
match self.lower_resolved_assoc_item_path(span, opt_self_ty,
item_def_id, trait_segment, item_segment,
ty::AssocTag::Type) {
Ok((item_def_id, item_args)) => {
Ty::new_projection_from_args(self.tcx(), ty::IsRigid::No,
item_def_id, item_args)
}
Err(guar) => Ty::new_error(self.tcx(), guar),
}
}
}
}#[instrument(level = "debug", skip_all)]
1905 fn lower_resolved_assoc_ty_path(
1906 &self,
1907 span: Span,
1908 opt_self_ty: Option<Ty<'tcx>>,
1909 item_def_id: DefId,
1910 trait_segment: Option<&hir::PathSegment<'_>>,
1911 item_segment: &hir::PathSegment<'_>,
1912 ) -> Ty<'tcx> {
1913 match self.lower_resolved_assoc_item_path(
1914 span,
1915 opt_self_ty,
1916 item_def_id,
1917 trait_segment,
1918 item_segment,
1919 ty::AssocTag::Type,
1920 ) {
1921 Ok((item_def_id, item_args)) => {
1922 Ty::new_projection_from_args(self.tcx(), ty::IsRigid::No, item_def_id, item_args)
1923 }
1924 Err(guar) => Ty::new_error(self.tcx(), guar),
1925 }
1926 }
1927
1928 {}
#[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_resolved_assoc_const_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1929u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} 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:
Result<Const<'tcx>, ErrorGuaranteed> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let (item_def_id, item_args) =
self.lower_resolved_assoc_item_path(span, opt_self_ty,
item_def_id, trait_segment, item_segment,
ty::AssocTag::Const)?;
self.check_const_item_in_type_system(item_def_id, span)?;
let alias_const =
ty::AliasConst::new(tcx,
ty::AliasConstKind::new_from_def_id(tcx, item_def_id,
ty::AliasConstInherentArgsKind::WithSelf), item_args);
Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const))
}
}
}#[instrument(level = "debug", skip_all)]
1930 fn lower_resolved_assoc_const_path(
1931 &self,
1932 span: Span,
1933 opt_self_ty: Option<Ty<'tcx>>,
1934 item_def_id: DefId,
1935 trait_segment: Option<&hir::PathSegment<'_>>,
1936 item_segment: &hir::PathSegment<'_>,
1937 ) -> Result<Const<'tcx>, ErrorGuaranteed> {
1938 let tcx = self.tcx();
1939 let (item_def_id, item_args) = self.lower_resolved_assoc_item_path(
1940 span,
1941 opt_self_ty,
1942 item_def_id,
1943 trait_segment,
1944 item_segment,
1945 ty::AssocTag::Const,
1946 )?;
1947 self.check_const_item_in_type_system(item_def_id, span)?;
1948 let alias_const = ty::AliasConst::new(
1949 tcx,
1950 ty::AliasConstKind::new_from_def_id(
1951 tcx,
1952 item_def_id,
1953 ty::AliasConstInherentArgsKind::WithSelf,
1954 ),
1955 item_args,
1956 );
1957 Ok(Const::new_alias(tcx, ty::IsRigid::No, alias_const))
1958 }
1959
1960 {}
#[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_resolved_assoc_item_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1961u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} 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:
Result<(DefId, GenericArgsRef<'tcx>), ErrorGuaranteed> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let trait_def_id = tcx.parent(item_def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1974",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1974u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_def_id")
}> =
::tracing::__macro_support::FieldName::new("trait_def_id");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_def_id)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let Some(self_ty) =
opt_self_ty else {
return Err(self.report_missing_self_ty_for_resolved_path(trait_def_id,
span, item_segment, assoc_tag));
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1984",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1984u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let trait_ref =
self.lower_mono_trait_ref(span, trait_def_id, self_ty,
trait_segment.unwrap(), false);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:1988",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(1988u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_ref")
}> =
::tracing::__macro_support::FieldName::new("trait_ref");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let item_args =
self.lower_generic_args_of_assoc_item(span, item_def_id,
item_segment, trait_ref.args);
Ok((item_def_id, item_args))
}
}
}#[instrument(level = "debug", skip_all)]
1962 fn lower_resolved_assoc_item_path(
1963 &self,
1964 span: Span,
1965 opt_self_ty: Option<Ty<'tcx>>,
1966 item_def_id: DefId,
1967 trait_segment: Option<&hir::PathSegment<'_>>,
1968 item_segment: &hir::PathSegment<'_>,
1969 assoc_tag: ty::AssocTag,
1970 ) -> Result<(DefId, GenericArgsRef<'tcx>), ErrorGuaranteed> {
1971 let tcx = self.tcx();
1972
1973 let trait_def_id = tcx.parent(item_def_id);
1974 debug!(?trait_def_id);
1975
1976 let Some(self_ty) = opt_self_ty else {
1977 return Err(self.report_missing_self_ty_for_resolved_path(
1978 trait_def_id,
1979 span,
1980 item_segment,
1981 assoc_tag,
1982 ));
1983 };
1984 debug!(?self_ty);
1985
1986 let trait_ref =
1987 self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment.unwrap(), false);
1988 debug!(?trait_ref);
1989
1990 let item_args =
1991 self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args);
1992
1993 Ok((item_def_id, item_args))
1994 }
1995
1996 pub fn prohibit_generic_args<'a>(
1997 &self,
1998 segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone,
1999 err_extend: GenericsArgsErrExtend<'a>,
2000 ) -> Result<(), ErrorGuaranteed> {
2001 let args_visitors = segments.clone().flat_map(|segment| segment.args().args);
2002 let mut result = Ok(());
2003 if let Some(_) = args_visitors.clone().next() {
2004 result = Err(self.report_prohibited_generic_args(
2005 segments.clone(),
2006 args_visitors,
2007 err_extend,
2008 ));
2009 }
2010
2011 for segment in segments {
2012 if let Some(c) = segment.args().constraints.first() {
2014 return Err(prohibit_assoc_item_constraint(self, c, None));
2015 }
2016 }
2017
2018 result
2019 }
2020
2021 pub fn probe_generic_path_segments(
2039 &self,
2040 segments: &[hir::PathSegment<'_>],
2041 self_ty: Option<Ty<'tcx>>,
2042 kind: DefKind,
2043 def_id: DefId,
2044 span: Span,
2045 ) -> Vec<GenericPathSegment> {
2046 let tcx = self.tcx();
2092
2093 if !!segments.is_empty() {
::core::panicking::panic("assertion failed: !segments.is_empty()")
};assert!(!segments.is_empty());
2094 let last = segments.len() - 1;
2095
2096 let mut generic_segments = ::alloc::vec::Vec::new()vec![];
2097
2098 match kind {
2099 DefKind::Ctor(CtorOf::Struct, ..) => {
2101 let generics = tcx.generics_of(def_id);
2104 let generics_def_id = generics.parent.unwrap_or(def_id);
2107 generic_segments.push(GenericPathSegment(generics_def_id, last));
2108 }
2109
2110 DefKind::Ctor(CtorOf::Variant, ..) | DefKind::Variant => {
2112 let (generics_def_id, index) = if let Some(self_ty) = self_ty {
2113 let adt_def = self.probe_adt(span, self_ty).unwrap();
2116 if true {
if !adt_def.is_enum() {
::core::panicking::panic("assertion failed: adt_def.is_enum()")
};
};debug_assert!(adt_def.is_enum());
2117
2118 (adt_def.did(), last)
2130 } else if let [.., second_to_last, _] = segments
2131 && second_to_last.args.is_some()
2132 && let Res::Def(DefKind::Enum, _) = second_to_last.res
2133 {
2134 let def_id = match kind {
2143 DefKind::Ctor(..) => tcx.parent(def_id),
2144 _ => def_id,
2145 };
2146
2147 let enum_def_id = tcx.parent(def_id);
2149
2150 (enum_def_id, last - 1)
2151 } else {
2152 let generics = tcx.generics_of(def_id);
2159 (generics.parent.unwrap_or(def_id), last)
2162 };
2163 generic_segments.push(GenericPathSegment(generics_def_id, index));
2164 }
2165
2166 DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => {
2168 generic_segments.push(GenericPathSegment(def_id, last));
2169 }
2170
2171 DefKind::AssocFn | DefKind::AssocConst => {
2173 if segments.len() >= 2 {
2174 let generics = tcx.generics_of(def_id);
2175 generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1));
2176 }
2177 generic_segments.push(GenericPathSegment(def_id, last));
2178 }
2179
2180 kind => bug_impl(None,
format_args!("unexpected definition kind {0:?} for {1:?}", kind, def_id),
Location::caller())bug!("unexpected definition kind {:?} for {:?}", kind, def_id),
2181 }
2182
2183 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2183",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2183u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("generic_segments")
}> =
::tracing::__macro_support::FieldName::new("generic_segments");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generic_segments)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?generic_segments);
2184
2185 generic_segments
2186 }
2187
2188 {}
#[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_resolved_ty_path",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2189u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} 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: Ty<'tcx> = 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 /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2197",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2197u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path.res")
}> =
::tracing::__macro_support::FieldName::new("path.res");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("opt_self_ty")
}> =
::tracing::__macro_support::FieldName::new("opt_self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path.segments")
}> =
::tracing::__macro_support::FieldName::new("path.segments");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path.res)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&opt_self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path.segments)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let tcx = self.tcx();
let span = path.span;
match path.res {
Res::Def(DefKind::OpaqueTy, did) => {
{
match tcx.opaque_ty_origin(did) {
hir::OpaqueTyOrigin::TyAlias { .. } => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"hir::OpaqueTyOrigin::TyAlias { .. }",
::core::option::Option::None);
}
}
};
let [leading_segments @ .., segment] =
path.segments else {
bug_impl(None, format_args!("impossible case reached"),
Location::caller())
};
let _ =
self.prohibit_generic_args(leading_segments.iter(),
GenericsArgsErrExtend::OpaqueTy);
let args =
self.lower_generic_args_of_path_segment(span, did, segment);
Ty::new_opaque(tcx, ty::IsRigid::No, did, args)
}
Res::Def(DefKind::Enum | DefKind::TyAlias | DefKind::Struct |
DefKind::Union | DefKind::ForeignTy, did) => {
{
match (&opt_self_ty, &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 [leading_segments @ .., segment] =
path.segments else {
bug_impl(None, format_args!("impossible case reached"),
Location::caller())
};
let _ =
self.prohibit_generic_args(leading_segments.iter(),
GenericsArgsErrExtend::None);
self.lower_path_segment(span, did, segment)
}
Res::Def(kind @ DefKind::Variant, def_id) if
let PermitVariants::Yes = permit_variants => {
{
match (&opt_self_ty, &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 generic_segments =
self.probe_generic_path_segments(path.segments, None, kind,
def_id, span);
let indices: FxHashSet<_> =
generic_segments.iter().map(|GenericPathSegment(_, index)|
index).collect();
let _ =
self.prohibit_generic_args(path.segments.iter().enumerate().filter_map(|(index,
seg)|
{
if !indices.contains(&index) { Some(seg) } else { None }
}), GenericsArgsErrExtend::DefVariant(&path.segments));
let &GenericPathSegment(def_id, index) =
generic_segments.last().unwrap();
self.lower_path_segment(span, def_id, &path.segments[index])
}
Res::Def(DefKind::TyParam, def_id) => {
{
match (&opt_self_ty, &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 _ =
self.prohibit_generic_args(path.segments.iter(),
GenericsArgsErrExtend::Param(def_id));
self.lower_ty_param(hir_id)
}
Res::SelfTyParam { .. } => {
{
match (&opt_self_ty, &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 _ =
self.prohibit_generic_args(path.segments.iter(),
if let [hir::PathSegment { args: Some(args), ident, .. }] =
&path.segments {
GenericsArgsErrExtend::SelfTyParam(ident.span.shrink_to_hi().to(args.span_ext))
} else { GenericsArgsErrExtend::None });
self.check_param_uses_if_mcg(tcx.types.self_param, span,
false)
}
Res::SelfTyAlias { alias_to: def_id, .. } => {
{
match (&opt_self_ty, &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 ty =
tcx.at(span).type_of(def_id).instantiate_identity().skip_norm_wip();
let _ =
self.prohibit_generic_args(path.segments.iter(),
GenericsArgsErrExtend::SelfTyAlias { def_id, span });
self.check_param_uses_if_mcg(ty, span, true)
}
Res::Def(DefKind::AssocTy, def_id) => {
let trait_segment =
if let [modules @ .., trait_, _item] = path.segments {
let _ =
self.prohibit_generic_args(modules.iter(),
GenericsArgsErrExtend::None);
Some(trait_)
} else { None };
self.lower_resolved_assoc_ty_path(span, opt_self_ty, def_id,
trait_segment, path.segments.last().unwrap())
}
Res::PrimTy(prim_ty) => {
{
match (&opt_self_ty, &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 _ =
self.prohibit_generic_args(path.segments.iter(),
GenericsArgsErrExtend::PrimTy(prim_ty));
match prim_ty {
hir::PrimTy::Bool => tcx.types.bool,
hir::PrimTy::Char => tcx.types.char,
hir::PrimTy::Int(it) => Ty::new_int(tcx, it),
hir::PrimTy::Uint(uit) => Ty::new_uint(tcx, uit),
hir::PrimTy::Float(ft) => Ty::new_float(tcx, ft),
hir::PrimTy::Str => tcx.types.str_,
}
}
Res::Err => {
let e =
self.tcx().dcx().span_delayed_bug(path.span,
"path with `Res::Err` but no error emitted");
Ty::new_error(tcx, e)
}
Res::Def(..) => {
{
match (&path.segments.get(0).map(|seg| seg.ident.name),
&Some(kw::SelfUpper)) {
(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::Some(format_args!("only expected incorrect resolution for `Self`")));
}
}
}
};
Ty::new_error(self.tcx(),
self.dcx().span_delayed_bug(span,
"incorrect resolution for `Self`"))
}
_ =>
bug_impl(Some(span),
format_args!("unexpected resolution: {0:?}", path.res),
Location::caller()),
}
}
}
}#[instrument(level = "debug", skip_all)]
2190 pub fn lower_resolved_ty_path(
2191 &self,
2192 opt_self_ty: Option<Ty<'tcx>>,
2193 path: &hir::Path<'_>,
2194 hir_id: HirId,
2195 permit_variants: PermitVariants,
2196 ) -> Ty<'tcx> {
2197 debug!(?path.res, ?opt_self_ty, ?path.segments);
2198 let tcx = self.tcx();
2199
2200 let span = path.span;
2201 match path.res {
2202 Res::Def(DefKind::OpaqueTy, did) => {
2203 assert_matches!(tcx.opaque_ty_origin(did), hir::OpaqueTyOrigin::TyAlias { .. });
2205 let [leading_segments @ .., segment] = path.segments else { bug!() };
2206 let _ = self.prohibit_generic_args(
2207 leading_segments.iter(),
2208 GenericsArgsErrExtend::OpaqueTy,
2209 );
2210 let args = self.lower_generic_args_of_path_segment(span, did, segment);
2211 Ty::new_opaque(tcx, ty::IsRigid::No, did, args)
2212 }
2213 Res::Def(
2214 DefKind::Enum
2215 | DefKind::TyAlias
2216 | DefKind::Struct
2217 | DefKind::Union
2218 | DefKind::ForeignTy,
2219 did,
2220 ) => {
2221 assert_eq!(opt_self_ty, None);
2222 let [leading_segments @ .., segment] = path.segments else { bug!() };
2223 let _ = self
2224 .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
2225 self.lower_path_segment(span, did, segment)
2226 }
2227 Res::Def(kind @ DefKind::Variant, def_id)
2228 if let PermitVariants::Yes = permit_variants =>
2229 {
2230 assert_eq!(opt_self_ty, None);
2233
2234 let generic_segments =
2235 self.probe_generic_path_segments(path.segments, None, kind, def_id, span);
2236 let indices: FxHashSet<_> =
2237 generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
2238 let _ = self.prohibit_generic_args(
2239 path.segments.iter().enumerate().filter_map(|(index, seg)| {
2240 if !indices.contains(&index) { Some(seg) } else { None }
2241 }),
2242 GenericsArgsErrExtend::DefVariant(&path.segments),
2243 );
2244
2245 let &GenericPathSegment(def_id, index) = generic_segments.last().unwrap();
2246 self.lower_path_segment(span, def_id, &path.segments[index])
2247 }
2248 Res::Def(DefKind::TyParam, def_id) => {
2249 assert_eq!(opt_self_ty, None);
2250 let _ = self.prohibit_generic_args(
2251 path.segments.iter(),
2252 GenericsArgsErrExtend::Param(def_id),
2253 );
2254 self.lower_ty_param(hir_id)
2255 }
2256 Res::SelfTyParam { .. } => {
2257 assert_eq!(opt_self_ty, None);
2259 let _ = self.prohibit_generic_args(
2260 path.segments.iter(),
2261 if let [hir::PathSegment { args: Some(args), ident, .. }] = &path.segments {
2262 GenericsArgsErrExtend::SelfTyParam(
2263 ident.span.shrink_to_hi().to(args.span_ext),
2264 )
2265 } else {
2266 GenericsArgsErrExtend::None
2267 },
2268 );
2269 self.check_param_uses_if_mcg(tcx.types.self_param, span, false)
2270 }
2271 Res::SelfTyAlias { alias_to: def_id, .. } => {
2272 assert_eq!(opt_self_ty, None);
2274 let ty = tcx.at(span).type_of(def_id).instantiate_identity().skip_norm_wip();
2276 let _ = self.prohibit_generic_args(
2277 path.segments.iter(),
2278 GenericsArgsErrExtend::SelfTyAlias { def_id, span },
2279 );
2280 self.check_param_uses_if_mcg(ty, span, true)
2281 }
2282 Res::Def(DefKind::AssocTy, def_id) => {
2283 let trait_segment = if let [modules @ .., trait_, _item] = path.segments {
2284 let _ = self.prohibit_generic_args(modules.iter(), GenericsArgsErrExtend::None);
2285 Some(trait_)
2286 } else {
2287 None
2288 };
2289 self.lower_resolved_assoc_ty_path(
2290 span,
2291 opt_self_ty,
2292 def_id,
2293 trait_segment,
2294 path.segments.last().unwrap(),
2295 )
2296 }
2297 Res::PrimTy(prim_ty) => {
2298 assert_eq!(opt_self_ty, None);
2299 let _ = self.prohibit_generic_args(
2300 path.segments.iter(),
2301 GenericsArgsErrExtend::PrimTy(prim_ty),
2302 );
2303 match prim_ty {
2304 hir::PrimTy::Bool => tcx.types.bool,
2305 hir::PrimTy::Char => tcx.types.char,
2306 hir::PrimTy::Int(it) => Ty::new_int(tcx, it),
2307 hir::PrimTy::Uint(uit) => Ty::new_uint(tcx, uit),
2308 hir::PrimTy::Float(ft) => Ty::new_float(tcx, ft),
2309 hir::PrimTy::Str => tcx.types.str_,
2310 }
2311 }
2312 Res::Err => {
2313 let e = self
2314 .tcx()
2315 .dcx()
2316 .span_delayed_bug(path.span, "path with `Res::Err` but no error emitted");
2317 Ty::new_error(tcx, e)
2318 }
2319 Res::Def(..) => {
2320 assert_eq!(
2321 path.segments.get(0).map(|seg| seg.ident.name),
2322 Some(kw::SelfUpper),
2323 "only expected incorrect resolution for `Self`"
2324 );
2325 Ty::new_error(
2326 self.tcx(),
2327 self.dcx().span_delayed_bug(span, "incorrect resolution for `Self`"),
2328 )
2329 }
2330 _ => span_bug!(span, "unexpected resolution: {:?}", path.res),
2331 }
2332 }
2333
2334 pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx> {
2339 let tcx = self.tcx();
2340
2341 let ty = match tcx.named_bound_var(hir_id) {
2342 Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
2343 let br = ty::BoundTy {
2344 var: ty::BoundVar::from_u32(index),
2345 kind: ty::BoundTyKind::Param(def_id.to_def_id()),
2346 };
2347 Ty::new_bound(tcx, debruijn, br)
2348 }
2349 Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
2350 let item_def_id = tcx.hir_ty_param_owner(def_id);
2351 let generics = tcx.generics_of(item_def_id);
2352 let index = generics.param_def_id_to_index[&def_id.to_def_id()];
2353 Ty::new_param(tcx, index, tcx.hir_ty_param_name(def_id))
2354 }
2355 Some(rbv::ResolvedArg::Error(guar)) => Ty::new_error(tcx, guar),
2356 arg => bug_impl(None,
format_args!("unexpected bound var resolution for {0:?}: {1:?}", hir_id,
arg), Location::caller())bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
2357 };
2358 self.check_param_uses_if_mcg(ty, tcx.hir_span(hir_id), false)
2359 }
2360
2361 pub(crate) fn lower_const_param(&self, param_def_id: DefId, path_hir_id: HirId) -> Const<'tcx> {
2366 let tcx = self.tcx();
2367
2368 let ct = match tcx.named_bound_var(path_hir_id) {
2369 Some(rbv::ResolvedArg::EarlyBound(_)) => {
2370 let item_def_id = tcx.parent(param_def_id);
2373 let generics = tcx.generics_of(item_def_id);
2374 let index = generics.param_def_id_to_index[¶m_def_id];
2375 let name = tcx.item_name(param_def_id);
2376 ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
2377 }
2378 Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => ty::Const::new_bound(
2379 tcx,
2380 debruijn,
2381 ty::BoundConst::new(ty::BoundVar::from_u32(index)),
2382 ),
2383 Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar),
2384 arg => bug_impl(None,
format_args!("unexpected bound var resolution for {0:?}: {1:?}",
path_hir_id, arg), Location::caller())bug!("unexpected bound var resolution for {:?}: {arg:?}", path_hir_id),
2385 };
2386 self.check_param_uses_if_mcg(ct, tcx.hir_span(path_hir_id), false)
2387 }
2388
2389 {}
#[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_arg",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2390u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("const_arg")
}> =
::tracing::__macro_support::FieldName::new("const_arg");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&const_arg)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::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: Const<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
if let hir::ConstArgKind::Anon(anon) = &const_arg.kind {
if (tcx.features().generic_const_parameter_types() ||
tcx.features().min_generic_const_args()) &&
(ty.has_free_regions() || ty.has_erased_regions()) {
let e =
self.dcx().span_err(const_arg.span,
"anonymous constants with lifetimes in their type are not yet supported");
tcx.feed_anon_const_type(anon.def_id,
ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)));
return ty::Const::new_error(tcx, e);
}
if ty.has_non_region_infer() {
let e =
self.dcx().span_err(const_arg.span,
"anonymous constants with inferred types are not yet supported");
tcx.feed_anon_const_type(anon.def_id,
ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)));
return ty::Const::new_error(tcx, e);
}
if ty.has_non_region_param() {
let e =
self.dcx().span_err(const_arg.span,
"anonymous constants referencing generics are not yet supported");
tcx.feed_anon_const_type(anon.def_id,
ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)));
return ty::Const::new_error(tcx, e);
}
tcx.feed_anon_const_type(anon.def_id,
ty::EarlyBinder::bind(tcx, ty));
}
let hir_id = const_arg.hir_id;
match const_arg.kind {
hir::ConstArgKind::Tup(exprs) =>
self.lower_const_arg_tup(exprs, ty, const_arg.span),
hir::ConstArgKind::Path(hir::QPath::Resolved(maybe_qself,
path)) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2456",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2456u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("maybe_qself")
}> =
::tracing::__macro_support::FieldName::new("maybe_qself");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&maybe_qself)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let opt_self_ty =
maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
self.lower_resolved_const_path(opt_self_ty, path, hir_id)
}
hir::ConstArgKind::Path(hir::QPath::TypeRelative(hir_self_ty,
segment)) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2461",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2461u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_self_ty")
}> =
::tracing::__macro_support::FieldName::new("hir_self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("segment")
}> =
::tracing::__macro_support::FieldName::new("segment");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let self_ty = self.lower_ty(hir_self_ty);
self.lower_type_relative_const_path(self_ty, hir_self_ty,
segment, hir_id,
const_arg.span).unwrap_or_else(|guar|
Const::new_error(tcx, guar))
}
hir::ConstArgKind::Struct(qpath, inits) => {
self.lower_const_arg_struct(hir_id, qpath, inits,
const_arg.span)
}
hir::ConstArgKind::TupleCall(qpath, args) => {
self.lower_const_arg_tuple_call(hir_id, qpath, args,
const_arg.span)
}
hir::ConstArgKind::Array(array_expr) =>
self.lower_const_arg_array(array_expr, ty),
hir::ConstArgKind::Anon(anon) =>
self.lower_const_arg_anon(anon),
hir::ConstArgKind::Infer(()) =>
self.ct_infer(None, const_arg.span),
hir::ConstArgKind::Error(e) => ty::Const::new_error(tcx, e),
hir::ConstArgKind::Literal { lit, negated } => {
self.lower_const_arg_literal(&lit, negated, ty,
const_arg.span)
}
}
}
}
}#[instrument(skip(self), level = "debug")]
2391 pub fn lower_const_arg(&self, const_arg: &hir::ConstArg<'_>, ty: Ty<'tcx>) -> Const<'tcx> {
2392 let tcx = self.tcx();
2393
2394 if let hir::ConstArgKind::Anon(anon) = &const_arg.kind {
2395 if (tcx.features().generic_const_parameter_types()
2408 || tcx.features().min_generic_const_args())
2409 && (ty.has_free_regions() || ty.has_erased_regions())
2410 {
2411 let e = self.dcx().span_err(
2412 const_arg.span,
2413 "anonymous constants with lifetimes in their type are not yet supported",
2414 );
2415 tcx.feed_anon_const_type(
2416 anon.def_id,
2417 ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)),
2418 );
2419 return ty::Const::new_error(tcx, e);
2420 }
2421 if ty.has_non_region_infer() {
2425 let e = self.dcx().span_err(
2426 const_arg.span,
2427 "anonymous constants with inferred types are not yet supported",
2428 );
2429 tcx.feed_anon_const_type(
2430 anon.def_id,
2431 ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)),
2432 );
2433 return ty::Const::new_error(tcx, e);
2434 }
2435 if ty.has_non_region_param() {
2438 let e = self.dcx().span_err(
2439 const_arg.span,
2440 "anonymous constants referencing generics are not yet supported",
2441 );
2442 tcx.feed_anon_const_type(
2443 anon.def_id,
2444 ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)),
2445 );
2446 return ty::Const::new_error(tcx, e);
2447 }
2448
2449 tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(tcx, ty));
2450 }
2451
2452 let hir_id = const_arg.hir_id;
2453 match const_arg.kind {
2454 hir::ConstArgKind::Tup(exprs) => self.lower_const_arg_tup(exprs, ty, const_arg.span),
2455 hir::ConstArgKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
2456 debug!(?maybe_qself, ?path);
2457 let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2458 self.lower_resolved_const_path(opt_self_ty, path, hir_id)
2459 }
2460 hir::ConstArgKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment)) => {
2461 debug!(?hir_self_ty, ?segment);
2462 let self_ty = self.lower_ty(hir_self_ty);
2463 self.lower_type_relative_const_path(
2464 self_ty,
2465 hir_self_ty,
2466 segment,
2467 hir_id,
2468 const_arg.span,
2469 )
2470 .unwrap_or_else(|guar| Const::new_error(tcx, guar))
2471 }
2472 hir::ConstArgKind::Struct(qpath, inits) => {
2473 self.lower_const_arg_struct(hir_id, qpath, inits, const_arg.span)
2474 }
2475 hir::ConstArgKind::TupleCall(qpath, args) => {
2476 self.lower_const_arg_tuple_call(hir_id, qpath, args, const_arg.span)
2477 }
2478 hir::ConstArgKind::Array(array_expr) => self.lower_const_arg_array(array_expr, ty),
2479 hir::ConstArgKind::Anon(anon) => self.lower_const_arg_anon(anon),
2480 hir::ConstArgKind::Infer(()) => self.ct_infer(None, const_arg.span),
2481 hir::ConstArgKind::Error(e) => ty::Const::new_error(tcx, e),
2482 hir::ConstArgKind::Literal { lit, negated } => {
2483 self.lower_const_arg_literal(&lit, negated, ty, const_arg.span)
2484 }
2485 }
2486 }
2487
2488 fn lower_const_arg_array(
2489 &self,
2490 array_expr: &hir::ConstArgArrayExpr<'_>,
2491 ty: Ty<'tcx>,
2492 ) -> Const<'tcx> {
2493 let tcx = self.tcx();
2494
2495 let (elem_ty, len) = match ty.kind() {
2496 ty::Array(elem_ty, len) => (elem_ty, len),
2497 ty::Error(e) => return Const::new_error(tcx, *e),
2498 _ => {
2499 let e = tcx
2500 .dcx()
2501 .span_err(array_expr.span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected `{0}`, found const array",
ty))
})format!("expected `{ty}`, found const array"));
2502 return Const::new_error(tcx, e);
2503 }
2504 };
2505
2506 let elems = array_expr
2507 .elems
2508 .iter()
2509 .map(|elem| self.lower_const_arg(elem, *elem_ty))
2510 .collect::<Vec<_>>();
2511
2512 let len = tcx
2513 .try_normalize_erasing_regions(
2514 ty::TypingEnv::new(ty::ParamEnv::empty(), TypingMode::non_body_analysis()),
2515 Unnormalized::new_wip(*len),
2516 )
2517 .unwrap_or(*len);
2518 if let Some(expected_len) = len.try_to_target_usize(tcx)
2519 && expected_len != elems.len() as u64
2520 {
2521 let e = tcx.dcx().span_err(
2522 array_expr.span,
2523 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected array with {1} elements, found {0} elements",
array_expr.elems.len(), expected_len))
})format!(
2524 "expected array with {expected_len} elements, found {} elements",
2525 array_expr.elems.len()
2526 ),
2527 );
2528 return Const::new_error(tcx, e);
2529 }
2530
2531 let valtree = ty::ValTree::from_branches(tcx, elems);
2532
2533 ty::Const::new_value(tcx, valtree, ty)
2534 }
2535
2536 fn try_recover_misrepresented_function_call(
2537 &self,
2538 hir_self_ty: &hir::Ty<'_>,
2539 span: Span,
2540 ) -> Option<ErrorGuaranteed> {
2541 let self_ty_res = match hir_self_ty.kind {
2551 hir::TyKind::Path(hir::QPath::Resolved(_, path)) => path.res,
2552 _ => Res::Err,
2553 };
2554 #[allow(non_exhaustive_omitted_patterns)] match self_ty_res {
Res::Def(DefKind::Struct | DefKind::Union | DefKind::ForeignTy, _) |
Res::PrimTy(_) => true,
_ => false,
}matches!(
2555 self_ty_res,
2556 Res::Def(DefKind::Struct | DefKind::Union | DefKind::ForeignTy, _) | Res::PrimTy(_)
2557 )
2558 .then(|| self.dcx().emit_err(diagnostics::ComplexConstArg { span }))
2559 }
2560
2561 fn lower_const_arg_tuple_call(
2562 &self,
2563 hir_id: HirId,
2564 qpath: hir::QPath<'_>,
2565 args: &[&hir::ConstArg<'_>],
2566 span: Span,
2567 ) -> Const<'tcx> {
2568 let tcx = self.tcx();
2569
2570 let non_adt_or_variant_res = || {
2571 let e = tcx.dcx().span_err(span, "tuple constructor with invalid base path");
2572 ty::Const::new_error(tcx, e)
2573 };
2574
2575 let ctor_const = match qpath {
2576 hir::QPath::Resolved(maybe_qself, path) => {
2577 let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2578 self.lower_resolved_const_path(opt_self_ty, path, hir_id)
2579 }
2580 hir::QPath::TypeRelative(hir_self_ty, segment) => {
2581 if let Some(e) = self.try_recover_misrepresented_function_call(hir_self_ty, span) {
2582 return ty::Const::new_error(tcx, e);
2583 }
2584
2585 let self_ty = self.lower_ty(hir_self_ty);
2586 match self.lower_type_relative_const_path(
2587 self_ty,
2588 hir_self_ty,
2589 segment,
2590 hir_id,
2591 span,
2592 ) {
2593 Ok(c) => c,
2594 Err(_) => return non_adt_or_variant_res(),
2595 }
2596 }
2597 };
2598
2599 let Some(value) = ctor_const.try_to_value() else {
2600 return non_adt_or_variant_res();
2601 };
2602
2603 let (adt_def, adt_args, variant_did) = match value.ty.kind() {
2604 ty::FnDef(def_id, fn_args)
2605 if let DefKind::Ctor(CtorOf::Variant, _) = tcx.def_kind(*def_id) =>
2606 {
2607 let parent_did = tcx.parent(*def_id);
2608 let enum_did = tcx.parent(parent_did);
2609 (tcx.adt_def(enum_did), fn_args, parent_did)
2610 }
2611 ty::FnDef(def_id, fn_args)
2612 if let DefKind::Ctor(CtorOf::Struct, _) = tcx.def_kind(*def_id) =>
2613 {
2614 let parent_did = tcx.parent(*def_id);
2615 (tcx.adt_def(parent_did), fn_args, parent_did)
2616 }
2617 _ => {
2618 let e = self.dcx().emit_err(diagnostics::ComplexConstArg { span });
2619 return Const::new_error(tcx, e);
2620 }
2621 };
2622
2623 let variant_def = adt_def.variant_with_id(variant_did);
2624 let variant_idx = adt_def.variant_index_with_id(variant_did).as_u32();
2625
2626 if args.len() != variant_def.fields.len() {
2627 let e = tcx.dcx().span_err(
2628 span,
2629 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("tuple constructor has {0} arguments but {1} were provided",
variant_def.fields.len(), args.len()))
})format!(
2630 "tuple constructor has {} arguments but {} were provided",
2631 variant_def.fields.len(),
2632 args.len()
2633 ),
2634 );
2635 return ty::Const::new_error(tcx, e);
2636 }
2637
2638 let fields = variant_def
2639 .fields
2640 .iter()
2641 .zip(args)
2642 .map(|(field_def, arg)| {
2643 self.lower_const_arg(
2644 arg,
2645 tcx.type_of(field_def.did)
2646 .instantiate(tcx, adt_args.no_bound_vars().unwrap())
2647 .skip_norm_wip(),
2648 )
2649 })
2650 .collect::<Vec<_>>();
2651
2652 let opt_discr_const = if adt_def.is_enum() {
2653 let valtree = ty::ValTree::from_scalar_int(tcx, variant_idx.into());
2654 Some(ty::Const::new_value(tcx, valtree, tcx.types.u32))
2655 } else {
2656 None
2657 };
2658
2659 let valtree = ty::ValTree::from_branches(tcx, opt_discr_const.into_iter().chain(fields));
2660 let adt_ty = Ty::new_adt(tcx, adt_def, adt_args.no_bound_vars().unwrap());
2661 ty::Const::new_value(tcx, valtree, adt_ty)
2662 }
2663
2664 fn lower_const_arg_tup(
2665 &self,
2666 exprs: &[&hir::ConstArg<'_>],
2667 ty: Ty<'tcx>,
2668 span: Span,
2669 ) -> Const<'tcx> {
2670 let tcx = self.tcx();
2671
2672 let found_tuple = || {
2673 tcx.sess
2674 .source_map()
2675 .span_to_snippet(span)
2676 .map(|snippet| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}`", snippet))
})format!("`{snippet}`"))
2677 .unwrap_or_else(|_| "const tuple".to_string())
2678 };
2679
2680 let tys = match ty.kind() {
2681 ty::Tuple(tys) => tys,
2682 ty::Error(e) => return Const::new_error(tcx, *e),
2683 _ => {
2684 let e =
2685 tcx.dcx().span_err(span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected `{0}`, found {1}", ty,
found_tuple()))
})format!("expected `{}`, found {}", ty, found_tuple()));
2686 return Const::new_error(tcx, e);
2687 }
2688 };
2689
2690 if exprs.len() != tys.len() {
2691 let e = tcx.dcx().span_err(span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expected `{0}`, found {1}", ty,
found_tuple()))
})format!("expected `{}`, found {}", ty, found_tuple()));
2692 return Const::new_error(tcx, e);
2693 }
2694
2695 let exprs = exprs
2696 .iter()
2697 .zip(tys.iter())
2698 .map(|(expr, ty)| self.lower_const_arg(expr, ty))
2699 .collect::<Vec<_>>();
2700
2701 let valtree = ty::ValTree::from_branches(tcx, exprs);
2702 ty::Const::new_value(tcx, valtree, ty)
2703 }
2704
2705 fn lower_const_arg_struct(
2706 &self,
2707 hir_id: HirId,
2708 qpath: hir::QPath<'_>,
2709 inits: &[&hir::ConstArgExprField<'_>],
2710 span: Span,
2711 ) -> Const<'tcx> {
2712 let tcx = self.tcx();
2715
2716 let non_adt_or_variant_res = || {
2717 let e = tcx.dcx().span_err(span, "struct expression with invalid base path");
2718 ty::Const::new_error(tcx, e)
2719 };
2720
2721 let ResolvedStructPath { res: opt_res, ty } =
2722 self.lower_path_for_struct_expr(qpath, span, hir_id);
2723
2724 let variant_did = match qpath {
2725 hir::QPath::Resolved(maybe_qself, path) => {
2726 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2726",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2726u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("maybe_qself")
}> =
::tracing::__macro_support::FieldName::new("maybe_qself");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&maybe_qself)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?maybe_qself, ?path);
2727 let variant_did = match path.res {
2728 Res::Def(DefKind::Variant | DefKind::Struct, did) => did,
2729 _ => return non_adt_or_variant_res(),
2730 };
2731
2732 variant_did
2733 }
2734 hir::QPath::TypeRelative(hir_self_ty, segment) => {
2735 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:2735",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(2735u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_self_ty")
}> =
::tracing::__macro_support::FieldName::new("hir_self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("segment")
}> =
::tracing::__macro_support::FieldName::new("segment");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?hir_self_ty, ?segment);
2736
2737 let res_def_id = match opt_res {
2738 Ok(r)
2739 if #[allow(non_exhaustive_omitted_patterns)] match tcx.def_kind(r.def_id()) {
DefKind::Variant | DefKind::Struct => true,
_ => false,
}matches!(
2740 tcx.def_kind(r.def_id()),
2741 DefKind::Variant | DefKind::Struct
2742 ) =>
2743 {
2744 r.def_id()
2745 }
2746 Ok(_) => return non_adt_or_variant_res(),
2747 Err(e) => return ty::Const::new_error(tcx, e),
2748 };
2749
2750 res_def_id
2751 }
2752 };
2753
2754 let ty::Adt(adt_def, adt_args) = ty.kind() else { ::core::panicking::panic("internal error: entered unreachable code")unreachable!() };
2755
2756 let variant_def = adt_def.variant_with_id(variant_did);
2757 let variant_idx = adt_def.variant_index_with_id(variant_did).as_u32();
2758
2759 for init in inits {
2760 if !variant_def.fields.iter().any(|field_def| field_def.name == init.field.name) {
2761 let mut err = if adt_def.is_enum() {
2762 {
tcx.dcx().struct_span_err(init.field.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("variant `{0}::{1}` has no field named `{2}`",
ty, variant_def.name, init.field))
})).with_code(E0559)
}struct_span_code_err!(
2763 tcx.dcx(),
2764 init.field.span,
2765 E0559,
2766 "variant `{}::{}` has no field named `{}`",
2767 ty,
2768 variant_def.name,
2769 init.field
2770 )
2771 } else {
2772 {
tcx.dcx().struct_span_err(init.field.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("struct `{0}` has no field named `{1}`",
variant_def.name, init.field))
})).with_code(E0560)
}struct_span_code_err!(
2773 tcx.dcx(),
2774 init.field.span,
2775 E0560,
2776 "struct `{}` has no field named `{}`",
2777 variant_def.name,
2778 init.field
2779 )
2780 };
2781 if adt_def.is_enum() {
2782 err.span_label(
2783 init.field.span,
2784 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}::{1}` does not have this field",
ty, variant_def.name))
})format!("`{}::{}` does not have this field", ty, variant_def.name),
2785 );
2786 } else {
2787 err.span_label(
2788 init.field.span,
2789 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` does not have this field",
variant_def.name))
})format!("`{}` does not have this field", variant_def.name),
2790 );
2791 }
2792 return ty::Const::new_error(tcx, err.emit());
2793 }
2794 }
2795
2796 let fields = variant_def
2797 .fields
2798 .iter()
2799 .map(|field_def| {
2800 let mut init_expr =
2803 inits.iter().filter(|init_expr| init_expr.field.name == field_def.name);
2804
2805 match init_expr.next() {
2806 Some(expr) => {
2807 if let Some(expr) = init_expr.next() {
2808 let e = tcx.dcx().span_err(
2809 expr.span,
2810 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("struct expression with multiple initialisers for `{0}`",
field_def.name))
})format!(
2811 "struct expression with multiple initialisers for `{}`",
2812 field_def.name,
2813 ),
2814 );
2815 return ty::Const::new_error(tcx, e);
2816 }
2817
2818 self.lower_const_arg(
2819 expr.expr,
2820 tcx.type_of(field_def.did).instantiate(tcx, adt_args).skip_norm_wip(),
2821 )
2822 }
2823 None => {
2824 let e = tcx.dcx().span_err(
2825 span,
2826 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("struct expression with missing field initialiser for `{0}`",
field_def.name))
})format!(
2827 "struct expression with missing field initialiser for `{}`",
2828 field_def.name
2829 ),
2830 );
2831 ty::Const::new_error(tcx, e)
2832 }
2833 }
2834 })
2835 .collect::<Vec<_>>();
2836
2837 let opt_discr_const = if adt_def.is_enum() {
2838 let valtree = ty::ValTree::from_scalar_int(tcx, variant_idx.into());
2839 Some(ty::Const::new_value(tcx, valtree, tcx.types.u32))
2840 } else {
2841 None
2842 };
2843
2844 let valtree = ty::ValTree::from_branches(tcx, opt_discr_const.into_iter().chain(fields));
2845 ty::Const::new_value(tcx, valtree, ty)
2846 }
2847
2848 pub fn lower_path_for_struct_expr(
2849 &self,
2850 qpath: hir::QPath<'_>,
2851 path_span: Span,
2852 hir_id: HirId,
2853 ) -> ResolvedStructPath<'tcx> {
2854 match qpath {
2855 hir::QPath::Resolved(ref maybe_qself, path) => {
2856 let self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
2857 let ty = self.lower_resolved_ty_path(self_ty, path, hir_id, PermitVariants::Yes);
2858 ResolvedStructPath { res: Ok(path.res), ty }
2859 }
2860 hir::QPath::TypeRelative(hir_self_ty, segment) => {
2861 let self_ty = self.lower_ty(hir_self_ty);
2862
2863 let result = self.lower_type_relative_ty_path(
2864 self_ty,
2865 hir_self_ty,
2866 segment,
2867 hir_id,
2868 path_span,
2869 PermitVariants::Yes,
2870 );
2871 let ty = result
2872 .map(|(ty, _, _)| ty)
2873 .unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));
2874
2875 ResolvedStructPath {
2876 res: result.map(|(_, kind, def_id)| Res::Def(kind, def_id)),
2877 ty,
2878 }
2879 }
2880 }
2881 }
2882
2883 fn lower_resolved_const_path(
2885 &self,
2886 opt_self_ty: Option<Ty<'tcx>>,
2887 path: &hir::Path<'_>,
2888 hir_id: HirId,
2889 ) -> Const<'tcx> {
2890 let tcx = self.tcx();
2891 let span = path.span;
2892 let ct = match path.res {
2893 Res::Def(DefKind::ConstParam, def_id) => {
2894 {
match (&opt_self_ty, &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);
}
}
}
};assert_eq!(opt_self_ty, None);
2895 let _ = self.prohibit_generic_args(
2896 path.segments.iter(),
2897 GenericsArgsErrExtend::Param(def_id),
2898 );
2899 self.lower_const_param(def_id, hir_id)
2900 }
2901 Res::Def(DefKind::Const, did) => {
2902 if let Err(guar) = self.check_const_item_in_type_system(did, span) {
2903 return Const::new_error(self.tcx(), guar);
2904 }
2905
2906 {
match (&opt_self_ty, &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);
}
}
}
};assert_eq!(opt_self_ty, None);
2907 let [leading_segments @ .., segment] = path.segments else { bug_impl(None, format_args!("impossible case reached"), Location::caller())bug!() };
2908 let _ = self
2909 .prohibit_generic_args(leading_segments.iter(), GenericsArgsErrExtend::None);
2910 let args = self.lower_generic_args_of_path_segment(span, did, segment);
2911 ty::Const::new_alias(
2912 tcx,
2913 ty::IsRigid::No,
2914 ty::AliasConst::new(
2915 tcx,
2916 ty::AliasConstKind::new_from_def_id(
2917 tcx,
2918 did,
2919 ty::AliasConstInherentArgsKind::WithSelf,
2920 ),
2921 args,
2922 ),
2923 )
2924 }
2925 Res::Def(kind @ DefKind::Ctor(ctor_of, CtorKind::Const), did) => {
2926 {
match (&opt_self_ty, &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);
}
}
}
};assert_eq!(opt_self_ty, None);
2927 let generic_segments =
2928 self.probe_generic_path_segments(path.segments, opt_self_ty, kind, did, span);
2929 let indices: FxHashSet<_> =
2930 generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
2931 let _ = self.prohibit_generic_args(
2932 path.segments.iter().enumerate().filter_map(|(index, seg)| {
2933 if !indices.contains(&index) { Some(seg) } else { None }
2934 }),
2935 GenericsArgsErrExtend::DefVariant(&path.segments),
2936 );
2937
2938 let parent_did = tcx.parent(did);
2939 let generics_did = match ctor_of {
2940 CtorOf::Variant => tcx.parent(parent_did),
2941 CtorOf::Struct => parent_did,
2942 };
2943 let args = self.lower_generic_args_of_path_segment(
2944 span,
2945 generics_did,
2946 &path.segments[generic_segments[0].1],
2947 );
2948 self.construct_const_ctor_value(did, ctor_of, args)
2949 }
2950 Res::Def(DefKind::Ctor(ctor_of, CtorKind::Fn), did) => {
2951 {
match (&opt_self_ty, &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);
}
}
}
};assert_eq!(opt_self_ty, None);
2952 let generic_segments = self.probe_generic_path_segments(
2953 path.segments,
2954 opt_self_ty,
2955 DefKind::Ctor(ctor_of, CtorKind::Const),
2956 did,
2957 span,
2958 );
2959 let indices: FxHashSet<_> =
2960 generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect();
2961 let _ = self.prohibit_generic_args(
2962 path.segments.iter().enumerate().filter_map(|(index, seg)| {
2963 if !indices.contains(&index) { Some(seg) } else { None }
2964 }),
2965 GenericsArgsErrExtend::DefVariant(&path.segments),
2966 );
2967
2968 let parent_did = tcx.parent(did);
2969 let generics_did = if let DefKind::Ctor(CtorOf::Variant, _) = tcx.def_kind(did) {
2970 tcx.parent(parent_did)
2971 } else {
2972 parent_did
2973 };
2974 let args = self.lower_generic_args_of_path_segment(
2975 span,
2976 generics_did,
2977 &path.segments[generic_segments[0].1],
2978 );
2979
2980 ty::Const::zero_sized(tcx, tcx.type_of(did).instantiate(tcx, args).skip_norm_wip())
2981 }
2982 Res::Def(DefKind::AssocConst, did) => {
2983 let trait_segment = if let [modules @ .., trait_, _item] = path.segments {
2984 let _ = self.prohibit_generic_args(modules.iter(), GenericsArgsErrExtend::None);
2985 Some(trait_)
2986 } else {
2987 None
2988 };
2989 self.lower_resolved_assoc_const_path(
2990 span,
2991 opt_self_ty,
2992 did,
2993 trait_segment,
2994 path.segments.last().unwrap(),
2995 )
2996 .unwrap_or_else(|guar| Const::new_error(tcx, guar))
2997 }
2998 Res::Def(DefKind::Static { .. }, _) => {
2999 let guar = self
3000 .dcx()
3001 .span_err(path.span, "static items cannot be used as const arguments");
3002 return Const::new_error(tcx, guar);
3003 }
3004 Res::Def(DefKind::Fn | DefKind::AssocFn, _) => {
3009 let guar = self
3010 .dcx()
3011 .struct_span_err(span, "function items cannot be used as const args")
3012 .emit();
3013 Const::new_error(tcx, guar)
3014 }
3015 res @ (Res::Def(
3018 DefKind::Mod
3019 | DefKind::Enum
3020 | DefKind::Variant
3021 | DefKind::Struct
3022 | DefKind::OpaqueTy
3023 | DefKind::TyAlias
3024 | DefKind::TraitAlias
3025 | DefKind::AssocTy
3026 | DefKind::Union
3027 | DefKind::Trait
3028 | DefKind::ForeignTy
3029 | DefKind::TyParam
3030 | DefKind::Macro(_)
3031 | DefKind::LifetimeParam
3032 | DefKind::Use
3033 | DefKind::ForeignMod
3034 | DefKind::AnonConst
3035 | DefKind::Field
3036 | DefKind::Impl { .. }
3037 | DefKind::Closure
3038 | DefKind::ExternCrate
3039 | DefKind::GlobalAsm
3040 | DefKind::SyntheticCoroutineBody
3041 | DefKind::TestBinderConstraints,
3042 _,
3043 )
3044 | Res::PrimTy(_)
3045 | Res::SelfTyParam { .. }
3046 | Res::SelfTyAlias { .. }
3047 | Res::SelfCtor(_)
3048 | Res::Local(_)
3049 | Res::ToolMod
3050 | Res::OpenMod(..)
3051 | Res::NonMacroAttr(_)
3052 | Res::Err) => Const::new_error_with_message(
3053 tcx,
3054 span,
3055 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("invalid Res {0:?} for const path",
res))
})format!("invalid Res {res:?} for const path"),
3056 ),
3057 };
3058 self.check_param_uses_if_mcg(ct, span, false)
3059 }
3060
3061 {}
#[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_arg_anon",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3062u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("anon")
}> =
::tracing::__macro_support::FieldName::new("anon");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&anon)
as &dyn ::tracing::field::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: Const<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let expr = &tcx.hir_body(anon.body).value;
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3067",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3067u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let ty =
tcx.type_of(anon.def_id).instantiate_identity().skip_norm_wip();
match self.try_lower_anon_const_lit(ty, expr) {
Some(v) => v,
None =>
ty::Const::new_alias(tcx, ty::IsRigid::No,
ty::AliasConst::new(tcx,
ty::AliasConstKind::Anon {
def_id: anon.def_id.to_def_id(),
},
ty::GenericArgs::identity_for_item(tcx,
anon.def_id.to_def_id()))),
}
}
}
}#[instrument(skip(self), level = "debug")]
3063 fn lower_const_arg_anon(&self, anon: &AnonConst) -> Const<'tcx> {
3064 let tcx = self.tcx();
3065
3066 let expr = &tcx.hir_body(anon.body).value;
3067 debug!(?expr);
3068
3069 let ty = tcx.type_of(anon.def_id).instantiate_identity().skip_norm_wip();
3073
3074 match self.try_lower_anon_const_lit(ty, expr) {
3075 Some(v) => v,
3076 None => ty::Const::new_alias(
3077 tcx,
3078 ty::IsRigid::No,
3079 ty::AliasConst::new(
3080 tcx,
3081 ty::AliasConstKind::Anon { def_id: anon.def_id.to_def_id() },
3082 ty::GenericArgs::identity_for_item(tcx, anon.def_id.to_def_id()),
3083 ),
3084 ),
3085 }
3086 }
3087
3088 {}
#[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_arg_literal",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3088u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("neg")
}> =
::tracing::__macro_support::FieldName::new("neg");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&neg as
&dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::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: Const<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let ty = if !ty.has_infer() { Some(ty) } else { None };
if let LitKind::Err(guar) = *kind {
return ty::Const::new_error(tcx, guar);
}
let input = LitToConstInput { lit: *kind, ty, neg };
match tcx.at(span).lit_to_const(input) {
Some(value) =>
ty::Const::new_value(tcx, value.valtree, value.ty),
None => {
let e =
tcx.dcx().span_err(span,
"type annotations needed for the literal");
ty::Const::new_error(tcx, e)
}
}
}
}
}#[instrument(skip(self), level = "debug")]
3089 fn lower_const_arg_literal(
3090 &self,
3091 kind: &LitKind,
3092 neg: bool,
3093 ty: Ty<'tcx>,
3094 span: Span,
3095 ) -> Const<'tcx> {
3096 let tcx = self.tcx();
3097
3098 let ty = if !ty.has_infer() { Some(ty) } else { None };
3099
3100 if let LitKind::Err(guar) = *kind {
3101 return ty::Const::new_error(tcx, guar);
3102 }
3103 let input = LitToConstInput { lit: *kind, ty, neg };
3104 match tcx.at(span).lit_to_const(input) {
3105 Some(value) => ty::Const::new_value(tcx, value.valtree, value.ty),
3106 None => {
3107 let e = tcx.dcx().span_err(span, "type annotations needed for the literal");
3108 ty::Const::new_error(tcx, e)
3109 }
3110 }
3111 }
3112
3113 {}
#[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("try_lower_anon_const_lit",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3113u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<Const<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let expr =
match &expr.kind {
hir::ExprKind::Block(block, _) if
block.stmts.is_empty() && block.expr.is_some() => {
block.expr.as_ref().unwrap()
}
_ => expr,
};
let lit_input =
match expr.kind {
hir::ExprKind::Lit(lit) => {
Some(LitToConstInput {
lit: lit.node,
ty: Some(ty),
neg: false,
})
}
hir::ExprKind::Unary(hir::UnOp::Neg, expr) =>
match expr.kind {
hir::ExprKind::Lit(lit) => {
Some(LitToConstInput {
lit: lit.node,
ty: Some(ty),
neg: true,
})
}
_ => None,
},
_ => None,
};
lit_input.and_then(|l|
{
if const_lit_matches_ty(tcx, &l.lit, ty, l.neg) {
tcx.at(expr.span).lit_to_const(l).map(|value|
ty::Const::new_value(tcx, value.valtree, value.ty))
} else { None }
})
}
}
}#[instrument(skip(self), level = "debug")]
3114 fn try_lower_anon_const_lit(
3115 &self,
3116 ty: Ty<'tcx>,
3117 expr: &'tcx hir::Expr<'tcx>,
3118 ) -> Option<Const<'tcx>> {
3119 let tcx = self.tcx();
3120
3121 let expr = match &expr.kind {
3124 hir::ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => {
3125 block.expr.as_ref().unwrap()
3126 }
3127 _ => expr,
3128 };
3129
3130 let lit_input = match expr.kind {
3131 hir::ExprKind::Lit(lit) => {
3132 Some(LitToConstInput { lit: lit.node, ty: Some(ty), neg: false })
3133 }
3134 hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
3135 hir::ExprKind::Lit(lit) => {
3136 Some(LitToConstInput { lit: lit.node, ty: Some(ty), neg: true })
3137 }
3138 _ => None,
3139 },
3140 _ => None,
3141 };
3142
3143 lit_input.and_then(|l| {
3144 if const_lit_matches_ty(tcx, &l.lit, ty, l.neg) {
3145 tcx.at(expr.span)
3146 .lit_to_const(l)
3147 .map(|value| ty::Const::new_value(tcx, value.valtree, value.ty))
3148 } else {
3149 None
3150 }
3151 })
3152 }
3153
3154 fn check_const_item_in_type_system(
3156 &self,
3157 def_id: DefId,
3158 span: Span,
3159 ) -> Result<(), ErrorGuaranteed> {
3160 let tcx = self.tcx();
3161 if tcx.features().generic_const_args() || tcx.is_direct_const(def_id) {
3162 Ok(())
3163 } else {
3164 let mut err = self
3165 .dcx()
3166 .struct_span_err(span, "use of `const` in the type system not marked as direct");
3167 if let Some(local_def_id) = def_id.as_local() {
3168 if let Some(body_id) = tcx.hir_node_by_def_id(local_def_id).body_id() {
3169 let body_span = tcx.hir_body(body_id).value.span;
3170
3171 err.multipart_suggestion(
3172 "add direct_const_arg!() to the right-hand side of the constant",
3173 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(body_span.shrink_to_lo(), String::from("core::direct_const_arg!(")),
(body_span.shrink_to_hi(), String::from(")"))]))vec![
3174 (body_span.shrink_to_lo(), String::from("core::direct_const_arg!(")),
3175 (body_span.shrink_to_hi(), String::from(")")),
3176 ],
3177 Applicability::MaybeIncorrect,
3178 );
3179 } else if let DefKind::AssocConst = tcx.def_kind(def_id)
3180 && let DefKind::Trait = tcx.def_kind(tcx.parent(def_id))
3181 {
3182 let node = tcx.hir_node_by_def_id(local_def_id).expect_trait_item();
3183 let sp = node.span.shrink_to_lo();
3184 err.span_suggestion_verbose(
3185 sp,
3186 "add `#[rustc_always_gca]` to the constant",
3187 "#[rustc_always_gca] ",
3188 Applicability::MaybeIncorrect,
3189 );
3190 }
3191 } else {
3192 err.note(
3193 "only consts with a `direct_const_arg!` right-hand side may be used in types",
3194 );
3195 }
3196 Err(err.emit())
3197 }
3198 }
3199
3200 fn lower_delegation_ty(&self, infer: hir::InferDelegation<'_>) -> Ty<'tcx> {
3201 match infer {
3202 hir::InferDelegation::DefId(def_id) => {
3203 self.tcx().type_of(def_id).instantiate_identity().skip_norm_wip()
3204 }
3205 rustc_hir::InferDelegation::Sig(_, idx) => {
3206 let delegation_sig = self.tcx().inherit_sig_for_delegation_item(self.item_def_id());
3207
3208 match idx {
3209 hir::InferDelegationSig::Input(idx) => delegation_sig[idx],
3210 hir::InferDelegationSig::Output { .. } => *delegation_sig.last().unwrap(),
3211 }
3212 }
3213 }
3214 }
3215
3216 {}
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",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3217u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_ty")
}> =
::tracing::__macro_support::FieldName::new("hir_ty");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: Ty<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let result_ty =
match &hir_ty.kind {
hir::TyKind::InferDelegation(infer) =>
self.lower_delegation_ty(*infer),
hir::TyKind::Slice(ty) =>
Ty::new_slice(tcx, self.lower_ty(ty)),
hir::TyKind::Ptr(mt) =>
Ty::new_ptr(tcx, self.lower_ty(mt.ty), mt.mutbl),
hir::TyKind::Ref(region, mt) => {
let r =
self.lower_lifetime(region, RegionInferReason::Reference);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3227",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3227u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("r")
}> =
::tracing::__macro_support::FieldName::new("r");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&r)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let t = self.lower_ty(mt.ty);
Ty::new_ref(tcx, r, t, mt.mutbl)
}
hir::TyKind::Never => tcx.types.never,
hir::TyKind::Tup(fields) => {
Ty::new_tup_from_iter(tcx,
fields.iter().map(|t| self.lower_ty(t)))
}
hir::TyKind::FnPtr(bf) => {
check_c_variadic_abi(tcx, bf.decl, bf.abi, hir_ty.span);
Ty::new_fn_ptr(tcx,
self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl,
None, Some(hir_ty)))
}
hir::TyKind::UnsafeBinder(binder) =>
Ty::new_unsafe_binder(tcx,
ty::Binder::bind_with_vars(self.lower_ty(binder.inner_ty),
tcx.late_bound_vars(hir_ty.hir_id))),
hir::TyKind::TraitObject(bounds, tagged_ptr) => {
let lifetime = tagged_ptr.pointer();
let syntax = tagged_ptr.tag();
self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id,
bounds, lifetime, syntax)
}
hir::TyKind::Path(hir::QPath::Resolved(_, path)) if
path.segments.last().and_then(|segment|
segment.args).is_some_and(|args|
{
#[allow(non_exhaustive_omitted_patterns)]
match args.parenthesized {
hir::GenericArgsParentheses::ReturnTypeNotation => true,
_ => false,
}
}) => {
let guar =
self.dcx().emit_err(BadReturnTypeNotation {
span: hir_ty.span,
suggestion: None,
});
Ty::new_error(tcx, guar)
}
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path))
=> {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3269",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3269u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("maybe_qself")
}> =
::tracing::__macro_support::FieldName::new("maybe_qself");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("path")
}> =
::tracing::__macro_support::FieldName::new("path");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&maybe_qself)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let opt_self_ty =
maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
self.lower_resolved_ty_path(opt_self_ty, path,
hir_ty.hir_id, PermitVariants::No)
}
&hir::TyKind::OpaqueDef(opaque_ty) => {
let in_trait =
match opaque_ty.origin {
hir::OpaqueTyOrigin::FnReturn {
parent, in_trait_or_impl: Some(hir::RpitContext::Trait), ..
} | hir::OpaqueTyOrigin::AsyncFn {
parent, in_trait_or_impl: Some(hir::RpitContext::Trait), ..
} => Some(parent),
hir::OpaqueTyOrigin::FnReturn {
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
.. } | hir::OpaqueTyOrigin::AsyncFn {
in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
.. } | hir::OpaqueTyOrigin::TyAlias { .. } => None,
};
self.lower_opaque_ty(opaque_ty.def_id, in_trait)
}
hir::TyKind::TraitAscription(hir_bounds) => {
let self_ty = self.ty_infer(None, hir_ty.span);
let mut bounds = Vec::new();
self.lower_bounds(self_ty, hir_bounds.iter(), &mut bounds,
ty::List::empty(), PredicateFilter::All,
OverlappingAsssocItemConstraints::Allowed);
self.add_implicit_sizedness_bounds(&mut bounds, self_ty,
hir_bounds, ImpliedBoundsContext::AssociatedTypeOrImplTrait,
hir_ty.span);
self.register_trait_ascription_bounds(bounds, hir_ty.hir_id,
hir_ty.span);
self_ty
}
hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty,
segment)) if
segment.args.is_some_and(|args|
{
#[allow(non_exhaustive_omitted_patterns)]
match args.parenthesized {
hir::GenericArgsParentheses::ReturnTypeNotation => true,
_ => false,
}
}) => {
let guar =
if let hir::Node::LetStmt(stmt) =
tcx.parent_hir_node(hir_ty.hir_id) && let None = stmt.init
&&
let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path))
= hir_self_ty.kind &&
let Res::Def(DefKind::Enum | DefKind::Struct |
DefKind::Union, def_id) = self_ty_path.res &&
let Some(_) =
tcx.inherent_impls(def_id).iter().flat_map(|imp|
{
tcx.associated_items(*imp).filter_by_name_unhygienic(segment.ident.name)
}).filter(|assoc|
{
#[allow(non_exhaustive_omitted_patterns)]
match assoc.kind {
ty::AssocKind::Fn { has_self: false, .. } => true,
_ => false,
}
}).next() {
let mut err =
tcx.dcx().struct_span_err(hir_ty.span,
"expected type, found associated function call");
if let Some(between) =
eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
err.span_suggestion_verbose(between,
"use `=` if you meant to assign", " = ",
Applicability::MaybeIncorrect);
}
self.dcx().try_steal_replace_and_emit_err(hir_ty.span,
StashKey::ReturnTypeNotation, err)
} else if let hir::Node::LetStmt(stmt) =
tcx.parent_hir_node(hir_ty.hir_id) && let None = stmt.init
&&
let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path))
= hir_self_ty.kind && let Res::PrimTy(_) = self_ty_path.res
&&
self.dcx().has_stashed_diagnostic(hir_ty.span,
StashKey::ReturnTypeNotation) {
let mut err =
tcx.dcx().struct_span_err(hir_ty.span,
"expected type, found associated function call");
if let Some(between) =
eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
err.span_suggestion_verbose(between,
"use `=` if you meant to assign", " = ",
Applicability::MaybeIncorrect);
}
self.dcx().try_steal_replace_and_emit_err(hir_ty.span,
StashKey::ReturnTypeNotation, err)
} else {
let suggestion =
if self.dcx().has_stashed_diagnostic(hir_ty.span,
StashKey::ReturnTypeNotation) {
Some(segment.ident.span.shrink_to_hi().with_hi(hir_ty.span.hi()))
} else { None };
let err =
self.dcx().create_err(BadReturnTypeNotation {
span: hir_ty.span,
suggestion,
});
self.dcx().try_steal_replace_and_emit_err(hir_ty.span,
StashKey::ReturnTypeNotation, err)
};
Ty::new_error(tcx, guar)
}
hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty,
segment)) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3419",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3419u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_self_ty")
}> =
::tracing::__macro_support::FieldName::new("hir_self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("segment")
}> =
::tracing::__macro_support::FieldName::new("segment");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&segment)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let self_ty = self.lower_ty(hir_self_ty);
self.lower_type_relative_ty_path(self_ty, hir_self_ty,
segment, hir_ty.hir_id, hir_ty.span,
PermitVariants::No).map(|(ty, _, _)|
ty).unwrap_or_else(|guar| Ty::new_error(tcx, guar))
}
hir::TyKind::Array(ty, length) => {
let length = self.lower_const_arg(length, tcx.types.usize);
Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)
}
hir::TyKind::Infer(()) => {
self.ty_infer(None, hir_ty.span)
}
hir::TyKind::Pat(ty, pat) => {
let ty_span = ty.span;
let ty = self.lower_ty(ty);
let pat_ty =
match self.lower_pat_ty_pat(ty, ty_span, pat) {
Ok(kind) => Ty::new_pat(tcx, ty, tcx.mk_pat(kind)),
Err(guar) => Ty::new_error(tcx, guar),
};
self.record_ty(pat.hir_id, ty, pat.span);
pat_ty
}
hir::TyKind::FieldOf(ty, hir::TyFieldPath { variant, field
}) =>
self.lower_field_of(self.lower_ty(ty), self.item_def_id(),
ty.span, hir_ty.hir_id, *variant, *field),
hir::TyKind::View(ty, fields) => {
self.lower_view(self.lower_ty(ty), fields, hir_ty.span)
}
hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
};
self.record_ty(hir_ty.hir_id, result_ty, hir_ty.span);
result_ty
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3217",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3217u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
3218 pub fn lower_ty(&self, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {
3219 let tcx = self.tcx();
3220
3221 let result_ty = match &hir_ty.kind {
3222 hir::TyKind::InferDelegation(infer) => self.lower_delegation_ty(*infer),
3223 hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)),
3224 hir::TyKind::Ptr(mt) => Ty::new_ptr(tcx, self.lower_ty(mt.ty), mt.mutbl),
3225 hir::TyKind::Ref(region, mt) => {
3226 let r = self.lower_lifetime(region, RegionInferReason::Reference);
3227 debug!(?r);
3228 let t = self.lower_ty(mt.ty);
3229 Ty::new_ref(tcx, r, t, mt.mutbl)
3230 }
3231 hir::TyKind::Never => tcx.types.never,
3232 hir::TyKind::Tup(fields) => {
3233 Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t)))
3234 }
3235 hir::TyKind::FnPtr(bf) => {
3236 check_c_variadic_abi(tcx, bf.decl, bf.abi, hir_ty.span);
3237
3238 Ty::new_fn_ptr(
3239 tcx,
3240 self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl, None, Some(hir_ty)),
3241 )
3242 }
3243 hir::TyKind::UnsafeBinder(binder) => Ty::new_unsafe_binder(
3244 tcx,
3245 ty::Binder::bind_with_vars(
3246 self.lower_ty(binder.inner_ty),
3247 tcx.late_bound_vars(hir_ty.hir_id),
3248 ),
3249 ),
3250 hir::TyKind::TraitObject(bounds, tagged_ptr) => {
3251 let lifetime = tagged_ptr.pointer();
3252 let syntax = tagged_ptr.tag();
3253 self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id, bounds, lifetime, syntax)
3254 }
3255 hir::TyKind::Path(hir::QPath::Resolved(_, path))
3259 if path.segments.last().and_then(|segment| segment.args).is_some_and(|args| {
3260 matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
3261 }) =>
3262 {
3263 let guar = self
3264 .dcx()
3265 .emit_err(BadReturnTypeNotation { span: hir_ty.span, suggestion: None });
3266 Ty::new_error(tcx, guar)
3267 }
3268 hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
3269 debug!(?maybe_qself, ?path);
3270 let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
3271 self.lower_resolved_ty_path(opt_self_ty, path, hir_ty.hir_id, PermitVariants::No)
3272 }
3273 &hir::TyKind::OpaqueDef(opaque_ty) => {
3274 let in_trait = match opaque_ty.origin {
3278 hir::OpaqueTyOrigin::FnReturn {
3279 parent,
3280 in_trait_or_impl: Some(hir::RpitContext::Trait),
3281 ..
3282 }
3283 | hir::OpaqueTyOrigin::AsyncFn {
3284 parent,
3285 in_trait_or_impl: Some(hir::RpitContext::Trait),
3286 ..
3287 } => Some(parent),
3288 hir::OpaqueTyOrigin::FnReturn {
3289 in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
3290 ..
3291 }
3292 | hir::OpaqueTyOrigin::AsyncFn {
3293 in_trait_or_impl: None | Some(hir::RpitContext::TraitImpl),
3294 ..
3295 }
3296 | hir::OpaqueTyOrigin::TyAlias { .. } => None,
3297 };
3298
3299 self.lower_opaque_ty(opaque_ty.def_id, in_trait)
3300 }
3301 hir::TyKind::TraitAscription(hir_bounds) => {
3302 let self_ty = self.ty_infer(None, hir_ty.span);
3305 let mut bounds = Vec::new();
3306 self.lower_bounds(
3307 self_ty,
3308 hir_bounds.iter(),
3309 &mut bounds,
3310 ty::List::empty(),
3311 PredicateFilter::All,
3312 OverlappingAsssocItemConstraints::Allowed,
3313 );
3314 self.add_implicit_sizedness_bounds(
3315 &mut bounds,
3316 self_ty,
3317 hir_bounds,
3318 ImpliedBoundsContext::AssociatedTypeOrImplTrait,
3319 hir_ty.span,
3320 );
3321 self.register_trait_ascription_bounds(bounds, hir_ty.hir_id, hir_ty.span);
3322 self_ty
3323 }
3324 hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment))
3328 if segment.args.is_some_and(|args| {
3329 matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
3330 }) =>
3331 {
3332 let guar = if let hir::Node::LetStmt(stmt) = tcx.parent_hir_node(hir_ty.hir_id)
3333 && let None = stmt.init
3334 && let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path)) =
3335 hir_self_ty.kind
3336 && let Res::Def(DefKind::Enum | DefKind::Struct | DefKind::Union, def_id) =
3337 self_ty_path.res
3338 && let Some(_) = tcx
3339 .inherent_impls(def_id)
3340 .iter()
3341 .flat_map(|imp| {
3342 tcx.associated_items(*imp).filter_by_name_unhygienic(segment.ident.name)
3343 })
3344 .filter(|assoc| {
3345 matches!(assoc.kind, ty::AssocKind::Fn { has_self: false, .. })
3346 })
3347 .next()
3348 {
3349 let mut err = tcx.dcx().struct_span_err(
3351 hir_ty.span,
3352 "expected type, found associated function call",
3353 );
3354 if let Some(between) = eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
3355 err.span_suggestion_verbose(
3356 between,
3357 "use `=` if you meant to assign",
3358 " = ",
3359 Applicability::MaybeIncorrect,
3360 );
3361 }
3362 self.dcx().try_steal_replace_and_emit_err(
3363 hir_ty.span,
3364 StashKey::ReturnTypeNotation,
3365 err,
3366 )
3367 } else if let hir::Node::LetStmt(stmt) = tcx.parent_hir_node(hir_ty.hir_id)
3368 && let None = stmt.init
3369 && let hir::TyKind::Path(hir::QPath::Resolved(_, self_ty_path)) =
3370 hir_self_ty.kind
3371 && let Res::PrimTy(_) = self_ty_path.res
3372 && self.dcx().has_stashed_diagnostic(hir_ty.span, StashKey::ReturnTypeNotation)
3373 {
3374 let mut err = tcx.dcx().struct_span_err(
3377 hir_ty.span,
3378 "expected type, found associated function call",
3379 );
3380 if let Some(between) = eq_ctxt_suggestion_span(stmt.pat.span, hir_ty.span) {
3381 err.span_suggestion_verbose(
3382 between,
3383 "use `=` if you meant to assign",
3384 " = ",
3385 Applicability::MaybeIncorrect,
3386 );
3387 }
3388 self.dcx().try_steal_replace_and_emit_err(
3389 hir_ty.span,
3390 StashKey::ReturnTypeNotation,
3391 err,
3392 )
3393 } else {
3394 let suggestion = if self
3395 .dcx()
3396 .has_stashed_diagnostic(hir_ty.span, StashKey::ReturnTypeNotation)
3397 {
3398 Some(segment.ident.span.shrink_to_hi().with_hi(hir_ty.span.hi()))
3404 } else {
3405 None
3406 };
3407 let err = self
3408 .dcx()
3409 .create_err(BadReturnTypeNotation { span: hir_ty.span, suggestion });
3410 self.dcx().try_steal_replace_and_emit_err(
3411 hir_ty.span,
3412 StashKey::ReturnTypeNotation,
3413 err,
3414 )
3415 };
3416 Ty::new_error(tcx, guar)
3417 }
3418 hir::TyKind::Path(hir::QPath::TypeRelative(hir_self_ty, segment)) => {
3419 debug!(?hir_self_ty, ?segment);
3420 let self_ty = self.lower_ty(hir_self_ty);
3421 self.lower_type_relative_ty_path(
3422 self_ty,
3423 hir_self_ty,
3424 segment,
3425 hir_ty.hir_id,
3426 hir_ty.span,
3427 PermitVariants::No,
3428 )
3429 .map(|(ty, _, _)| ty)
3430 .unwrap_or_else(|guar| Ty::new_error(tcx, guar))
3431 }
3432 hir::TyKind::Array(ty, length) => {
3433 let length = self.lower_const_arg(length, tcx.types.usize);
3434 Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length)
3435 }
3436 hir::TyKind::Infer(()) => {
3437 self.ty_infer(None, hir_ty.span)
3442 }
3443 hir::TyKind::Pat(ty, pat) => {
3444 let ty_span = ty.span;
3445 let ty = self.lower_ty(ty);
3446 let pat_ty = match self.lower_pat_ty_pat(ty, ty_span, pat) {
3447 Ok(kind) => Ty::new_pat(tcx, ty, tcx.mk_pat(kind)),
3448 Err(guar) => Ty::new_error(tcx, guar),
3449 };
3450 self.record_ty(pat.hir_id, ty, pat.span);
3451 pat_ty
3452 }
3453 hir::TyKind::FieldOf(ty, hir::TyFieldPath { variant, field }) => self.lower_field_of(
3454 self.lower_ty(ty),
3455 self.item_def_id(),
3456 ty.span,
3457 hir_ty.hir_id,
3458 *variant,
3459 *field,
3460 ),
3461 hir::TyKind::View(ty, fields) => {
3462 self.lower_view(self.lower_ty(ty), fields, hir_ty.span)
3463 }
3464
3465 hir::TyKind::Err(guar) => Ty::new_error(tcx, *guar),
3466 };
3467
3468 self.record_ty(hir_ty.hir_id, result_ty, hir_ty.span);
3469 result_ty
3470 }
3471
3472 fn lower_pat_ty_pat(
3473 &self,
3474 ty: Ty<'tcx>,
3475 ty_span: Span,
3476 pat: &hir::TyPat<'_>,
3477 ) -> Result<ty::PatternKind<'tcx>, ErrorGuaranteed> {
3478 let tcx = self.tcx();
3479 match pat.kind {
3480 hir::TyPatKind::Range(start, end) => {
3481 match ty.kind() {
3482 ty::Int(_) | ty::Uint(_) | ty::Char => {
3485 let start = self.lower_const_arg(start, ty);
3486 let end = self.lower_const_arg(end, ty);
3487 Ok(ty::PatternKind::Range { start, end })
3488 }
3489 _ => Err(self
3490 .dcx()
3491 .span_delayed_bug(ty_span, "invalid base type for range pattern")),
3492 }
3493 }
3494 hir::TyPatKind::NotNull => Ok(ty::PatternKind::NotNull),
3495 hir::TyPatKind::Or(patterns) => {
3496 self.tcx()
3497 .mk_patterns_from_iter(patterns.iter().map(|pat| {
3498 self.lower_pat_ty_pat(ty, ty_span, pat).map(|pat| tcx.mk_pat(pat))
3499 }))
3500 .map(ty::PatternKind::Or)
3501 }
3502 hir::TyPatKind::Err(e) => Err(e),
3503 }
3504 }
3505
3506 fn lower_field_of(
3507 &self,
3508 ty: Ty<'tcx>,
3509 item_def_id: LocalDefId,
3510 ty_span: Span,
3511 hir_id: HirId,
3512 variant: Option<Ident>,
3513 field: Ident,
3514 ) -> Ty<'tcx> {
3515 let dcx = self.dcx();
3516 let tcx = self.tcx();
3517 match ty.kind() {
3518 ty::Adt(def, _) => {
3519 let base_did = def.did();
3520 let kind_name = tcx.def_descr(base_did);
3521 let (variant_idx, variant) = if def.is_enum() {
3522 let Some(variant) = variant else {
3523 let err = dcx
3524 .create_err(NoVariantNamed { span: field.span, ident: field, ty })
3525 .with_span_help(
3526 field.span.shrink_to_lo(),
3527 "you might be missing a variant here: `Variant.`",
3528 )
3529 .emit();
3530 return Ty::new_error(tcx, err);
3531 };
3532
3533 if let Some(res) = def
3534 .variants()
3535 .iter_enumerated()
3536 .find(|(_, f)| f.ident(tcx).normalize_to_macros_2_0() == variant)
3537 {
3538 res
3539 } else {
3540 let err = dcx
3541 .create_err(NoVariantNamed { span: variant.span, ident: variant, ty })
3542 .emit();
3543 return Ty::new_error(tcx, err);
3544 }
3545 } else {
3546 if let Some(variant) = variant {
3547 let adt_path = tcx.def_path_str(base_did);
3548 {
dcx.struct_span_err(variant.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} `{1}` does not have any variants",
kind_name, adt_path))
})).with_code(E0609)
}struct_span_code_err!(
3549 dcx,
3550 variant.span,
3551 E0609,
3552 "{kind_name} `{adt_path}` does not have any variants",
3553 )
3554 .with_span_label(variant.span, "variant unknown")
3555 .emit();
3556 }
3557 (FIRST_VARIANT, def.non_enum_variant())
3558 };
3559 let (ident, def_scope) =
3560 tcx.adjust_ident_and_get_scope(field, def.did(), item_def_id);
3561 if let Some((field_idx, field)) = variant
3562 .fields
3563 .iter_enumerated()
3564 .find(|(_, f)| f.ident(tcx).normalize_to_macros_2_0() == ident)
3565 {
3566 if field.vis.is_accessible_from(def_scope, tcx) {
3567 tcx.check_stability(field.did, Some(hir_id), ident.span, None);
3568 } else {
3569 let adt_path = tcx.def_path_str(base_did);
3570 {
dcx.struct_span_err(ident.span,
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("field `{0}` of {1} `{2}` is private",
ident, kind_name, adt_path))
})).with_code(E0616)
}struct_span_code_err!(
3571 dcx,
3572 ident.span,
3573 E0616,
3574 "field `{ident}` of {kind_name} `{adt_path}` is private",
3575 )
3576 .with_span_label(ident.span, "private field")
3577 .emit();
3578 }
3579 Ty::new_field_representing_type(tcx, ty, variant_idx, field_idx)
3580 } else {
3581 let err =
3582 dcx.create_err(NoFieldOnType { span: ident.span, field: ident, ty }).emit();
3583 Ty::new_error(tcx, err)
3584 }
3585 }
3586 ty::Tuple(tys) => {
3587 let index = match field.as_str().parse::<usize>() {
3588 Ok(idx) => idx,
3589 Err(_) => {
3590 let err =
3591 dcx.create_err(NoFieldOnType { span: field.span, field, ty }).emit();
3592 return Ty::new_error(tcx, err);
3593 }
3594 };
3595 if field.name != sym::integer(index) {
3596 bug_impl(None, format_args!("we parsed above, but now not equal?"),
Location::caller());bug!("we parsed above, but now not equal?");
3597 }
3598 if tys.get(index).is_some() {
3599 Ty::new_field_representing_type(tcx, ty, FIRST_VARIANT, index.into())
3600 } else {
3601 let err = dcx.create_err(NoFieldOnType { span: field.span, field, ty }).emit();
3602 Ty::new_error(tcx, err)
3603 }
3604 }
3605 ty::Alias(..) => Ty::new_error(
3618 tcx,
3619 dcx.span_err(ty_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("could not resolve fields of `{0}`",
ty))
})format!("could not resolve fields of `{ty}`")),
3620 ),
3621 ty::Error(err) => Ty::new_error(tcx, *err),
3622 ty::Bool
3623 | ty::Char
3624 | ty::Int(_)
3625 | ty::Uint(_)
3626 | ty::Float(_)
3627 | ty::Foreign(_)
3628 | ty::Str
3629 | ty::RawPtr(_, _)
3630 | ty::Ref(_, _, _)
3631 | ty::FnDef(_, _)
3632 | ty::FnPtr(_, _)
3633 | ty::UnsafeBinder(_)
3634 | ty::Dynamic(_, _)
3635 | ty::Closure(_, _)
3636 | ty::CoroutineClosure(_, _)
3637 | ty::Coroutine(_, _)
3638 | ty::CoroutineWitness(_, _)
3639 | ty::Never
3640 | ty::Param(_)
3641 | ty::Bound(_, _)
3642 | ty::Placeholder(_)
3643 | ty::Slice(..) => Ty::new_error(
3644 tcx,
3645 dcx.span_err(ty_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("type `{0}` doesn\'t have fields",
ty))
})format!("type `{ty}` doesn't have fields")),
3646 ),
3647 ty::Infer(_) => Ty::new_error(
3648 tcx,
3649 dcx.span_err(ty_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("cannot use `{0}` in this position",
ty))
})format!("cannot use `{ty}` in this position")),
3650 ),
3651 ty::Array(..) | ty::Pat(..) => Ty::new_error(
3653 tcx,
3654 dcx.span_err(ty_span, ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("type `{0}` is not yet supported in `field_of!`",
ty))
})format!("type `{ty}` is not yet supported in `field_of!`")),
3655 ),
3656 }
3657 }
3658
3659 {}
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_opaque_ty",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3660u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_id")
}> =
::tracing::__macro_support::FieldName::new("def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("in_trait")
}> =
::tracing::__macro_support::FieldName::new("in_trait");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&in_trait)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: Ty<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let lifetimes = tcx.opaque_captured_lifetimes(def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3665",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3665u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lifetimes")
}> =
::tracing::__macro_support::FieldName::new("lifetimes");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lifetimes)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let def_id =
if let Some(parent_def_id) = in_trait {
*tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id.to_def_id()).iter().find(|rpitit|
match tcx.opt_rpitit_info(**rpitit) {
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. })
=> {
opaque_def_id.expect_local() == def_id
}
_ =>
::core::panicking::panic("internal error: entered unreachable code"),
}).unwrap()
} else { def_id.to_def_id() };
let generics = tcx.generics_of(def_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3685",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3685u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("generics")
}> =
::tracing::__macro_support::FieldName::new("generics");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&generics)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let offset = generics.count() - lifetimes.len();
let args =
ty::GenericArgs::for_item(tcx, def_id,
|param, _|
{
if let Some(i) = (param.index as usize).checked_sub(offset)
{
let (lifetime, _) = lifetimes[i];
self.lower_resolved_lifetime(lifetime).into()
} else { tcx.mk_param_from_def(param) }
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3701",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3701u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if in_trait.is_some() {
Ty::new_projection_from_args(tcx, ty::IsRigid::No, def_id,
args)
} else {
Ty::new_opaque(tcx, ty::IsRigid::No, def_id, args)
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3660",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3660u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
3661 fn lower_opaque_ty(&self, def_id: LocalDefId, in_trait: Option<LocalDefId>) -> Ty<'tcx> {
3662 let tcx = self.tcx();
3663
3664 let lifetimes = tcx.opaque_captured_lifetimes(def_id);
3665 debug!(?lifetimes);
3666
3667 let def_id = if let Some(parent_def_id) = in_trait {
3671 *tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id.to_def_id())
3672 .iter()
3673 .find(|rpitit| match tcx.opt_rpitit_info(**rpitit) {
3674 Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
3675 opaque_def_id.expect_local() == def_id
3676 }
3677 _ => unreachable!(),
3678 })
3679 .unwrap()
3680 } else {
3681 def_id.to_def_id()
3682 };
3683
3684 let generics = tcx.generics_of(def_id);
3685 debug!(?generics);
3686
3687 let offset = generics.count() - lifetimes.len();
3691
3692 let args = ty::GenericArgs::for_item(tcx, def_id, |param, _| {
3693 if let Some(i) = (param.index as usize).checked_sub(offset) {
3694 let (lifetime, _) = lifetimes[i];
3695 self.lower_resolved_lifetime(lifetime).into()
3697 } else {
3698 tcx.mk_param_from_def(param)
3699 }
3700 });
3701 debug!(?args);
3702
3703 if in_trait.is_some() {
3704 Ty::new_projection_from_args(tcx, ty::IsRigid::No, def_id, args)
3705 } else {
3706 Ty::new_opaque(tcx, ty::IsRigid::No, def_id, args)
3707 }
3708 }
3709
3710 {}
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_ty",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3711u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_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_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: ty::PolyFnSig<'tcx> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx();
let bound_vars = tcx.late_bound_vars(hir_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3723",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3723u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("bound_vars")
}> =
::tracing::__macro_support::FieldName::new("bound_vars");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_vars)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let (input_tys, output_ty) =
self.lower_fn_sig(decl, generics, hir_id, hir_ty);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3727",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3727u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("output_ty")
}> =
::tracing::__macro_support::FieldName::new("output_ty");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output_ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3729",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3729u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("abi")
}> =
::tracing::__macro_support::FieldName::new("abi");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("safety")
}> =
::tracing::__macro_support::FieldName::new("safety");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("decl.fn_decl_kind")
}> =
::tracing::__macro_support::FieldName::new("decl.fn_decl_kind");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("input_tys_len")
}> =
::tracing::__macro_support::FieldName::new("input_tys_len");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&abi)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&safety)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl.fn_decl_kind)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&input_tys.len())
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let fn_sig_kind =
FnSigKind::default().set_abi(abi).set_safety(safety).set_c_variadic(decl.fn_decl_kind.c_variadic()).set_splatted(decl.splatted(),
input_tys.len()).unwrap();
let fn_ty =
tcx.mk_fn_sig(input_tys, output_ty, fn_sig_kind);
let fn_ptr_ty =
ty::Binder::bind_with_vars(fn_ty, bound_vars);
if let Some(hir::Ty {
kind: hir::TyKind::FnPtr(fn_ptr_ty), span, .. }) = hir_ty {
check_abi(tcx, hir_id, *span, fn_ptr_ty.abi);
}
cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi,
fn_ptr_ty);
if !fn_ptr_ty.references_error() {
let inputs = fn_ptr_ty.inputs();
let late_bound_in_args =
tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i|
i.to_owned()));
let output = fn_ptr_ty.output();
let late_bound_in_ret =
tcx.collect_referenced_late_bound_regions(output);
self.validate_late_bound_regions(late_bound_in_args,
late_bound_in_ret,
|br_name|
{
{
self.dcx().struct_span_err(decl.output.span(),
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("return type references {0}, which is not constrained by the fn input types",
br_name))
})).with_code(E0581)
}
});
}
fn_ptr_ty
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:3711",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3711u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::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};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self, hir_id, safety, abi, decl, generics, hir_ty), ret)]
3712 pub fn lower_fn_ty(
3713 &self,
3714 hir_id: HirId,
3715 safety: hir::Safety,
3716 abi: rustc_abi::ExternAbi,
3717 decl: &hir::FnDecl<'_>,
3718 generics: Option<&hir::Generics<'_>>,
3719 hir_ty: Option<&hir::Ty<'_>>,
3720 ) -> ty::PolyFnSig<'tcx> {
3721 let tcx = self.tcx();
3722 let bound_vars = tcx.late_bound_vars(hir_id);
3723 debug!(?bound_vars);
3724
3725 let (input_tys, output_ty) = self.lower_fn_sig(decl, generics, hir_id, hir_ty);
3726
3727 debug!(?output_ty);
3728
3729 debug!(?abi, ?safety, ?decl.fn_decl_kind, input_tys_len = ?input_tys.len());
3730 let fn_sig_kind = FnSigKind::default()
3731 .set_abi(abi)
3732 .set_safety(safety)
3733 .set_c_variadic(decl.fn_decl_kind.c_variadic())
3734 .set_splatted(decl.splatted(), input_tys.len())
3735 .unwrap();
3736 let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, fn_sig_kind);
3737 let fn_ptr_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
3738
3739 if let Some(hir::Ty { kind: hir::TyKind::FnPtr(fn_ptr_ty), span, .. }) = hir_ty {
3740 check_abi(tcx, hir_id, *span, fn_ptr_ty.abi);
3741 }
3742
3743 cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, fn_ptr_ty);
3745
3746 if !fn_ptr_ty.references_error() {
3747 let inputs = fn_ptr_ty.inputs();
3754 let late_bound_in_args =
3755 tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
3756 let output = fn_ptr_ty.output();
3757 let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
3758
3759 self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
3760 struct_span_code_err!(
3761 self.dcx(),
3762 decl.output.span(),
3763 E0581,
3764 "return type references {}, which is not constrained by the fn input types",
3765 br_name
3766 )
3767 });
3768 }
3769
3770 fn_ptr_ty
3771 }
3772
3773 pub(super) fn suggest_trait_fn_ty_for_impl_fn_infer(
3778 &self,
3779 fn_hir_id: HirId,
3780 arg_idx: Option<usize>,
3781 ) -> Option<Ty<'tcx>> {
3782 let tcx = self.tcx();
3783 let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
3784 tcx.hir_node(fn_hir_id)
3785 else {
3786 return None;
3787 };
3788 let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl();
3789
3790 let trait_ref = self.lower_impl_trait_ref(&i.of_trait?.trait_ref, self.lower_ty(i.self_ty));
3791
3792 let assoc = tcx.associated_items(trait_ref.def_id).find_by_ident_and_kind(
3793 tcx,
3794 *ident,
3795 ty::AssocTag::Fn,
3796 trait_ref.def_id,
3797 )?;
3798
3799 let fn_sig = tcx
3800 .fn_sig(assoc.def_id)
3801 .instantiate(
3802 tcx,
3803 trait_ref
3804 .args
3805 .extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
3806 )
3807 .skip_norm_wip();
3808 let fn_sig = tcx.liberate_late_bound_regions(fn_hir_id.expect_owner().to_def_id(), fn_sig);
3809
3810 Some(if let Some(arg_idx) = arg_idx {
3811 *fn_sig.inputs().get(arg_idx)?
3812 } else {
3813 fn_sig.output()
3814 })
3815 }
3816
3817 {}
#[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("validate_late_bound_regions",
"rustc_hir_analysis::hir_ty_lowering",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs"),
::tracing_core::__macro_support::Option::Some(3817u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_analysis::hir_ty_lowering"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("constrained_regions")
}> =
::tracing::__macro_support::FieldName::new("constrained_regions");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("referenced_regions")
}> =
::tracing::__macro_support::FieldName::new("referenced_regions");
NAME.as_str()
}], ::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};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&constrained_regions)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&referenced_regions)
as &dyn ::tracing::field::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;
}
{
for br in referenced_regions.difference(&constrained_regions) {
let br_name =
if let Some(name) = br.get_name(self.tcx()) {
::alloc::__export::must_use({
::alloc::fmt::format(format_args!("lifetime `{0}`", name))
})
} else { "an anonymous lifetime".to_string() };
let mut err = generate_err(&br_name);
if !br.is_named(self.tcx()) {
err.note("lifetimes appearing in an associated or opaque type are not considered constrained");
err.note("consider introducing a named lifetime parameter");
}
err.emit();
}
}
}
}#[instrument(level = "trace", skip(self, generate_err))]
3818 fn validate_late_bound_regions<'cx>(
3819 &'cx self,
3820 constrained_regions: FxIndexSet<ty::BoundRegionKind<'tcx>>,
3821 referenced_regions: FxIndexSet<ty::BoundRegionKind<'tcx>>,
3822 generate_err: impl Fn(&str) -> Diag<'cx>,
3823 ) {
3824 for br in referenced_regions.difference(&constrained_regions) {
3825 let br_name = if let Some(name) = br.get_name(self.tcx()) {
3826 format!("lifetime `{name}`")
3827 } else {
3828 "an anonymous lifetime".to_string()
3829 };
3830
3831 let mut err = generate_err(&br_name);
3832
3833 if !br.is_named(self.tcx()) {
3834 err.note(
3841 "lifetimes appearing in an associated or opaque type are not considered constrained",
3842 );
3843 err.note("consider introducing a named lifetime parameter");
3844 }
3845
3846 err.emit();
3847 }
3848 }
3849
3850 fn construct_const_ctor_value(
3851 &self,
3852 ctor_def_id: DefId,
3853 ctor_of: CtorOf,
3854 args: GenericArgsRef<'tcx>,
3855 ) -> Const<'tcx> {
3856 let tcx = self.tcx();
3857 let parent_did = tcx.parent(ctor_def_id);
3858
3859 let adt_def = tcx.adt_def(match ctor_of {
3860 CtorOf::Variant => tcx.parent(parent_did),
3861 CtorOf::Struct => parent_did,
3862 });
3863
3864 let variant_idx = adt_def.variant_index_with_id(parent_did);
3865
3866 let valtree = if adt_def.is_enum() {
3867 let discr = ty::ValTree::from_scalar_int(tcx, variant_idx.as_u32().into());
3868 ty::ValTree::from_branches(tcx, [ty::Const::new_value(tcx, discr, tcx.types.u32)])
3869 } else {
3870 ty::ValTree::zst(tcx)
3871 };
3872
3873 let adt_ty = Ty::new_adt(tcx, adt_def, args);
3874 ty::Const::new_value(tcx, valtree, adt_ty)
3875 }
3876
3877 fn lower_view(&self, inner_ty: Ty<'tcx>, fields: &[Ident], ty_span: Span) -> Ty<'tcx> {
3878 let mut viewed_fields = Vec::<Ident>::with_capacity(fields.len());
3881
3882 for f in fields {
3883 let f = f.normalize_to_macros_2_0();
3884 if let Some(previous_field_span) =
3886 viewed_fields.iter().find_map(|f_| (*f_ == f).then_some(f_.span))
3887 {
3888 self.dcx().emit_err(diagnostics::ViewedFieldIsAlreadyPartOfTheView {
3889 name: f.name,
3890 span: f.span,
3891 previous_field_span,
3892 });
3893 continue;
3894 }
3895 viewed_fields.push(f);
3896 }
3897
3898 let variant = match inner_ty.kind() {
3900 ty::Adt(def, _) if def.is_struct() => def.non_enum_variant(),
3901
3902 ty::Adt(def, _) => {
3903 let guar = self.dcx().emit_err(diagnostics::OnlyStructsCanBeViewedAdt {
3904 ty: inner_ty,
3905 span: ty_span,
3906 article: def.article(),
3907 kind: def.descr(),
3908 });
3909 return Ty::new_error(self.tcx(), guar);
3910 }
3911
3912 _ => {
3913 let guar = self.dcx().emit_err(diagnostics::OnlyStructsCanBeViewedNonAdt {
3914 ty: inner_ty,
3915 span: ty_span,
3916 });
3917 return Ty::new_error(self.tcx(), guar);
3918 }
3919 };
3920
3921 let mut viewed_indices = Vec::with_capacity(viewed_fields.len());
3923 let mut error = None;
3924 for field in viewed_fields {
3925 let Some((_, field)) = variant
3926 .fields
3927 .iter_enumerated()
3928 .find(|(_, f)| f.ident(self.tcx()).normalize_to_macros_2_0() == field)
3929 else {
3930 let err =
3931 self.dcx().emit_err(NoFieldOnType { span: field.span, field, ty: inner_ty });
3932 error = Some(err);
3933 continue;
3934 };
3935
3936 viewed_indices.push(field);
3937 }
3938 if let Some(guar) = error {
3939 return Ty::new_error(self.tcx(), guar);
3940 }
3941
3942 inner_ty
3944 }
3945}