1#![allow(rustc::usage_of_ty_tykind)]
4
5use std::borrow::Cow;
6use std::debug_assert_matches;
7use std::ops::{ControlFlow, Range};
8
9use hir::def::{CtorKind, DefKind};
10use rustc_abi::{FIRST_VARIANT, FieldIdx, NumScalableVectors, ScalableElt, VariantIdx};
11use rustc_attr_ir::lang_items::LangItem;
12use rustc_errors::{ErrorGuaranteed, MultiSpan};
13use rustc_hir as hir;
14use rustc_hir::def_id::DefId;
15use rustc_macros::{StableHash, TyDecodable, TyEncodable, TypeFoldable, extension};
16use rustc_span::{DUMMY_SP, Span, Symbol, bug, kw, sym};
17use rustc_type_ir::TyKind::*;
18use rustc_type_ir::solve::SizedTraitKind;
19use rustc_type_ir::walk::TypeWalker;
20use rustc_type_ir::{
21 self as ir, BoundVar, CallerBoundsIterator, CollectAndApply, MayBeErased, TypeVisitableExt,
22 elaborate,
23};
24use tracing::instrument;
25use ty::util::IntTypeExt;
26
27use super::{AdtFlags, GenericParamDefKind};
28use crate::infer::canonical::Canonical;
29use crate::traits::ObligationCause;
30use crate::ty::InferTy::*;
31use crate::ty::{
32 self, AdtDef, Const, Discr, GenericArg, GenericArgs, List, ParamEnv, Region, Ty, TyCtxt,
33 TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, ValTree,
34};
35
36#[rustc_diagnostic_item = "TyKind"]
38pub type TyKind<'tcx> = ir::TyKind<TyCtxt<'tcx>>;
39pub type TypeAndMut<'tcx> = ir::TypeAndMut<TyCtxt<'tcx>>;
40pub type AliasTy<'tcx> = ir::AliasTy<TyCtxt<'tcx>>;
41pub type AliasTyKind<'tcx> = ir::AliasTyKind<TyCtxt<'tcx>>;
42pub type Alias<'tcx, K> = ir::Alias<TyCtxt<'tcx>, K>;
43pub type ProjectionAliasTy<'tcx> = ir::ProjectionAliasTy<TyCtxt<'tcx>>;
44pub type InherentAliasTy<'tcx> = ir::InherentAliasTy<TyCtxt<'tcx>>;
45pub type OpaqueAliasTy<'tcx> = ir::OpaqueAliasTy<TyCtxt<'tcx>>;
46pub type FreeAliasTy<'tcx> = ir::FreeAliasTy<TyCtxt<'tcx>>;
47pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>;
48pub type FnSigKind<'tcx> = ir::FnSigKind<TyCtxt<'tcx>>;
49pub type Binder<'tcx, T> = ir::Binder<TyCtxt<'tcx>, T>;
50pub type EarlyBinder<'tcx, T> = ir::EarlyBinder<TyCtxt<'tcx>, T>;
51pub type Unnormalized<'tcx, T> = ir::Unnormalized<TyCtxt<'tcx>, T>;
52pub type TypingMode<'tcx, S = MayBeErased> = ir::TypingMode<TyCtxt<'tcx>, S>;
53pub type TypingModeEqWrapper<'tcx> = ir::TypingModeEqWrapper<TyCtxt<'tcx>>;
54pub type Placeholder<'tcx, T> = ir::Placeholder<TyCtxt<'tcx>, T>;
55pub type PlaceholderRegion<'tcx> = ir::PlaceholderRegion<TyCtxt<'tcx>>;
56pub type PlaceholderType<'tcx> = ir::PlaceholderType<TyCtxt<'tcx>>;
57pub type PlaceholderConst<'tcx> = ir::PlaceholderConst<TyCtxt<'tcx>>;
58pub type BoundTy<'tcx> = ir::BoundTy<TyCtxt<'tcx>>;
59pub type BoundConst<'tcx> = ir::BoundConst<TyCtxt<'tcx>>;
60pub type BoundRegion<'tcx> = ir::BoundRegion<TyCtxt<'tcx>>;
61pub type BoundVariableKind<'tcx> = ir::BoundVariableKind<TyCtxt<'tcx>>;
62pub type BoundRegionKind<'tcx> = ir::BoundRegionKind<TyCtxt<'tcx>>;
63pub type BoundTyKind<'tcx> = ir::BoundTyKind<TyCtxt<'tcx>>;
64
65pub trait Article {
66 fn article(&self) -> &'static str;
67}
68
69impl<'tcx> Article for TyKind<'tcx> {
70 fn article(&self) -> &'static str {
72 match self {
73 Int(_) | Float(_) | Array(_, _) => "an",
74 Adt(def, _) if def.is_enum() => "an",
75 Error(_) => "a",
78 _ => "a",
79 }
80 }
81}
82
83pub trait CoroutineArgsExt<'tcx> {
#[doc = " Coroutine has not been resumed yet."]
const UNRESUMED: usize;
#[doc = " Coroutine has returned or is completed."]
const RETURNED: usize;
#[doc = " Coroutine has been poisoned."]
const POISONED: usize;
#[doc =
" Number of variants to reserve in coroutine state. Corresponds to"]
#[doc =
" `UNRESUMED` (beginning of a coroutine) and `RETURNED`/`POISONED`"]
#[doc = " (end of a coroutine) states."]
const RESERVED_VARIANTS: usize;
const UNRESUMED_NAME: &'static str;
const RETURNED_NAME: &'static str;
const POISONED_NAME: &'static str;
#[doc = " The valid variant indices of this coroutine."]
fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> Range<VariantIdx>;
#[doc =
" The discriminant for the given variant. Panics if the `variant_index` is"]
#[doc = " out of range."]
fn discriminant_for_variant(&self, def_id: DefId, tcx: TyCtxt<'tcx>,
variant_index: VariantIdx)
-> Discr<'tcx>;
#[doc =
" The set of all discriminants for the coroutine, enumerated with their"]
#[doc = " variant indices."]
fn discriminants(self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> impl Iterator<Item = (VariantIdx, Discr<'tcx>)>;
#[doc =
" Calls `f` with a reference to the name of the enumerator for the given"]
#[doc = " variant `v`."]
fn variant_name(v: VariantIdx)
-> Cow<'static, str>;
#[doc = " The type of the state discriminant used in the coroutine type."]
fn discr_ty(&self, tcx: TyCtxt<'tcx>)
-> Ty<'tcx>;
#[doc =
" This returns the types of the MIR locals which had to be stored across suspension points."]
#[doc =
" It is calculated in rustc_mir_transform::coroutine::StateTransform."]
#[doc = " All the types here must be in the tuple in CoroutineInterior."]
#[doc = ""]
#[doc =
" The locals are grouped by their variant number. Note that some locals may"]
#[doc = " be repeated in multiple variants."]
fn state_tys(self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> impl Iterator<Item : Iterator<Item = Ty<'tcx>>>;
}
impl<'tcx> CoroutineArgsExt<'tcx> for ty::CoroutineArgs<TyCtxt<'tcx>> {
#[doc = " Coroutine has not been resumed yet."]
const UNRESUMED: usize = 0;
#[doc = " Coroutine has returned or is completed."]
const RETURNED: usize = 1;
#[doc = " Coroutine has been poisoned."]
const POISONED: usize = 2;
#[doc =
" Number of variants to reserve in coroutine state. Corresponds to"]
#[doc =
" `UNRESUMED` (beginning of a coroutine) and `RETURNED`/`POISONED`"]
#[doc = " (end of a coroutine) states."]
const RESERVED_VARIANTS: usize = 3;
const UNRESUMED_NAME: &'static str = "Unresumed";
const RETURNED_NAME: &'static str = "Returned";
const POISONED_NAME: &'static str = "Panicked";
#[doc = " The valid variant indices of this coroutine."]
#[inline]
fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> Range<VariantIdx> {
FIRST_VARIANT..tcx.coroutine_layout(def_id,
self.args).unwrap().variant_fields.next_index()
}
#[doc =
" The discriminant for the given variant. Panics if the `variant_index` is"]
#[doc = " out of range."]
#[inline]
fn discriminant_for_variant(&self, def_id: DefId, tcx: TyCtxt<'tcx>,
variant_index: VariantIdx) -> Discr<'tcx> {
if !self.variant_range(def_id, tcx).contains(&variant_index) {
::core::panicking::panic("assertion failed: self.variant_range(def_id, tcx).contains(&variant_index)")
};
Discr {
val: variant_index.as_usize() as u128,
ty: self.discr_ty(tcx),
}
}
#[doc =
" The set of all discriminants for the coroutine, enumerated with their"]
#[doc = " variant indices."]
#[inline]
fn discriminants(self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> {
self.variant_range(def_id,
tcx).map(move |index|
{
(index,
Discr {
val: index.as_usize() as u128,
ty: self.discr_ty(tcx),
})
})
}
#[doc =
" Calls `f` with a reference to the name of the enumerator for the given"]
#[doc = " variant `v`."]
fn variant_name(v: VariantIdx) -> Cow<'static, str> {
match v.as_usize() {
Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
Self::RETURNED => Cow::from(Self::RETURNED_NAME),
Self::POISONED => Cow::from(Self::POISONED_NAME),
_ =>
Cow::from(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("Suspend{0}",
v.as_usize() - Self::RESERVED_VARIANTS))
})),
}
}
#[doc = " The type of the state discriminant used in the coroutine type."]
#[inline]
fn discr_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { tcx.types.u32 }
#[doc =
" This returns the types of the MIR locals which had to be stored across suspension points."]
#[doc =
" It is calculated in rustc_mir_transform::coroutine::StateTransform."]
#[doc = " All the types here must be in the tuple in CoroutineInterior."]
#[doc = ""]
#[doc =
" The locals are grouped by their variant number. Note that some locals may"]
#[doc = " be repeated in multiple variants."]
#[inline]
fn state_tys(self, def_id: DefId, tcx: TyCtxt<'tcx>)
-> impl Iterator<Item : Iterator<Item = Ty<'tcx>>> {
let layout = tcx.coroutine_layout(def_id, self.args).unwrap();
layout.variant_fields.iter().map(move |variant|
{
variant.iter().map(move |field|
{
if tcx.is_async_drop_in_place_coroutine(def_id) {
layout.field_tys[*field].ty
} else {
ty::EarlyBinder::bind(tcx,
layout.field_tys[*field].ty).instantiate(tcx,
self.args).skip_norm_wip()
}
})
})
}
}#[extension(pub trait CoroutineArgsExt<'tcx>)]
84impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
85 const UNRESUMED: usize = 0;
87 const RETURNED: usize = 1;
89 const POISONED: usize = 2;
91 const RESERVED_VARIANTS: usize = 3;
95
96 const UNRESUMED_NAME: &'static str = "Unresumed";
97 const RETURNED_NAME: &'static str = "Returned";
98 const POISONED_NAME: &'static str = "Panicked";
99
100 #[inline]
102 fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
103 FIRST_VARIANT..tcx.coroutine_layout(def_id, self.args).unwrap().variant_fields.next_index()
105 }
106
107 #[inline]
110 fn discriminant_for_variant(
111 &self,
112 def_id: DefId,
113 tcx: TyCtxt<'tcx>,
114 variant_index: VariantIdx,
115 ) -> Discr<'tcx> {
116 assert!(self.variant_range(def_id, tcx).contains(&variant_index));
119 Discr { val: variant_index.as_usize() as u128, ty: self.discr_ty(tcx) }
120 }
121
122 #[inline]
125 fn discriminants(
126 self,
127 def_id: DefId,
128 tcx: TyCtxt<'tcx>,
129 ) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> {
130 self.variant_range(def_id, tcx).map(move |index| {
131 (index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) })
132 })
133 }
134
135 fn variant_name(v: VariantIdx) -> Cow<'static, str> {
138 match v.as_usize() {
139 Self::UNRESUMED => Cow::from(Self::UNRESUMED_NAME),
140 Self::RETURNED => Cow::from(Self::RETURNED_NAME),
141 Self::POISONED => Cow::from(Self::POISONED_NAME),
142 _ => Cow::from(format!("Suspend{}", v.as_usize() - Self::RESERVED_VARIANTS)),
143 }
144 }
145
146 #[inline]
148 fn discr_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
149 tcx.types.u32
150 }
151
152 #[inline]
159 fn state_tys(
160 self,
161 def_id: DefId,
162 tcx: TyCtxt<'tcx>,
163 ) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>>> {
164 let layout = tcx.coroutine_layout(def_id, self.args).unwrap();
165 layout.variant_fields.iter().map(move |variant| {
166 variant.iter().map(move |field| {
167 if tcx.is_async_drop_in_place_coroutine(def_id) {
168 layout.field_tys[*field].ty
169 } else {
170 ty::EarlyBinder::bind(tcx, layout.field_tys[*field].ty)
171 .instantiate(tcx, self.args)
172 .skip_norm_wip()
173 }
174 })
175 })
176 }
177}
178
179#[derive(#[automatically_derived]impl<'tcx> ::core::fmt::Debug for UpvarArgs<'tcx> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Closure(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Closure", &__self_0),
Self::Coroutine(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Coroutine", &__self_0),
Self::CoroutineClosure(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"CoroutineClosure", &__self_0),
}
}
}Debug, #[automatically_derived]impl<'tcx> ::core::marker::Copy for UpvarArgs<'tcx> {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
::core::clone::TrivialClone for UpvarArgs<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for UpvarArgs<'tcx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<GenericArgs<'tcx>>;
let _: ::core::clone::AssertParamIsClone<GenericArgs<'tcx>>;
let _: ::core::clone::AssertParamIsClone<GenericArgs<'tcx>>;
*self
}
}Clone, const _: () =
{
impl<'tcx> ::rustc_data_structures::stable_hash::StableHash for
UpvarArgs<'tcx> {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
UpvarArgs::Closure(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
UpvarArgs::Coroutine(ref __binding_0) =>
1u8.stable_hash(__hcx, __hasher),
UpvarArgs::CoroutineClosure(ref __binding_0) =>
2u8.stable_hash(__hcx, __hasher),
}
match *self {
UpvarArgs::Closure(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
UpvarArgs::Coroutine(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
UpvarArgs::CoroutineClosure(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for UpvarArgs<'tcx> {
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 {
UpvarArgs::Closure(__binding_0) => {
UpvarArgs::Closure(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
UpvarArgs::Coroutine(__binding_0) => {
UpvarArgs::Coroutine(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
UpvarArgs::CoroutineClosure(__binding_0) => {
UpvarArgs::CoroutineClosure(::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?)
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
UpvarArgs::Closure(__binding_0) => {
UpvarArgs::Closure(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
UpvarArgs::Coroutine(__binding_0) => {
UpvarArgs::Coroutine(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
UpvarArgs::CoroutineClosure(__binding_0) => {
UpvarArgs::CoroutineClosure(::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder))
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for UpvarArgs<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
UpvarArgs::Closure(ref __binding_0) => {
{
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);
}
}
}
}
UpvarArgs::Coroutine(ref __binding_0) => {
{
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);
}
}
}
}
UpvarArgs::CoroutineClosure(ref __binding_0) => {
{
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);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
180pub enum UpvarArgs<'tcx> {
181 Closure(GenericArgs<'tcx>),
182 Coroutine(GenericArgs<'tcx>),
183 CoroutineClosure(GenericArgs<'tcx>),
184}
185
186impl<'tcx> UpvarArgs<'tcx> {
187 #[inline]
191 pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
192 match self.tupled_upvars_ty().kind() {
193 TyKind::Error(_) => ty::List::empty(),
194 TyKind::Tuple(args) => args,
195 TyKind::Infer(_) => ::rustc_span::macros::bug_impl(None,
format_args!("upvar_tys called before capture types are inferred"),
Location::caller())bug!("upvar_tys called before capture types are inferred"),
196 ty => ::rustc_span::macros::bug_impl(None,
format_args!("Unexpected representation of upvar types tuple {0:?}", ty),
Location::caller())bug!("Unexpected representation of upvar types tuple {:?}", ty),
197 }
198 }
199
200 #[inline]
201 pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
202 match self {
203 UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(),
204 UpvarArgs::Coroutine(args) => args.as_coroutine().tupled_upvars_ty(),
205 UpvarArgs::CoroutineClosure(args) => args.as_coroutine_closure().tupled_upvars_ty(),
206 }
207 }
208}
209
210#[derive(#[automatically_derived]impl<'tcx> ::core::marker::Copy for
InlineConstArgs<'tcx> {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
::core::clone::TrivialClone for InlineConstArgs<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for
InlineConstArgs<'tcx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<GenericArgs<'tcx>>;
*self
}
}Clone, #[automatically_derived]impl<'tcx> ::core::fmt::Debug for
InlineConstArgs<'tcx> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"InlineConstArgs args", &&self.args)
}
}Debug)]
225pub struct InlineConstArgs<'tcx> {
226 pub args: GenericArgs<'tcx>,
229}
230
231pub struct InlineConstArgsParts<'tcx, 'a, T> {
233 pub parent_args: &'a [GenericArg<'tcx>],
234 pub ty: T,
235}
236
237impl<'tcx> InlineConstArgs<'tcx> {
238 pub fn new(
240 tcx: TyCtxt<'tcx>,
241 parts: InlineConstArgsParts<'tcx, '_, Ty<'tcx>>,
242 ) -> InlineConstArgs<'tcx> {
243 InlineConstArgs {
244 args: tcx.mk_args_from_iter(
245 parts.parent_args.iter().copied().chain(std::iter::once(parts.ty.into())),
246 ),
247 }
248 }
249
250 fn split(&self) -> InlineConstArgsParts<'tcx, '_, GenericArg<'tcx>> {
253 match self.args.as_slice() {
254 [parent_args @ .., ty] => InlineConstArgsParts { parent_args, ty: *ty },
255 _ => ::rustc_span::macros::bug_impl(None,
format_args!("inline const args missing synthetics"), Location::caller())bug!("inline const args missing synthetics"),
256 }
257 }
258
259 pub fn parent_args(&self) -> &[GenericArg<'tcx>] {
261 self.split().parent_args
262 }
263
264 pub fn ty(self) -> Ty<'tcx> {
266 self.split().ty.expect_ty()
267 }
268}
269
270pub type PolyFnSig<'tcx> = Binder<'tcx, FnSig<'tcx>>;
271pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<'tcx, FnSig<'tcx>>>;
272
273#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ParamTy {
}
#[automatically_derived]impl ::core::clone::Clone for ParamTy {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for ParamTy { }Copy, #[automatically_derived]impl ::core::marker::StructuralPartialEq for ParamTy {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ParamTy {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.index == other.index && self.name == other.name
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ParamTy {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u32>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for ParamTy {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for ParamTy {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.index, &other.index) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.name, &other.name),
cmp => cmp,
}
}
}Ord, #[automatically_derived]impl ::core::hash::Hash for ParamTy {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.index, state);
::core::hash::Hash::hash(&self.name, state)
}
}Hash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ParamTy {
fn encode(&self, __encoder: &mut __E) {
let ParamTy { index: ref __binding_0, name: ref __binding_1
} = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ParamTy {
fn decode(__decoder: &mut __D) -> Self {
ParamTy {
index: ::rustc_serialize::Decodable::decode(__decoder),
name: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
274#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ParamTy {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ParamTy { index: ref __binding_0, name: ref __binding_1 } =>
{
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
275pub struct ParamTy {
276 pub index: u32,
277 pub name: Symbol,
278}
279
280impl rustc_type_ir::inherent::ParamLike for ParamTy {
281 fn index(self) -> u32 {
282 self.index
283 }
284}
285
286impl<'tcx> ParamTy {
287 pub fn new(index: u32, name: Symbol) -> ParamTy {
288 ParamTy { index, name }
289 }
290
291 pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
292 ParamTy::new(def.index, def.name)
293 }
294
295 #[inline]
296 pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
297 Ty::new_param(tcx, self.index, self.name)
298 }
299
300 pub fn span_from_generics(self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span {
301 let generics = tcx.generics_of(item_with_generics);
302 let type_param = generics.type_param(self, tcx);
303 tcx.def_span(type_param.def_id)
304 }
305}
306
307#[derive(#[automatically_derived]impl ::core::marker::Copy for ParamConst { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ParamConst {
}
#[automatically_derived]impl ::core::clone::Clone for ParamConst {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u32>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]impl ::core::hash::Hash for ParamConst {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.index, state);
::core::hash::Hash::hash(&self.name, state)
}
}Hash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for ParamConst {
fn encode(&self, __encoder: &mut __E) {
let ParamConst { index: ref __binding_0, name: ref __binding_1
} = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for ParamConst {
fn decode(__decoder: &mut __D) -> Self {
ParamConst {
index: ::rustc_serialize::Decodable::decode(__decoder),
name: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable, #[automatically_derived]impl ::core::cmp::Eq for ParamConst {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u32>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ParamConst {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ParamConst {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.index == other.index && self.name == other.name
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Ord for ParamConst {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
match ::core::cmp::Ord::cmp(&self.index, &other.index) {
::core::cmp::Ordering::Equal =>
::core::cmp::Ord::cmp(&self.name, &other.name),
cmp => cmp,
}
}
}Ord, #[automatically_derived]impl ::core::cmp::PartialOrd for ParamConst {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd)]
308#[derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ParamConst {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ParamConst { index: ref __binding_0, name: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash)]
309pub struct ParamConst {
310 pub index: u32,
311 pub name: Symbol,
312}
313
314impl rustc_type_ir::inherent::ParamLike for ParamConst {
315 fn index(self) -> u32 {
316 self.index
317 }
318}
319
320impl ParamConst {
321 pub fn new(index: u32, name: Symbol) -> ParamConst {
322 ParamConst { index, name }
323 }
324
325 pub fn for_def(def: &ty::GenericParamDef) -> ParamConst {
326 ParamConst::new(def.index, def.name)
327 }
328
329 {}
#[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("find_const_ty_from_env",
"rustc_middle::ty::sty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5df8c02afdf6b882bc301442cea70f026e3d3974/compiler/rustc_middle/src/ty/sty.rs"),
::tracing_core::__macro_support::Option::Some(329u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::sty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self")
}> =
::tracing::__macro_support::FieldName::new("self");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("env")
}> =
::tracing::__macro_support::FieldName::new("env");
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(&self)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&env)
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: Ty<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let mut candidates =
env.caller_bounds().non_trait_clauses().iter().filter_map(|clause|
{
match clause.kind().skip_binder() {
ty::ClauseKind::ConstArgHasType(param_ct, ty) => {
if !!(param_ct, ty).has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !(param_ct, ty).has_escaping_bound_vars()")
};
match param_ct.kind() {
ty::ConstKind::Param(param_ct) if
param_ct.index == self.index => Some(ty),
_ => None,
}
}
_ => None,
}
});
let ty =
candidates.next().unwrap_or_else(||
{
::rustc_span::macros::bug_impl(None,
format_args!("cannot find `{0:?}` in param-env: {1:#?}",
self, env), Location::caller());
});
if !candidates.next().is_none() {
{
::core::panicking::panic_fmt(format_args!("did not expect duplicate `ConstParamHasTy` for `{0:?}` in param-env: {1:#?}",
self, env));
}
};
ty
}
}
}#[instrument(level = "debug")]
330 pub fn find_const_ty_from_env<'tcx>(self, env: ParamEnv<'tcx>) -> Ty<'tcx> {
331 let mut candidates = env.caller_bounds().non_trait_clauses().iter().filter_map(|clause| {
332 match clause.kind().skip_binder() {
334 ty::ClauseKind::ConstArgHasType(param_ct, ty) => {
335 assert!(!(param_ct, ty).has_escaping_bound_vars());
336
337 match param_ct.kind() {
338 ty::ConstKind::Param(param_ct) if param_ct.index == self.index => Some(ty),
339 _ => None,
340 }
341 }
342 _ => None,
343 }
344 });
345
346 let ty = candidates.next().unwrap_or_else(|| {
353 bug!("cannot find `{self:?}` in param-env: {env:#?}");
354 });
355 assert!(
356 candidates.next().is_none(),
357 "did not expect duplicate `ConstParamHasTy` for `{self:?}` in param-env: {env:#?}"
358 );
359 ty
360 }
361}
362
363impl<'tcx> Ty<'tcx> {
365 #[inline]
368 fn new(tcx: TyCtxt<'tcx>, st: TyKind<'tcx>) -> Ty<'tcx> {
369 tcx.mk_ty_from_kind(st)
370 }
371
372 #[inline]
373 pub fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferTy) -> Ty<'tcx> {
374 Ty::new(tcx, TyKind::Infer(infer))
375 }
376
377 #[inline]
378 pub fn new_var(tcx: TyCtxt<'tcx>, v: ty::TyVid) -> Ty<'tcx> {
379 tcx.types
381 .infer_ty_vars
382 .get(v.as_usize())
383 .copied()
384 .unwrap_or_else(|| Ty::new(tcx, Infer(TyVar(v))))
385 }
386
387 #[inline]
388 pub fn new_int_var(tcx: TyCtxt<'tcx>, v: ty::IntVid) -> Ty<'tcx> {
389 Ty::new_infer(tcx, IntVar(v))
390 }
391
392 #[inline]
393 pub fn new_float_var(tcx: TyCtxt<'tcx>, v: ty::FloatVid) -> Ty<'tcx> {
394 Ty::new_infer(tcx, FloatVar(v))
395 }
396
397 #[inline]
398 pub fn new_fresh(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
399 tcx.types
401 .infer_fresh_tys
402 .get(n as usize)
403 .copied()
404 .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshTy(n)))
405 }
406
407 #[inline]
408 pub fn new_fresh_int(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
409 tcx.types
411 .infer_fresh_int_tys
412 .get(n as usize)
413 .copied()
414 .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshIntTy(n)))
415 }
416
417 #[inline]
418 pub fn new_fresh_float(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> {
419 tcx.types
421 .infer_fresh_float_tys
422 .get(n as usize)
423 .copied()
424 .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshFloatTy(n)))
425 }
426
427 #[inline]
428 pub fn new_param(tcx: TyCtxt<'tcx>, index: u32, name: Symbol) -> Ty<'tcx> {
429 Ty::new(tcx, Param(ParamTy { index, name }))
430 }
431
432 #[inline]
433 pub fn new_bound(
434 tcx: TyCtxt<'tcx>,
435 index: ty::DebruijnIndex,
436 bound_ty: ty::BoundTy<'tcx>,
437 ) -> Ty<'tcx> {
438 if let ty::BoundTy { var, kind: ty::BoundTyKind::Anon } = bound_ty
440 && let Some(inner) = tcx.types.bound_bound_anons.get(index.as_usize())
441 && let Some(ty) = inner.get(var.as_usize()).copied()
442 {
443 ty
444 } else {
445 Ty::new(tcx, Bound(ty::BoundVarIndexKind::Bound(index), bound_ty))
446 }
447 }
448
449 #[inline]
450 pub fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: BoundVar) -> Ty<'tcx> {
451 if let Some(ty) = tcx.types.bound_canonical_anons.get(var.as_usize()).copied() {
453 ty
454 } else {
455 Ty::new(
456 tcx,
457 Bound(
458 ty::BoundVarIndexKind::Canonical,
459 ty::BoundTy { var, kind: ty::BoundTyKind::Anon },
460 ),
461 )
462 }
463 }
464
465 #[inline]
466 pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Ty<'tcx> {
467 if placeholder.universe.is_root()
468 && placeholder.bound.kind == ty::BoundTyKind::Anon
469 && let Some(ty) =
470 tcx.types.placeholder_root_anons.get(placeholder.bound.var.as_usize()).copied()
471 {
472 ty
473 } else {
474 Ty::new(tcx, Placeholder(placeholder))
475 }
476 }
477
478 #[inline]
479 pub fn new_alias(
480 tcx: TyCtxt<'tcx>,
481 is_rigid: ty::IsRigid,
482 alias_ty: ty::AliasTy<'tcx>,
483 ) -> Ty<'tcx> {
484 Ty::new(tcx, Alias(is_rigid, alias_ty))
485 }
486
487 #[inline]
488 pub fn new_pat(tcx: TyCtxt<'tcx>, base: Ty<'tcx>, pat: ty::Pattern<'tcx>) -> Ty<'tcx> {
489 Ty::new(tcx, Pat(base, pat))
490 }
491
492 #[inline]
493 pub fn new_field_representing_type(
494 tcx: TyCtxt<'tcx>,
495 base: Ty<'tcx>,
496 variant: VariantIdx,
497 field: FieldIdx,
498 ) -> Ty<'tcx> {
499 let Some(did) = tcx.lang_items().field_representing_type() else {
500 ::rustc_span::macros::bug_impl(None,
format_args!("could not locate the `FieldRepresentingType` lang item"),
Location::caller())bug!("could not locate the `FieldRepresentingType` lang item")
501 };
502 let def = tcx.adt_def(did);
503 let args = tcx.mk_args(&[
504 base.into(),
505 Const::new_value(
506 tcx,
507 ValTree::from_scalar_int(tcx, variant.as_u32().into()),
508 tcx.types.u32,
509 )
510 .into(),
511 Const::new_value(
512 tcx,
513 ValTree::from_scalar_int(tcx, field.as_u32().into()),
514 tcx.types.u32,
515 )
516 .into(),
517 ]);
518 Ty::new_adt(tcx, def, args)
519 }
520
521 #[inline]
522 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("new_opaque",
"rustc_middle::ty::sty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5df8c02afdf6b882bc301442cea70f026e3d3974/compiler/rustc_middle/src/ty/sty.rs"),
::tracing_core::__macro_support::Option::Some(522u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::sty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_rigid")
}> =
::tracing::__macro_support::FieldName::new("is_rigid");
NAME.as_str()
},
{
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("args")
}> =
::tracing::__macro_support::FieldName::new("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(&is_rigid)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&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: Ty<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
Ty::new_alias(tcx, is_rigid,
AliasTy::new_from_args(tcx, ty::Opaque { def_id }, args))
}
}
}#[instrument(level = "debug", skip(tcx))]
523 pub fn new_opaque(
524 tcx: TyCtxt<'tcx>,
525 is_rigid: ty::IsRigid,
526 def_id: DefId,
527 args: GenericArgs<'tcx>,
528 ) -> Ty<'tcx> {
529 Ty::new_alias(tcx, is_rigid, AliasTy::new_from_args(tcx, ty::Opaque { def_id }, args))
530 }
531
532 pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Ty<'tcx> {
534 Ty::new(tcx, Error(guar))
535 }
536
537 #[track_caller]
539 pub fn new_misc_error(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
540 Ty::new_error_with_message(tcx, DUMMY_SP, "TyKind::Error constructed but no error reported")
541 }
542
543 #[track_caller]
546 pub fn new_error_with_message<S: Into<MultiSpan>>(
547 tcx: TyCtxt<'tcx>,
548 span: S,
549 msg: impl Into<Cow<'static, str>>,
550 ) -> Ty<'tcx> {
551 let reported = tcx.dcx().span_delayed_bug(span, msg);
552 Ty::new(tcx, Error(reported))
553 }
554
555 #[inline]
556 pub fn new_int(tcx: TyCtxt<'tcx>, i: ty::IntTy) -> Ty<'tcx> {
557 use ty::IntTy::*;
558 match i {
559 Isize => tcx.types.isize,
560 I8 => tcx.types.i8,
561 I16 => tcx.types.i16,
562 I32 => tcx.types.i32,
563 I64 => tcx.types.i64,
564 I128 => tcx.types.i128,
565 }
566 }
567
568 #[inline]
569 pub fn new_uint(tcx: TyCtxt<'tcx>, ui: ty::UintTy) -> Ty<'tcx> {
570 use ty::UintTy::*;
571 match ui {
572 Usize => tcx.types.usize,
573 U8 => tcx.types.u8,
574 U16 => tcx.types.u16,
575 U32 => tcx.types.u32,
576 U64 => tcx.types.u64,
577 U128 => tcx.types.u128,
578 }
579 }
580
581 #[inline]
582 pub fn new_float(tcx: TyCtxt<'tcx>, f: ty::FloatTy) -> Ty<'tcx> {
583 use ty::FloatTy::*;
584 match f {
585 F16 => tcx.types.f16,
586 F32 => tcx.types.f32,
587 F64 => tcx.types.f64,
588 F128 => tcx.types.f128,
589 }
590 }
591
592 #[inline]
593 pub fn new_ref(
594 tcx: TyCtxt<'tcx>,
595 r: Region<'tcx>,
596 ty: Ty<'tcx>,
597 mutbl: ty::Mutability,
598 ) -> Ty<'tcx> {
599 Ty::new(tcx, Ref(r, ty, mutbl))
600 }
601
602 #[inline]
603 pub fn new_mut_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
604 Ty::new_ref(tcx, r, ty, hir::Mutability::Mut)
605 }
606
607 #[inline]
608 pub fn new_imm_ref(tcx: TyCtxt<'tcx>, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
609 Ty::new_ref(tcx, r, ty, hir::Mutability::Not)
610 }
611
612 pub fn new_pinned_ref(
613 tcx: TyCtxt<'tcx>,
614 r: Region<'tcx>,
615 ty: Ty<'tcx>,
616 mutbl: ty::Mutability,
617 ) -> Ty<'tcx> {
618 let pin = tcx.adt_def(tcx.require_lang_item(LangItem::Pin, DUMMY_SP));
619 Ty::new_adt(tcx, pin, tcx.mk_args(&[Ty::new_ref(tcx, r, ty, mutbl).into()]))
620 }
621
622 #[inline]
623 pub fn new_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mutbl: ty::Mutability) -> Ty<'tcx> {
624 Ty::new(tcx, ty::RawPtr(ty, mutbl))
625 }
626
627 #[inline]
628 pub fn new_mut_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
629 Ty::new_ptr(tcx, ty, hir::Mutability::Mut)
630 }
631
632 #[inline]
633 pub fn new_imm_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
634 Ty::new_ptr(tcx, ty, hir::Mutability::Not)
635 }
636
637 #[inline]
638 pub fn new_adt(tcx: TyCtxt<'tcx>, def: AdtDef<'tcx>, args: GenericArgs<'tcx>) -> Ty<'tcx> {
639 tcx.debug_assert_args_compatible(def.did(), args);
640 tcx.debug_assert_adt_def_kind_compatible(def);
641 Ty::new(tcx, Adt(def, args))
642 }
643
644 #[inline]
645 pub fn new_foreign(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> {
646 Ty::new(tcx, Foreign(def_id))
647 }
648
649 #[inline]
650 pub fn new_array(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
651 Ty::new(tcx, Array(ty, ty::Const::from_target_usize(tcx, n)))
652 }
653
654 #[inline]
655 pub fn new_array_with_const_len(
656 tcx: TyCtxt<'tcx>,
657 ty: Ty<'tcx>,
658 ct: ty::Const<'tcx>,
659 ) -> Ty<'tcx> {
660 Ty::new(tcx, Array(ty, ct))
661 }
662
663 #[inline]
664 pub fn new_slice(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
665 Ty::new(tcx, Slice(ty))
666 }
667
668 #[inline]
669 pub fn new_tup(tcx: TyCtxt<'tcx>, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
670 if ts.is_empty() { tcx.types.unit } else { Ty::new(tcx, Tuple(tcx.mk_type_list(ts))) }
671 }
672
673 pub fn new_tup_from_iter<I, T>(tcx: TyCtxt<'tcx>, iter: I) -> T::Output
674 where
675 I: Iterator<Item = T>,
676 T: CollectAndApply<Ty<'tcx>, Ty<'tcx>>,
677 {
678 T::collect_and_apply(iter, |ts| Ty::new_tup(tcx, ts))
679 }
680
681 #[inline]
683 pub fn new_fn_def(
684 tcx: TyCtxt<'tcx>,
685 def_id: DefId,
686 args: ty::Binder<'tcx, impl IntoIterator<Item: Into<GenericArg<'tcx>>>>,
687 ) -> Ty<'tcx> {
688 if true {
{
match tcx.def_kind(def_id) {
DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) =>
{}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn)",
::core::option::Option::None);
}
}
};
};debug_assert_matches!(
689 tcx.def_kind(def_id),
690 DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn)
691 );
692 let args = args.map_bound(|args| tcx.check_and_mk_args(def_id, args));
693 Ty::new(tcx, FnDef(def_id, args))
694 }
695
696 #[inline]
697 pub fn new_fn_ptr(tcx: TyCtxt<'tcx>, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
698 let (sig_tys, hdr) = fty.split();
699 Ty::new(tcx, FnPtr(sig_tys, hdr))
700 }
701
702 #[inline]
703 pub fn new_unsafe_binder(tcx: TyCtxt<'tcx>, b: Binder<'tcx, Ty<'tcx>>) -> Ty<'tcx> {
704 Ty::new(tcx, UnsafeBinder(b.into()))
705 }
706
707 #[inline]
708 pub fn new_dynamic(
709 tcx: TyCtxt<'tcx>,
710 obj: &'tcx List<ty::PolyExistentialPredicate<'tcx>>,
711 reg: ty::Region<'tcx>,
712 ) -> Ty<'tcx> {
713 if truecfg!(debug_assertions) {
714 let projection_count = obj
715 .projection_bounds()
716 .filter(|item| !tcx.generics_require_sized_self(item.item_def_id()))
717 .count();
718 let expected_count: usize = obj.principal_def_id().map_or(0, |principal_def_id| {
719 elaborate::supertraits(
721 tcx,
722 ty::Binder::dummy(ty::TraitRef::identity(tcx, principal_def_id)),
723 )
724 .map(|principal| {
725 tcx.associated_items(principal.def_id())
726 .in_definition_order()
727 .filter(|item| item.can_have_equality_constraint(tcx))
728 .filter(|item| !item.is_impl_trait_in_trait())
729 .filter(|item| !tcx.generics_require_sized_self(item.def_id))
730 .count()
731 })
732 .sum()
733 });
734 {
match (&projection_count, &expected_count) {
(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!("expected {0:?} to have {1} projections, but it has {2}",
obj, expected_count, projection_count)));
}
}
}
};assert_eq!(
735 projection_count, expected_count,
736 "expected {obj:?} to have {expected_count} projections, \
737 but it has {projection_count}"
738 );
739 }
740 Ty::new(tcx, Dynamic(obj, reg))
741 }
742
743 #[inline]
744 pub fn new_projection_from_args(
745 tcx: TyCtxt<'tcx>,
746 is_rigid: ty::IsRigid,
747 item_def_id: DefId,
748 args: ty::GenericArgs<'tcx>,
749 ) -> Ty<'tcx> {
750 Ty::new_alias(
751 tcx,
752 is_rigid,
753 AliasTy::new_from_args(tcx, ty::Projection { def_id: item_def_id }, args),
754 )
755 }
756
757 #[inline]
758 pub fn new_projection(
759 tcx: TyCtxt<'tcx>,
760 is_rigid: ty::IsRigid,
761 item_def_id: DefId,
762 args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
763 ) -> Ty<'tcx> {
764 Ty::new_alias(
765 tcx,
766 is_rigid,
767 AliasTy::new(tcx, ty::Projection { def_id: item_def_id }, args),
768 )
769 }
770
771 #[inline]
772 pub fn new_closure(
773 tcx: TyCtxt<'tcx>,
774 def_id: DefId,
775 closure_args: GenericArgs<'tcx>,
776 ) -> Ty<'tcx> {
777 tcx.debug_assert_args_compatible(def_id, closure_args);
778 Ty::new(tcx, Closure(def_id, closure_args))
779 }
780
781 #[inline]
782 pub fn new_coroutine_closure(
783 tcx: TyCtxt<'tcx>,
784 def_id: DefId,
785 closure_args: GenericArgs<'tcx>,
786 ) -> Ty<'tcx> {
787 tcx.debug_assert_args_compatible(def_id, closure_args);
788 Ty::new(tcx, CoroutineClosure(def_id, closure_args))
789 }
790
791 #[inline]
792 pub fn new_coroutine(
793 tcx: TyCtxt<'tcx>,
794 def_id: DefId,
795 coroutine_args: GenericArgs<'tcx>,
796 ) -> Ty<'tcx> {
797 tcx.debug_assert_args_compatible(def_id, coroutine_args);
798 Ty::new(tcx, Coroutine(def_id, coroutine_args))
799 }
800
801 #[inline]
802 pub fn new_coroutine_witness(
803 tcx: TyCtxt<'tcx>,
804 def_id: DefId,
805 args: GenericArgs<'tcx>,
806 ) -> Ty<'tcx> {
807 if truecfg!(debug_assertions) {
808 tcx.debug_assert_args_compatible(tcx.typeck_root_def_id(def_id), args);
809 }
810 Ty::new(tcx, CoroutineWitness(def_id, args))
811 }
812
813 pub fn new_coroutine_witness_for_coroutine(
814 tcx: TyCtxt<'tcx>,
815 def_id: DefId,
816 coroutine_args: GenericArgs<'tcx>,
817 ) -> Ty<'tcx> {
818 tcx.debug_assert_args_compatible(def_id, coroutine_args);
819 let args =
828 ty::GenericArgs::for_item(tcx, tcx.typeck_root_def_id(def_id), |def, _| {
829 match def.kind {
830 ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
831 ty::GenericParamDefKind::Type { .. }
832 | ty::GenericParamDefKind::Const { .. } => coroutine_args[def.index as usize],
833 }
834 });
835 Ty::new_coroutine_witness(tcx, def_id, args)
836 }
837
838 pub fn new_view(
839 tcx: TyCtxt<'tcx>,
840 def: AdtDef<'tcx>,
841 args: GenericArgs<'tcx>,
842 fields: &[FieldIdx],
843 ) -> Ty<'tcx> {
844 tcx.debug_assert_args_compatible(def.did(), args);
845 tcx.debug_assert_adt_def_kind_compatible(def);
846
847 let base = Ty::new_adt(tcx, def, args);
848
849 let fields = fields
850 .iter()
851 .map(|field| Ty::new_field_representing_type(tcx, base, FIRST_VARIANT, *field));
852 let fields = Ty::new_tup_from_iter(tcx, fields);
853
854 Ty::new(tcx, TyKind::View(def, args, fields))
855 }
856
857 #[inline]
860 pub fn new_static_str(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
861 Ty::new_imm_ref(tcx, tcx.lifetimes.re_static, tcx.types.str_)
862 }
863
864 fn new_generic_adt(tcx: TyCtxt<'tcx>, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> {
867 let adt_def = tcx.adt_def(wrapper_def_id);
868 let args = GenericArgs::for_item(tcx, wrapper_def_id, |param, args| match param.kind {
869 GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => ::rustc_span::macros::bug_impl(None, format_args!("impossible case reached"),
Location::caller())bug!(),
870 GenericParamDefKind::Type { has_default, .. } => {
871 if param.index == 0 {
872 ty_param.into()
873 } else {
874 if !has_default { ::core::panicking::panic("assertion failed: has_default") };assert!(has_default);
875 tcx.type_of(param.def_id).instantiate(tcx, args).skip_norm_wip().into()
876 }
877 }
878 });
879 Ty::new_adt(tcx, adt_def, args)
880 }
881
882 #[inline]
883 pub fn new_lang_item(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, item: LangItem) -> Option<Ty<'tcx>> {
884 let def_id = tcx.lang_items().get(item)?;
885 Some(Ty::new_generic_adt(tcx, def_id, ty))
886 }
887
888 #[inline]
889 pub fn new_diagnostic_item(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, name: Symbol) -> Option<Ty<'tcx>> {
890 let def_id = tcx.get_diagnostic_item(name)?;
891 Some(Ty::new_generic_adt(tcx, def_id, ty))
892 }
893
894 #[inline]
895 pub fn new_box(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
896 let def_id = tcx.require_lang_item(LangItem::OwnedBox, DUMMY_SP);
897 Ty::new_generic_adt(tcx, def_id, ty)
898 }
899
900 #[inline]
901 pub fn new_option(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
902 let def_id = tcx.require_lang_item(LangItem::Option, DUMMY_SP);
903 Ty::new_generic_adt(tcx, def_id, ty)
904 }
905
906 #[inline]
907 pub fn new_maybe_uninit(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
908 let def_id = tcx.require_lang_item(LangItem::MaybeUninit, DUMMY_SP);
909 Ty::new_generic_adt(tcx, def_id, ty)
910 }
911
912 pub fn new_task_context(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
914 let context_did = tcx.require_lang_item(LangItem::Context, DUMMY_SP);
915 let context_adt_ref = tcx.adt_def(context_did);
916 let context_args = tcx.mk_args(&[tcx.lifetimes.re_erased.into()]);
917 let context_ty = Ty::new_adt(tcx, context_adt_ref, context_args);
918 Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, context_ty)
919 }
920}
921
922impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
923 fn new_bool(tcx: TyCtxt<'tcx>) -> Self {
924 tcx.types.bool
925 }
926
927 fn new_u8(tcx: TyCtxt<'tcx>) -> Self {
928 tcx.types.u8
929 }
930
931 fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferTy) -> Self {
932 Ty::new_infer(tcx, infer)
933 }
934
935 fn new_var(tcx: TyCtxt<'tcx>, vid: ty::TyVid) -> Self {
936 Ty::new_var(tcx, vid)
937 }
938
939 fn new_param(tcx: TyCtxt<'tcx>, param: ty::ParamTy) -> Self {
940 Ty::new_param(tcx, param.index, param.name)
941 }
942
943 fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Self {
944 Ty::new_placeholder(tcx, placeholder)
945 }
946
947 fn new_bound(
948 interner: TyCtxt<'tcx>,
949 debruijn: ty::DebruijnIndex,
950 var: ty::BoundTy<'tcx>,
951 ) -> Self {
952 Ty::new_bound(interner, debruijn, var)
953 }
954
955 fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
956 Ty::new_bound(tcx, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
957 }
958
959 fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: ty::BoundVar) -> Self {
960 Ty::new_canonical_bound(tcx, var)
961 }
962
963 fn new_alias(
964 interner: TyCtxt<'tcx>,
965 is_rigid: ty::IsRigid,
966 alias_ty: ty::AliasTy<'tcx>,
967 ) -> Self {
968 Ty::new_alias(interner, is_rigid, alias_ty)
969 }
970
971 fn new_error(interner: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self {
972 Ty::new_error(interner, guar)
973 }
974
975 fn new_adt(
976 interner: TyCtxt<'tcx>,
977 adt_def: ty::AdtDef<'tcx>,
978 args: ty::GenericArgs<'tcx>,
979 ) -> Self {
980 Ty::new_adt(interner, adt_def, args)
981 }
982
983 fn new_foreign(interner: TyCtxt<'tcx>, def_id: DefId) -> Self {
984 Ty::new_foreign(interner, def_id)
985 }
986
987 fn new_dynamic(
988 interner: TyCtxt<'tcx>,
989 preds: &'tcx List<ty::PolyExistentialPredicate<'tcx>>,
990 region: ty::Region<'tcx>,
991 ) -> Self {
992 Ty::new_dynamic(interner, preds, region)
993 }
994
995 fn new_coroutine(interner: TyCtxt<'tcx>, def_id: DefId, args: ty::GenericArgs<'tcx>) -> Self {
996 Ty::new_coroutine(interner, def_id, args)
997 }
998
999 fn new_coroutine_closure(
1000 interner: TyCtxt<'tcx>,
1001 def_id: DefId,
1002 args: ty::GenericArgs<'tcx>,
1003 ) -> Self {
1004 Ty::new_coroutine_closure(interner, def_id, args)
1005 }
1006
1007 fn new_closure(interner: TyCtxt<'tcx>, def_id: DefId, args: ty::GenericArgs<'tcx>) -> Self {
1008 Ty::new_closure(interner, def_id, args)
1009 }
1010
1011 fn new_coroutine_witness(
1012 interner: TyCtxt<'tcx>,
1013 def_id: DefId,
1014 args: ty::GenericArgs<'tcx>,
1015 ) -> Self {
1016 Ty::new_coroutine_witness(interner, def_id, args)
1017 }
1018
1019 fn new_coroutine_witness_for_coroutine(
1020 interner: TyCtxt<'tcx>,
1021 def_id: DefId,
1022 coroutine_args: ty::GenericArgs<'tcx>,
1023 ) -> Self {
1024 Ty::new_coroutine_witness_for_coroutine(interner, def_id, coroutine_args)
1025 }
1026
1027 fn new_ptr(interner: TyCtxt<'tcx>, ty: Self, mutbl: hir::Mutability) -> Self {
1028 Ty::new_ptr(interner, ty, mutbl)
1029 }
1030
1031 fn new_ref(
1032 interner: TyCtxt<'tcx>,
1033 region: ty::Region<'tcx>,
1034 ty: Self,
1035 mutbl: hir::Mutability,
1036 ) -> Self {
1037 Ty::new_ref(interner, region, ty, mutbl)
1038 }
1039
1040 fn new_array_with_const_len(interner: TyCtxt<'tcx>, ty: Self, len: ty::Const<'tcx>) -> Self {
1041 Ty::new_array_with_const_len(interner, ty, len)
1042 }
1043
1044 fn new_slice(interner: TyCtxt<'tcx>, ty: Self) -> Self {
1045 Ty::new_slice(interner, ty)
1046 }
1047
1048 fn new_tup(interner: TyCtxt<'tcx>, tys: &[Ty<'tcx>]) -> Self {
1049 Ty::new_tup(interner, tys)
1050 }
1051
1052 fn new_tup_from_iter<It, T>(interner: TyCtxt<'tcx>, iter: It) -> T::Output
1053 where
1054 It: Iterator<Item = T>,
1055 T: CollectAndApply<Self, Self>,
1056 {
1057 Ty::new_tup_from_iter(interner, iter)
1058 }
1059
1060 fn tuple_fields(self) -> &'tcx ty::List<Ty<'tcx>> {
1061 self.tuple_fields()
1062 }
1063
1064 fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> {
1065 self.to_opt_closure_kind()
1066 }
1067
1068 fn from_closure_kind(interner: TyCtxt<'tcx>, kind: ty::ClosureKind) -> Self {
1069 Ty::from_closure_kind(interner, kind)
1070 }
1071
1072 fn from_coroutine_closure_kind(
1073 interner: TyCtxt<'tcx>,
1074 kind: rustc_type_ir::ClosureKind,
1075 ) -> Self {
1076 Ty::from_coroutine_closure_kind(interner, kind)
1077 }
1078
1079 fn new_fn_def(
1080 interner: TyCtxt<'tcx>,
1081 def_id: DefId,
1082 args: ty::Binder<'tcx, ty::GenericArgs<'tcx>>,
1083 ) -> Self {
1084 Ty::new_fn_def(interner, def_id, args)
1085 }
1086
1087 fn new_fn_ptr(interner: TyCtxt<'tcx>, sig: ty::Binder<'tcx, ty::FnSig<'tcx>>) -> Self {
1088 Ty::new_fn_ptr(interner, sig)
1089 }
1090
1091 fn new_pat(interner: TyCtxt<'tcx>, ty: Self, pat: ty::Pattern<'tcx>) -> Self {
1092 Ty::new_pat(interner, ty, pat)
1093 }
1094
1095 fn new_unsafe_binder(interner: TyCtxt<'tcx>, ty: ty::Binder<'tcx, Ty<'tcx>>) -> Self {
1096 Ty::new_unsafe_binder(interner, ty)
1097 }
1098
1099 fn new_unit(interner: TyCtxt<'tcx>) -> Self {
1100 interner.types.unit
1101 }
1102
1103 fn new_usize(interner: TyCtxt<'tcx>) -> Self {
1104 interner.types.usize
1105 }
1106
1107 fn discriminant_ty(self, interner: TyCtxt<'tcx>) -> Ty<'tcx> {
1108 self.discriminant_ty(interner)
1109 }
1110
1111 fn has_unsafe_fields(self) -> bool {
1112 Ty::has_unsafe_fields(self)
1113 }
1114}
1115
1116impl<'tcx> Ty<'tcx> {
1118 #[inline(always)]
1123 pub fn kind(self) -> &'tcx TyKind<'tcx> {
1124 self.0.0
1125 }
1126
1127 #[inline]
1128 pub fn is_unit(self) -> bool {
1129 match self.kind() {
1130 Tuple(tys) => tys.is_empty(),
1131 _ => false,
1132 }
1133 }
1134
1135 #[inline]
1137 pub fn is_usize(self) -> bool {
1138 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Uint(UintTy::Usize) => true,
_ => false,
}matches!(self.kind(), Uint(UintTy::Usize))
1139 }
1140
1141 #[inline]
1143 pub fn is_usize_like(self) -> bool {
1144 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Uint(UintTy::Usize) | Infer(IntVar(_)) => true,
_ => false,
}matches!(self.kind(), Uint(UintTy::Usize) | Infer(IntVar(_)))
1145 }
1146
1147 #[inline]
1148 pub fn is_never(self) -> bool {
1149 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Never => true,
_ => false,
}matches!(self.kind(), Never)
1150 }
1151
1152 #[inline]
1153 pub fn is_primitive(self) -> bool {
1154 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Bool | Char | Int(_) | Uint(_) | Float(_) => true,
_ => false,
}matches!(self.kind(), Bool | Char | Int(_) | Uint(_) | Float(_))
1155 }
1156
1157 #[inline]
1158 pub fn is_adt(self) -> bool {
1159 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Adt(..) => true,
_ => false,
}matches!(self.kind(), Adt(..))
1160 }
1161
1162 #[inline]
1163 pub fn is_self_param(self) -> bool {
1164 if let Param(param) = self.kind() {
1165 param.index == 0 && param.name == kw::SelfUpper
1166 } else {
1167 false
1168 }
1169 }
1170
1171 #[inline]
1172 pub fn is_ref(self) -> bool {
1173 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Ref(..) => true,
_ => false,
}matches!(self.kind(), Ref(..))
1174 }
1175
1176 #[inline]
1177 pub fn is_ty_var(self) -> bool {
1178 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Infer(TyVar(_)) => true,
_ => false,
}matches!(self.kind(), Infer(TyVar(_)))
1179 }
1180
1181 #[inline]
1182 pub fn ty_vid(self) -> Option<ty::TyVid> {
1183 match self.kind() {
1184 &Infer(TyVar(vid)) => Some(vid),
1185 _ => None,
1186 }
1187 }
1188
1189 #[inline]
1190 pub fn float_vid(self) -> Option<ty::FloatVid> {
1191 match self.kind() {
1192 &Infer(FloatVar(vid)) => Some(vid),
1193 _ => None,
1194 }
1195 }
1196
1197 #[inline]
1198 pub fn is_ty_or_numeric_infer(self) -> bool {
1199 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Infer(_) => true,
_ => false,
}matches!(self.kind(), Infer(_))
1200 }
1201
1202 #[inline]
1203 pub fn is_phantom_data(self) -> bool {
1204 if let Adt(def, _) = self.kind() { def.is_phantom_data() } else { false }
1205 }
1206
1207 #[inline]
1208 pub fn is_unsafe_cell(self) -> bool {
1209 if let Adt(def, _) = self.kind() { def.is_unsafe_cell() } else { false }
1210 }
1211
1212 #[inline]
1213 pub fn is_bool(self) -> bool {
1214 *self.kind() == Bool
1215 }
1216
1217 #[inline]
1219 pub fn is_str(self) -> bool {
1220 *self.kind() == Str
1221 }
1222
1223 #[inline]
1225 pub fn is_imm_ref_str(self) -> bool {
1226 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Ref(_, inner, hir::Mutability::Not) if inner.is_str() => true,
_ => false,
}matches!(self.kind(), ty::Ref(_, inner, hir::Mutability::Not) if inner.is_str())
1227 }
1228
1229 #[inline]
1230 pub fn is_param(self, index: u32) -> bool {
1231 match self.kind() {
1232 ty::Param(data) => data.index == index,
1233 _ => false,
1234 }
1235 }
1236
1237 #[inline]
1238 pub fn is_slice(self) -> bool {
1239 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Slice(_) => true,
_ => false,
}matches!(self.kind(), Slice(_))
1240 }
1241
1242 #[inline]
1243 pub fn is_array_slice(self) -> bool {
1244 match self.kind() {
1245 Slice(_) => true,
1246 ty::RawPtr(ty, _) | Ref(_, ty, _) => #[allow(non_exhaustive_omitted_patterns)] match ty.kind() {
Slice(_) => true,
_ => false,
}matches!(ty.kind(), Slice(_)),
1247 _ => false,
1248 }
1249 }
1250
1251 #[inline]
1252 pub fn is_array(self) -> bool {
1253 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Array(..) => true,
_ => false,
}matches!(self.kind(), Array(..))
1254 }
1255
1256 #[inline]
1257 pub fn is_simd(self) -> bool {
1258 match self.kind() {
1259 Adt(def, _) => def.repr().simd(),
1260 _ => false,
1261 }
1262 }
1263
1264 #[inline]
1265 pub fn is_scalable_vector(self) -> bool {
1266 match self.kind() {
1267 Adt(def, _) => def.repr().scalable(),
1268 _ => false,
1269 }
1270 }
1271
1272 pub fn sequence_element_type(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
1273 match self.kind() {
1274 Array(ty, _) | Slice(ty) => *ty,
1275 Str => tcx.types.u8,
1276 _ => ::rustc_span::macros::bug_impl(None,
format_args!("`sequence_element_type` called on non-sequence value: {0}",
self), Location::caller())bug!("`sequence_element_type` called on non-sequence value: {}", self),
1277 }
1278 }
1279
1280 pub fn scalable_vector_parts(
1281 self,
1282 tcx: TyCtxt<'tcx>,
1283 ) -> Option<(u16, Ty<'tcx>, NumScalableVectors)> {
1284 let Adt(def, args) = self.kind() else {
1285 return None;
1286 };
1287 let (num_vectors, vec_def) = match def.repr().scalable? {
1288 ScalableElt::ElementCount(_) => (NumScalableVectors::for_non_tuple(), *def),
1289 ScalableElt::Container => (
1290 NumScalableVectors::from_field_count(def.non_enum_variant().fields.len())?,
1291 def.non_enum_variant().fields[FieldIdx::ZERO]
1292 .ty(tcx, *args)
1293 .skip_norm_wip()
1294 .ty_adt_def()?,
1295 ),
1296 };
1297 let Some(ScalableElt::ElementCount(element_count)) = vec_def.repr().scalable else {
1298 return None;
1299 };
1300 let variant = vec_def.non_enum_variant();
1301 {
match (&variant.fields.len(), &1) {
(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!(variant.fields.len(), 1);
1302 let field_ty = variant.fields[FieldIdx::ZERO].ty(tcx, *args);
1303 Some((element_count, field_ty.skip_norm_wip(), num_vectors))
1304 }
1305
1306 pub fn simd_size_and_type(self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
1307 let Adt(def, args) = self.kind() else {
1308 ::rustc_span::macros::bug_impl(None,
format_args!("`simd_size_and_type` called on invalid type"),
Location::caller())bug!("`simd_size_and_type` called on invalid type")
1309 };
1310 if !def.repr().simd() {
{
::core::panicking::panic_fmt(format_args!("`simd_size_and_type` called on non-SIMD type"));
}
};assert!(def.repr().simd(), "`simd_size_and_type` called on non-SIMD type");
1311 let variant = def.non_enum_variant();
1312 {
match (&variant.fields.len(), &1) {
(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!(variant.fields.len(), 1);
1313 let field_ty = variant.fields[FieldIdx::ZERO].ty(tcx, *args);
1314 let Array(f0_elem_ty, f0_len) = field_ty.skip_norm_wip().kind() else {
1315 ::rustc_span::macros::bug_impl(None,
format_args!("Simd type has non-array field type {0:?}", field_ty),
Location::caller())bug!("Simd type has non-array field type {field_ty:?}")
1316 };
1317 (
1322 f0_len
1323 .try_to_target_usize(tcx)
1324 .expect("expected SIMD field to have definite array size"),
1325 *f0_elem_ty,
1326 )
1327 }
1328
1329 #[inline]
1330 pub fn is_mutable_ptr(self) -> bool {
1331 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
RawPtr(_, hir::Mutability::Mut) | Ref(_, _, hir::Mutability::Mut) => true,
_ => false,
}matches!(self.kind(), RawPtr(_, hir::Mutability::Mut) | Ref(_, _, hir::Mutability::Mut))
1332 }
1333
1334 #[inline]
1336 pub fn ref_mutability(self) -> Option<hir::Mutability> {
1337 match self.kind() {
1338 Ref(_, _, mutability) => Some(*mutability),
1339 _ => None,
1340 }
1341 }
1342
1343 #[inline]
1344 pub fn is_raw_ptr(self) -> bool {
1345 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
RawPtr(_, _) => true,
_ => false,
}matches!(self.kind(), RawPtr(_, _))
1346 }
1347
1348 #[inline]
1351 pub fn is_any_ptr(self) -> bool {
1352 self.is_ref() || self.is_raw_ptr() || self.is_fn_ptr()
1353 }
1354
1355 #[inline]
1356 pub fn is_box(self) -> bool {
1357 match self.kind() {
1358 Adt(def, _) => def.is_box(),
1359 _ => false,
1360 }
1361 }
1362
1363 #[inline]
1368 pub fn is_box_global(self, tcx: TyCtxt<'tcx>) -> bool {
1369 match self.kind() {
1370 Adt(def, args) if def.is_box() => {
1371 let Some(alloc) = args.get(1) else {
1372 return true;
1374 };
1375 alloc.expect_ty().ty_adt_def().is_some_and(|alloc_adt| {
1376 tcx.is_lang_item(alloc_adt.did(), LangItem::GlobalAlloc)
1377 })
1378 }
1379 _ => false,
1380 }
1381 }
1382
1383 pub fn boxed_ty(self) -> Option<Ty<'tcx>> {
1384 match self.kind() {
1385 Adt(def, args) if def.is_box() => Some(args.type_at(0)),
1386 _ => None,
1387 }
1388 }
1389
1390 pub fn pinned_ty(self) -> Option<Ty<'tcx>> {
1391 match self.kind() {
1392 Adt(def, args) if def.is_pin() => Some(args.type_at(0)),
1393 _ => None,
1394 }
1395 }
1396
1397 pub fn maybe_pinned_ref(
1406 self,
1407 ) -> Option<(Ty<'tcx>, ty::Pinnedness, ty::Mutability, Region<'tcx>)> {
1408 match self.kind() {
1409 Adt(def, args)
1410 if def.is_pin()
1411 && let &ty::Ref(region, ty, mutbl) = args.type_at(0).kind() =>
1412 {
1413 Some((ty, ty::Pinnedness::Pinned, mutbl, region))
1414 }
1415 &Ref(region, ty, mutbl) => Some((ty, ty::Pinnedness::Not, mutbl, region)),
1416 _ => None,
1417 }
1418 }
1419
1420 pub fn expect_boxed_ty(self) -> Ty<'tcx> {
1422 self.boxed_ty()
1423 .unwrap_or_else(|| ::rustc_span::macros::bug_impl(None,
format_args!("`expect_boxed_ty` is called on non-box type {0:?}", self),
Location::caller())bug!("`expect_boxed_ty` is called on non-box type {:?}", self))
1424 }
1425
1426 #[inline]
1430 pub fn is_scalar(self) -> bool {
1431 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Bool | Char | Int(_) | Float(_) | Uint(_) | FnDef(..) | FnPtr(..) |
RawPtr(_, _) | Infer(IntVar(_) | FloatVar(_)) => true,
_ => false,
}matches!(
1432 self.kind(),
1433 Bool | Char
1434 | Int(_)
1435 | Float(_)
1436 | Uint(_)
1437 | FnDef(..)
1438 | FnPtr(..)
1439 | RawPtr(_, _)
1440 | Infer(IntVar(_) | FloatVar(_))
1441 )
1442 }
1443
1444 #[inline]
1446 pub fn is_floating_point(self) -> bool {
1447 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Float(_) | Infer(FloatVar(_)) => true,
_ => false,
}matches!(self.kind(), Float(_) | Infer(FloatVar(_)))
1448 }
1449
1450 #[inline]
1451 pub fn is_trait(self) -> bool {
1452 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Dynamic(_, _) => true,
_ => false,
}matches!(self.kind(), Dynamic(_, _))
1453 }
1454
1455 #[inline]
1456 pub fn is_enum(self) -> bool {
1457 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Adt(adt_def, _) if adt_def.is_enum() => true,
_ => false,
}matches!(self.kind(), Adt(adt_def, _) if adt_def.is_enum())
1458 }
1459
1460 #[inline]
1461 pub fn is_union(self) -> bool {
1462 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Adt(adt_def, _) if adt_def.is_union() => true,
_ => false,
}matches!(self.kind(), Adt(adt_def, _) if adt_def.is_union())
1463 }
1464
1465 #[inline]
1466 pub fn is_closure(self) -> bool {
1467 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Closure(..) => true,
_ => false,
}matches!(self.kind(), Closure(..))
1468 }
1469
1470 #[inline]
1471 pub fn is_coroutine(self) -> bool {
1472 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Coroutine(..) => true,
_ => false,
}matches!(self.kind(), Coroutine(..))
1473 }
1474
1475 #[inline]
1476 pub fn is_coroutine_closure(self) -> bool {
1477 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
CoroutineClosure(..) => true,
_ => false,
}matches!(self.kind(), CoroutineClosure(..))
1478 }
1479
1480 #[inline]
1481 pub fn is_integral(self) -> bool {
1482 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Infer(IntVar(_)) | Int(_) | Uint(_) => true,
_ => false,
}matches!(self.kind(), Infer(IntVar(_)) | Int(_) | Uint(_))
1483 }
1484
1485 #[inline]
1486 pub fn is_fresh_ty(self) -> bool {
1487 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Infer(FreshTy(_)) => true,
_ => false,
}matches!(self.kind(), Infer(FreshTy(_)))
1488 }
1489
1490 #[inline]
1491 pub fn is_fresh(self) -> bool {
1492 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Infer(FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_)) => true,
_ => false,
}matches!(self.kind(), Infer(FreshTy(_) | FreshIntTy(_) | FreshFloatTy(_)))
1493 }
1494
1495 #[inline]
1496 pub fn is_char(self) -> bool {
1497 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Char => true,
_ => false,
}matches!(self.kind(), Char)
1498 }
1499
1500 #[inline]
1501 pub fn is_numeric(self) -> bool {
1502 self.is_integral() || self.is_floating_point()
1503 }
1504
1505 #[inline]
1506 pub fn is_signed(self) -> bool {
1507 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Int(_) => true,
_ => false,
}matches!(self.kind(), Int(_))
1508 }
1509
1510 #[inline]
1511 pub fn is_ptr_sized_integral(self) -> bool {
1512 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Int(ty::IntTy::Isize) | Uint(ty::UintTy::Usize) => true,
_ => false,
}matches!(self.kind(), Int(ty::IntTy::Isize) | Uint(ty::UintTy::Usize))
1513 }
1514
1515 #[inline]
1516 pub fn has_concrete_skeleton(self) -> bool {
1517 !#[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Param(_) | Infer(_) | Error(_) => true,
_ => false,
}matches!(self.kind(), Param(_) | Infer(_) | Error(_))
1518 }
1519
1520 pub fn contains(self, other: Ty<'tcx>) -> bool {
1524 struct ContainsTyVisitor<'tcx>(Ty<'tcx>);
1525
1526 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsTyVisitor<'tcx> {
1527 type Result = ControlFlow<()>;
1528
1529 fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1530 if self.0 == t { ControlFlow::Break(()) } else { t.super_visit_with(self) }
1531 }
1532 }
1533
1534 let cf = self.visit_with(&mut ContainsTyVisitor(other));
1535 cf.is_break()
1536 }
1537
1538 pub fn contains_closure(self) -> bool {
1542 struct ContainsClosureVisitor;
1543
1544 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsClosureVisitor {
1545 type Result = ControlFlow<()>;
1546
1547 fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1548 if let ty::Closure(..) = t.kind() {
1549 ControlFlow::Break(())
1550 } else {
1551 t.super_visit_with(self)
1552 }
1553 }
1554 }
1555
1556 let cf = self.visit_with(&mut ContainsClosureVisitor);
1557 cf.is_break()
1558 }
1559
1560 pub fn find_async_drop_impl_coroutine<F: FnMut(Ty<'tcx>)>(
1565 self,
1566 tcx: TyCtxt<'tcx>,
1567 mut f: F,
1568 ) -> Ty<'tcx> {
1569 if !self.is_coroutine() {
::core::panicking::panic("assertion failed: self.is_coroutine()")
};assert!(self.is_coroutine());
1570 let mut cor_ty = self;
1571 let mut ty = cor_ty;
1572 loop {
1573 let ty::Coroutine(def_id, args) = ty.kind() else { return cor_ty };
1574 cor_ty = ty;
1575 f(ty);
1576 if !tcx.is_async_drop_in_place_coroutine(*def_id) {
1577 return cor_ty;
1578 }
1579 ty = args.first().unwrap().expect_ty();
1580 }
1581 }
1582
1583 pub fn builtin_deref(self, explicit: bool) -> Option<Ty<'tcx>> {
1588 match *self.kind() {
1589 _ if let Some(boxed) = self.boxed_ty() => Some(boxed),
1590 Ref(_, ty, _) => Some(ty),
1591 RawPtr(ty, _) if explicit => Some(ty),
1592 _ => None,
1593 }
1594 }
1595
1596 pub fn builtin_index(self) -> Option<Ty<'tcx>> {
1598 match self.kind() {
1599 Array(ty, _) | Slice(ty) => Some(*ty),
1600 _ => None,
1601 }
1602 }
1603
1604 {}
#[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("fn_sig",
"rustc_middle::ty::sty", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5df8c02afdf6b882bc301442cea70f026e3d3974/compiler/rustc_middle/src/ty/sty.rs"),
::tracing_core::__macro_support::Option::Some(1604u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::sty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self")
}> =
::tracing::__macro_support::FieldName::new("self");
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(&self)
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: PolyFnSig<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{ self.kind().fn_sig(tcx) }
}
}#[tracing::instrument(level = "trace", skip(tcx))]
1605 pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
1606 self.kind().fn_sig(tcx)
1607 }
1608
1609 {}
#[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("unnormalized_fn_sig",
"rustc_middle::ty::sty", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5df8c02afdf6b882bc301442cea70f026e3d3974/compiler/rustc_middle/src/ty/sty.rs"),
::tracing_core::__macro_support::Option::Some(1609u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::sty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self")
}> =
::tracing::__macro_support::FieldName::new("self");
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(&self)
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:
ty::Unnormalized<'tcx, PolyFnSig<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{ self.kind().unnormalized_fn_sig(tcx) }
}
}#[tracing::instrument(level = "trace", skip(tcx))]
1610 pub fn unnormalized_fn_sig(self, tcx: TyCtxt<'tcx>) -> ty::Unnormalized<'tcx, PolyFnSig<'tcx>> {
1611 self.kind().unnormalized_fn_sig(tcx)
1612 }
1613
1614 #[inline]
1615 pub fn is_fn(self) -> bool {
1616 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
FnDef(..) | FnPtr(..) => true,
_ => false,
}matches!(self.kind(), FnDef(..) | FnPtr(..))
1617 }
1618
1619 #[inline]
1620 pub fn is_fn_ptr(self) -> bool {
1621 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
FnPtr(..) => true,
_ => false,
}matches!(self.kind(), FnPtr(..))
1622 }
1623
1624 #[inline]
1625 pub fn is_opaque(self) -> bool {
1626 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => true,
_ => false,
}matches!(self.kind(), Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }))
1627 }
1628
1629 #[inline]
1630 pub fn ty_adt_def(self) -> Option<AdtDef<'tcx>> {
1631 match self.kind() {
1632 Adt(adt, _) => Some(*adt),
1633 _ => None,
1634 }
1635 }
1636
1637 #[inline]
1641 pub fn tuple_fields(self) -> &'tcx List<Ty<'tcx>> {
1642 match self.kind() {
1643 Tuple(args) => args,
1644 _ => ::rustc_span::macros::bug_impl(None,
format_args!("tuple_fields called on non-tuple: {0:?}", self),
Location::caller())bug!("tuple_fields called on non-tuple: {self:?}"),
1645 }
1646 }
1647
1648 #[inline]
1650 pub fn opt_tuple_fields(self) -> Option<&'tcx List<Ty<'tcx>>> {
1651 match self.kind() {
1652 Tuple(args) => Some(args),
1653 _ => None,
1654 }
1655 }
1656
1657 #[inline]
1661 pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
1662 match self.kind() {
1663 TyKind::Adt(adt, _) => Some(adt.variant_range()),
1664 TyKind::Coroutine(def_id, args) => {
1665 Some(args.as_coroutine().variant_range(*def_id, tcx))
1666 }
1667 TyKind::UnsafeBinder(bound_ty) => {
1668 tcx.instantiate_bound_regions_with_erased((*bound_ty).into()).variant_range(tcx)
1669 }
1670 _ => None,
1671 }
1672 }
1673
1674 #[inline]
1679 pub fn discriminant_for_variant(
1680 self,
1681 tcx: TyCtxt<'tcx>,
1682 variant_index: VariantIdx,
1683 ) -> Option<Discr<'tcx>> {
1684 match self.kind() {
1685 TyKind::Adt(adt, _) if adt.is_enum() => {
1686 Some(adt.discriminant_for_variant(tcx, variant_index))
1687 }
1688 TyKind::Coroutine(def_id, args) => {
1689 Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index))
1690 }
1691 TyKind::UnsafeBinder(bound_ty) => tcx
1692 .instantiate_bound_regions_with_erased((*bound_ty).into())
1693 .discriminant_for_variant(tcx, variant_index),
1694 _ => None,
1695 }
1696 }
1697
1698 pub fn discriminant_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
1700 match self.kind() {
1701 ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx),
1702 ty::Coroutine(_, args) => args.as_coroutine().discr_ty(tcx),
1703
1704 ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => {
1705 let assoc_items = tcx.associated_item_def_ids(
1706 tcx.require_lang_item(LangItem::DiscriminantKind, DUMMY_SP),
1707 );
1708 Ty::new_projection_from_args(
1709 tcx,
1710 ty::IsRigid::No,
1711 assoc_items[0],
1712 tcx.mk_args(&[self.into()]),
1713 )
1714 }
1715
1716 ty::Pat(ty, _) => ty.discriminant_ty(tcx),
1717 ty::UnsafeBinder(bound_ty) => {
1718 tcx.instantiate_bound_regions_with_erased((*bound_ty).into()).discriminant_ty(tcx)
1719 }
1720
1721 ty::Bool
1722 | ty::Char
1723 | ty::Int(_)
1724 | ty::Uint(_)
1725 | ty::Float(_)
1726 | ty::Adt(..)
1727 | ty::Foreign(_)
1728 | ty::Str
1729 | ty::Array(..)
1730 | ty::Slice(_)
1731 | ty::RawPtr(_, _)
1732 | ty::Ref(..)
1733 | ty::FnDef(..)
1734 | ty::FnPtr(..)
1735 | ty::Dynamic(..)
1736 | ty::Closure(..)
1737 | ty::CoroutineClosure(..)
1738 | ty::CoroutineWitness(..)
1739 | ty::Never
1740 | ty::Tuple(_)
1741 | ty::Error(_)
1742 | ty::Infer(IntVar(_) | FloatVar(_)) => tcx.types.u8,
1743
1744 ty::Bound(..)
1745 | ty::Placeholder(_)
1746 | ty::Infer(FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1747 ::rustc_span::macros::bug_impl(None,
format_args!("`discriminant_ty` applied to unexpected type: {0:?}", self),
Location::caller())bug!("`discriminant_ty` applied to unexpected type: {:?}", self)
1748 }
1749
1750 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
1752 }
1753 }
1754
1755 pub fn ptr_metadata_ty_or_tail(
1758 self,
1759 tcx: TyCtxt<'tcx>,
1760 normalize: impl FnMut(Unnormalized<'tcx, Ty<'tcx>>) -> Ty<'tcx>,
1761 ) -> Result<Ty<'tcx>, Ty<'tcx>> {
1762 let tail = tcx.struct_tail_raw(self, &ObligationCause::dummy(), normalize, || {});
1763 match tail.kind() {
1764 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1766 | ty::Uint(_)
1767 | ty::Int(_)
1768 | ty::Bool
1769 | ty::Float(_)
1770 | ty::FnDef(..)
1771 | ty::FnPtr(..)
1772 | ty::RawPtr(..)
1773 | ty::Char
1774 | ty::Ref(..)
1775 | ty::Coroutine(..)
1776 | ty::CoroutineWitness(..)
1777 | ty::Array(..)
1778 | ty::Closure(..)
1779 | ty::CoroutineClosure(..)
1780 | ty::Never
1781 | ty::Error(_) => Ok(tcx.types.unit),
1782 ty::Foreign(..) => Ok(tcx.types.unit),
1784 ty::View(..) => Ok(tcx.types.unit),
1786 ty::Adt(..) => Ok(tcx.types.unit),
1789 ty::Tuple(..) => Ok(tcx.types.unit),
1792
1793 ty::Str | ty::Slice(_) => Ok(tcx.types.usize),
1794
1795 ty::Dynamic(_, _) => {
1796 let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, DUMMY_SP);
1797 Ok(tcx.type_of(dyn_metadata).instantiate(tcx, &[tail.into()]).skip_norm_wip())
1798 }
1799
1800 ty::Param(_) | ty::Alias(..) => Err(tail),
1803
1804 ty::UnsafeBinder(_) => {
::core::panicking::panic_fmt(format_args!("not implemented: {0}",
format_args!("FIXME(unsafe_binder)")));
}unimplemented!("FIXME(unsafe_binder)"),
1805
1806 ty::Infer(ty::TyVar(_))
1807 | ty::Pat(..)
1808 | ty::Bound(..)
1809 | ty::Placeholder(..)
1810 | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => ::rustc_span::macros::bug_impl(None,
format_args!("`ptr_metadata_ty_or_tail` applied to unexpected type: {0:?} (tail = {1:?})",
self, tail), Location::caller())bug!(
1811 "`ptr_metadata_ty_or_tail` applied to unexpected type: {self:?} (tail = {tail:?})"
1812 ),
1813 }
1814 }
1815
1816 pub fn ptr_metadata_ty(
1819 self,
1820 tcx: TyCtxt<'tcx>,
1821 normalize: impl FnMut(Unnormalized<'tcx, Ty<'tcx>>) -> Ty<'tcx>,
1822 ) -> Ty<'tcx> {
1823 match self.ptr_metadata_ty_or_tail(tcx, normalize) {
1824 Ok(metadata) => metadata,
1825 Err(tail) => ::rustc_span::macros::bug_impl(None,
format_args!("`ptr_metadata_ty` failed to get metadata for type: {0:?} (tail = {1:?})",
self, tail), Location::caller())bug!(
1826 "`ptr_metadata_ty` failed to get metadata for type: {self:?} (tail = {tail:?})"
1827 ),
1828 }
1829 }
1830
1831 #[track_caller]
1840 pub fn pointee_metadata_ty_or_projection(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
1841 let Some(pointee_ty) = self.builtin_deref(true) else {
1842 ::rustc_span::macros::bug_impl(None,
format_args!("Type {0:?} is not a pointer or reference type", self),
Location::caller())bug!("Type {self:?} is not a pointer or reference type")
1843 };
1844 if pointee_ty.has_trivial_sizedness(tcx, SizedTraitKind::Sized) {
1845 tcx.types.unit
1846 } else {
1847 match pointee_ty.ptr_metadata_ty_or_tail(tcx, |x| x.skip_norm_wip()) {
1848 Ok(metadata_ty) => metadata_ty,
1849 Err(tail_ty) => {
1850 let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, DUMMY_SP);
1851 Ty::new_projection(tcx, ty::IsRigid::No, metadata_def_id, [tail_ty])
1852 }
1853 }
1854 }
1855 }
1856
1857 pub fn to_opt_closure_kind(self) -> Option<ty::ClosureKind> {
1897 match self.kind() {
1898 Int(int_ty) => match int_ty {
1899 ty::IntTy::I8 => Some(ty::ClosureKind::Fn),
1900 ty::IntTy::I16 => Some(ty::ClosureKind::FnMut),
1901 ty::IntTy::I32 => Some(ty::ClosureKind::FnOnce),
1902 _ => ::rustc_span::macros::bug_impl(None,
format_args!("cannot convert type `{0:?}` to a closure kind", self),
Location::caller())bug!("cannot convert type `{:?}` to a closure kind", self),
1903 },
1904
1905 Bound(..) | Placeholder(_) | Param(_) | Infer(_) => None,
1909
1910 Error(_) => Some(ty::ClosureKind::Fn),
1911
1912 _ => ::rustc_span::macros::bug_impl(None,
format_args!("cannot convert type `{0:?}` to a closure kind", self),
Location::caller())bug!("cannot convert type `{:?}` to a closure kind", self),
1913 }
1914 }
1915
1916 pub fn from_closure_kind(tcx: TyCtxt<'tcx>, kind: ty::ClosureKind) -> Ty<'tcx> {
1919 match kind {
1920 ty::ClosureKind::Fn => tcx.types.i8,
1921 ty::ClosureKind::FnMut => tcx.types.i16,
1922 ty::ClosureKind::FnOnce => tcx.types.i32,
1923 }
1924 }
1925
1926 pub fn from_coroutine_closure_kind(tcx: TyCtxt<'tcx>, kind: ty::ClosureKind) -> Ty<'tcx> {
1939 match kind {
1940 ty::ClosureKind::Fn | ty::ClosureKind::FnMut => tcx.types.i16,
1941 ty::ClosureKind::FnOnce => tcx.types.i32,
1942 }
1943 }
1944
1945 {}
#[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("has_trivial_sizedness",
"rustc_middle::ty::sty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/5df8c02afdf6b882bc301442cea70f026e3d3974/compiler/rustc_middle/src/ty/sty.rs"),
::tracing_core::__macro_support::Option::Some(1954u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::ty::sty"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self")
}> =
::tracing::__macro_support::FieldName::new("self");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("sizedness")
}> =
::tracing::__macro_support::FieldName::new("sizedness");
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(&self)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&sizedness)
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: bool = loop {};
return __tracing_attr_fake_return;
}
{
match self.kind() {
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | ty::Uint(_) |
ty::Int(_) | ty::Bool | ty::Float(_) | ty::FnDef(..) |
ty::FnPtr(..) | ty::UnsafeBinder(_) | ty::RawPtr(..) |
ty::Char | ty::Ref(..) | ty::Coroutine(..) |
ty::CoroutineWitness(..) | ty::Array(..) | ty::Pat(..) |
ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never |
ty::Error(_) => true,
ty::Str | ty::Slice(_) | ty::Dynamic(_, _) =>
match sizedness {
SizedTraitKind::Sized => false,
SizedTraitKind::MetaSized => true,
},
ty::Foreign(..) =>
match sizedness {
SizedTraitKind::Sized | SizedTraitKind::MetaSized => false,
},
ty::Tuple(tys) =>
tys.last().is_none_or(|ty|
ty.has_trivial_sizedness(tcx, sizedness)),
ty::Adt(def, args) =>
def.sizedness_constraint(tcx,
sizedness).is_none_or(|ty|
{
ty.instantiate(tcx,
args).skip_norm_wip().has_trivial_sizedness(tcx, sizedness)
}),
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) |
ty::Bound(..) | ty::View(..) => {
false
}
ty::Infer(ty::TyVar(_)) => false,
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) |
ty::FreshFloatTy(_)) => {
::rustc_span::macros::bug_impl(None,
format_args!("`has_trivial_sizedness` applied to unexpected type: {0:?}",
self), Location::caller())
}
}
}
}
}#[instrument(skip(tcx), level = "debug")]
1955 pub fn has_trivial_sizedness(self, tcx: TyCtxt<'tcx>, sizedness: SizedTraitKind) -> bool {
1956 match self.kind() {
1957 ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
1958 | ty::Uint(_)
1959 | ty::Int(_)
1960 | ty::Bool
1961 | ty::Float(_)
1962 | ty::FnDef(..)
1963 | ty::FnPtr(..)
1964 | ty::UnsafeBinder(_)
1965 | ty::RawPtr(..)
1966 | ty::Char
1967 | ty::Ref(..)
1968 | ty::Coroutine(..)
1969 | ty::CoroutineWitness(..)
1970 | ty::Array(..)
1971 | ty::Pat(..)
1972 | ty::Closure(..)
1973 | ty::CoroutineClosure(..)
1974 | ty::Never
1975 | ty::Error(_) => true,
1976
1977 ty::Str | ty::Slice(_) | ty::Dynamic(_, _) => match sizedness {
1978 SizedTraitKind::Sized => false,
1979 SizedTraitKind::MetaSized => true,
1980 },
1981
1982 ty::Foreign(..) => match sizedness {
1983 SizedTraitKind::Sized | SizedTraitKind::MetaSized => false,
1984 },
1985
1986 ty::Tuple(tys) => tys.last().is_none_or(|ty| ty.has_trivial_sizedness(tcx, sizedness)),
1987
1988 ty::Adt(def, args) => def.sizedness_constraint(tcx, sizedness).is_none_or(|ty| {
1989 ty.instantiate(tcx, args).skip_norm_wip().has_trivial_sizedness(tcx, sizedness)
1990 }),
1991
1992 ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) | ty::Bound(..) | ty::View(..) => {
1993 false
1994 }
1995
1996 ty::Infer(ty::TyVar(_)) => false,
1997
1998 ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
1999 bug!("`has_trivial_sizedness` applied to unexpected type: {:?}", self)
2000 }
2001 }
2002 }
2003
2004 pub fn is_trivially_pure_clone_copy(self) -> bool {
2013 match self.kind() {
2014 ty::Bool | ty::Char | ty::Never => true,
2015
2016 ty::Str | ty::Slice(..) | ty::Foreign(..) | ty::Dynamic(..) => false,
2018
2019 ty::Infer(ty::InferTy::FloatVar(_) | ty::InferTy::IntVar(_))
2020 | ty::Int(..)
2021 | ty::Uint(..)
2022 | ty::Float(..) => true,
2023
2024 ty::FnDef(..) => true,
2026
2027 ty::Array(element_ty, _len) => element_ty.is_trivially_pure_clone_copy(),
2028
2029 ty::Tuple(field_tys) => {
2031 field_tys.len() <= 3 && field_tys.iter().all(Self::is_trivially_pure_clone_copy)
2032 }
2033
2034 ty::Pat(ty, _) => ty.is_trivially_pure_clone_copy(),
2035
2036 ty::FnPtr(..) => false,
2039
2040 ty::Ref(_, _, hir::Mutability::Mut) => false,
2042
2043 ty::Ref(_, _, hir::Mutability::Not) | ty::RawPtr(..) => true,
2046
2047 ty::Coroutine(..) | ty::CoroutineWitness(..) => false,
2048
2049 ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) => false,
2051
2052 ty::UnsafeBinder(_) => false,
2053
2054 ty::Alias(..) => false,
2056
2057 ty::Param(..) | ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) | ty::Error(..) => {
2058 false
2059 }
2060
2061 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
2063 }
2064 }
2065
2066 pub fn is_trivially_wf(self, tcx: TyCtxt<'tcx>) -> bool {
2067 match *self.kind() {
2068 ty::Bool
2069 | ty::Char
2070 | ty::Int(_)
2071 | ty::Uint(_)
2072 | ty::Float(_)
2073 | ty::Str
2074 | ty::Never
2075 | ty::Param(_)
2076 | ty::Placeholder(_)
2077 | ty::Bound(..) => true,
2078
2079 ty::Slice(ty) => {
2080 ty.is_trivially_wf(tcx) && ty.has_trivial_sizedness(tcx, SizedTraitKind::Sized)
2081 }
2082 ty::RawPtr(ty, _) => ty.is_trivially_wf(tcx),
2083
2084 ty::FnPtr(sig_tys, _) => {
2085 sig_tys.skip_binder().inputs_and_output.iter().all(|ty| ty.is_trivially_wf(tcx))
2086 }
2087 ty::Ref(_, ty, _) => ty.is_global() && ty.is_trivially_wf(tcx),
2088
2089 ty::Infer(infer) => match infer {
2090 ty::TyVar(_) => false,
2091 ty::IntVar(_) | ty::FloatVar(_) => true,
2092 ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => true,
2093 },
2094
2095 ty::Adt(_, _)
2096 | ty::Tuple(_)
2097 | ty::Array(..)
2098 | ty::Foreign(_)
2099 | ty::Pat(_, _)
2100 | ty::FnDef(..)
2101 | ty::UnsafeBinder(..)
2102 | ty::Dynamic(..)
2103 | ty::Closure(..)
2104 | ty::CoroutineClosure(..)
2105 | ty::Coroutine(..)
2106 | ty::CoroutineWitness(..)
2107 | ty::Alias(..)
2108 | ty::View(..)
2109 | ty::Error(_) => false,
2110 }
2111 }
2112
2113 pub fn primitive_symbol(self) -> Option<Symbol> {
2115 match self.kind() {
2116 ty::Bool => Some(sym::bool),
2117 ty::Char => Some(sym::char),
2118 ty::Int(i) => Some(i.name()),
2119 ty::Uint(u) => Some(u.name()),
2120 ty::Float(f) => Some(f.name()),
2121 ty::Str => Some(sym::str),
2122 _ => None,
2123 }
2124 }
2125
2126 pub fn is_c_void(self, tcx: TyCtxt<'_>) -> bool {
2127 match self.kind() {
2128 ty::Adt(adt, _) => tcx.is_lang_item(adt.did(), LangItem::CVoid),
2129 _ => false,
2130 }
2131 }
2132
2133 pub fn is_async_drop_in_place_coroutine(self, tcx: TyCtxt<'_>) -> bool {
2134 match self.kind() {
2135 ty::Coroutine(def, ..) => tcx.is_async_drop_in_place_coroutine(*def),
2136 _ => false,
2137 }
2138 }
2139
2140 pub fn is_known_rigid(self) -> bool {
2146 self.kind().is_known_rigid()
2147 }
2148
2149 pub fn walk(self) -> TypeWalker<TyCtxt<'tcx>> {
2160 TypeWalker::new(self.into())
2161 }
2162
2163 #[inline]
2166 pub fn is_like_maybe_dangling(self) -> bool {
2167 match self.kind() {
2168 ty::Adt(def, _) => {
2169 def.flags().contains(AdtFlags::IS_MAYBE_DANGLING)
2172 || def.flags().contains(AdtFlags::IS_MANUALLY_DROP)
2173 }
2174 ty::Coroutine(..) => true,
2175 _ => false,
2176 }
2177 }
2178}
2179
2180impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
2181 fn inputs(self) -> &'tcx [Ty<'tcx>] {
2182 self.split_last().unwrap().1
2183 }
2184
2185 fn output(self) -> Ty<'tcx> {
2186 *self.split_last().unwrap().0
2187 }
2188}
2189
2190impl<'tcx> rustc_type_ir::inherent::Symbol<TyCtxt<'tcx>> for Symbol {
2191 const KW_UNDERSCORE_LIFETIME: Self = kw::UnderscoreLifetime;
2192 const KW_STATIC_LIFETIME: Self = kw::StaticLifetime;
2193 const SYM_ANON: Self = sym::anon;
2194}
2195
2196#[cfg(target_pointer_width = "64")]
2198mod size_asserts {
2199 use rustc_data_structures::static_assert_size;
2200
2201 use super::*;
2202 const _: [(); 32] = [(); ::std::mem::size_of::<TyKind<'_>>()];static_assert_size!(TyKind<'_>, 32);
2204 const _: [(); 40] =
[(); ::std::mem::size_of::<ty::WithCachedTypeInfo<TyKind<'_>>>()];static_assert_size!(ty::WithCachedTypeInfo<TyKind<'_>>, 40);
2205 }