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