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