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