1use std::fmt::{self, Debug};
4
5use rustc_abi::{FieldIdx, VariantIdx};
6use rustc_errors::ErrorGuaranteed;
7use rustc_index::IndexVec;
8use rustc_index::bit_set::BitMatrix;
9use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
10use rustc_span::{Span, Symbol};
11
12use super::{ConstValue, SourceInfo};
13use crate::ty::{self, CoroutineArgsExt, Ty};
14
15rustc_index::newtype_index! {
16 #[derive(HashStable)]
17 #[encodable]
18 #[debug_format = "_s{}"]
19 pub struct CoroutineSavedLocal {}
20}
21
22#[derive(Clone, Debug, PartialEq, Eq)]
23#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
24pub struct CoroutineSavedTy<'tcx> {
25 pub ty: Ty<'tcx>,
26 pub source_info: SourceInfo,
28 pub ignore_for_traits: bool,
30}
31
32#[derive(Clone, PartialEq, Eq)]
34#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
35pub struct CoroutineLayout<'tcx> {
36 pub field_tys: IndexVec<CoroutineSavedLocal, CoroutineSavedTy<'tcx>>,
38
39 pub field_names: IndexVec<CoroutineSavedLocal, Option<Symbol>>,
41
42 pub variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>>,
45
46 pub variant_source_info: IndexVec<VariantIdx, SourceInfo>,
49
50 #[type_foldable(identity)]
54 #[type_visitable(ignore)]
55 pub storage_conflicts: BitMatrix<CoroutineSavedLocal, CoroutineSavedLocal>,
56}
57
58impl Debug for CoroutineLayout<'_> {
59 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
60 fmt.debug_struct("CoroutineLayout")
61 .field_with("field_tys", |fmt| {
62 fmt.debug_map().entries(self.field_tys.iter_enumerated()).finish()
63 })
64 .field_with("variant_fields", |fmt| {
65 let mut map = fmt.debug_map();
66 for (idx, fields) in self.variant_fields.iter_enumerated() {
67 map.key_with(|fmt| {
68 let variant_name = ty::CoroutineArgs::variant_name(idx);
69 if fmt.alternate() {
70 write!(fmt, "{variant_name:9}({idx:?})")
71 } else {
72 write!(fmt, "{variant_name}")
73 }
74 });
75 map.value_with(|fmt| write!(fmt, "{fields:?}"));
77 }
78 map.finish()
79 })
80 .field("storage_conflicts", &self.storage_conflicts)
81 .finish()
82 }
83}
84
85#[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
91pub struct ConstQualifs {
92 pub has_mut_interior: bool,
93 pub needs_drop: bool,
94 pub needs_non_const_drop: bool,
95 pub tainted_by_errors: Option<ErrorGuaranteed>,
96}
97#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
103#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
104pub enum ConstraintCategory<'tcx> {
105 Return(ReturnConstraint),
106 Yield,
107 UseAsConst,
108 UseAsStatic,
109 TypeAnnotation(AnnotationSource),
110 Cast {
111 is_raw_ptr_dyn_type_cast: bool,
112 is_implicit_coercion: bool,
114 unsize_to: Option<Ty<'tcx>>,
117 },
118
119 CallArgument(Option<Ty<'tcx>>),
121 CopyBound,
122 SizedBound,
123 Assignment,
124 Usage,
127 OpaqueType,
128 ClosureUpvar(FieldIdx),
129
130 Predicate(Span),
134
135 Boring,
139 BoringNoLocation,
141
142 Internal,
144
145 OutlivesUnnameablePlaceholder(
150 #[type_foldable(identity)]
151 #[type_visitable(ignore)]
152 ty::RegionVid,
153 ),
154}
155
156#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
157#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
158pub enum ReturnConstraint {
159 Normal,
160 ClosureUpvar(FieldIdx),
161}
162
163#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
164#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
165pub enum AnnotationSource {
166 Ascription,
167 Declaration,
168 OpaqueCast,
169 GenericArg,
170}
171
172#[derive(Copy, Clone, Debug, HashStable)]
174pub struct DestructuredConstant<'tcx> {
175 pub variant: Option<VariantIdx>,
176 pub fields: &'tcx [(ConstValue, Ty<'tcx>)],
177}