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