1use std::fmt::{self, Debug};
4
5use rustc_abi::{FieldIdx, VariantIdx};
6use rustc_data_structures::fx::FxIndexMap;
7use rustc_errors::ErrorGuaranteed;
8use rustc_hir::def_id::LocalDefId;
9use rustc_index::IndexVec;
10use rustc_index::bit_set::BitMatrix;
11use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
12use rustc_span::{Span, Symbol};
13
14use super::{ConstValue, SourceInfo};
15use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty};
16
17rustc_index::newtype_index! {
18 #[derive(HashStable)]
19 #[encodable]
20 #[debug_format = "_{}"]
21 pub struct CoroutineSavedLocal {}
22}
23
24#[derive(Clone, Debug, PartialEq, Eq)]
25#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
26pub struct CoroutineSavedTy<'tcx> {
27 pub ty: Ty<'tcx>,
28 pub source_info: SourceInfo,
30 pub ignore_for_traits: bool,
32}
33
34#[derive(Clone, PartialEq, Eq)]
36#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
37pub struct CoroutineLayout<'tcx> {
38 pub field_tys: IndexVec<CoroutineSavedLocal, CoroutineSavedTy<'tcx>>,
40
41 pub field_names: IndexVec<CoroutineSavedLocal, Option<Symbol>>,
43
44 pub variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>>,
47
48 pub variant_source_info: IndexVec<VariantIdx, SourceInfo>,
51
52 #[type_foldable(identity)]
56 #[type_visitable(ignore)]
57 pub storage_conflicts: BitMatrix<CoroutineSavedLocal, CoroutineSavedLocal>,
58}
59
60impl Debug for CoroutineLayout<'_> {
61 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
62 fmt.debug_struct("CoroutineLayout")
63 .field_with("field_tys", |fmt| {
64 fmt.debug_map().entries(self.field_tys.iter_enumerated()).finish()
65 })
66 .field_with("variant_fields", |fmt| {
67 let mut map = fmt.debug_map();
68 for (idx, fields) in self.variant_fields.iter_enumerated() {
69 map.key_with(|fmt| {
70 let variant_name = ty::CoroutineArgs::variant_name(idx);
71 if fmt.alternate() {
72 write!(fmt, "{variant_name:9}({idx:?})")
73 } else {
74 write!(fmt, "{variant_name}")
75 }
76 });
77 map.value_with(|fmt| write!(fmt, "{fields:?}"));
79 }
80 map.finish()
81 })
82 .field("storage_conflicts", &self.storage_conflicts)
83 .finish()
84 }
85}
86
87#[derive(Default, Debug, TyEncodable, TyDecodable, HashStable)]
91pub struct ConcreteOpaqueTypes<'tcx>(pub FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>);
92
93#[derive(Clone, Copy, Debug, Default, TyEncodable, TyDecodable, HashStable)]
99pub struct ConstQualifs {
100 pub has_mut_interior: bool,
101 pub needs_drop: bool,
102 pub needs_non_const_drop: bool,
103 pub tainted_by_errors: Option<ErrorGuaranteed>,
104}
105#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
111#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
112pub enum ConstraintCategory<'tcx> {
113 Return(ReturnConstraint),
114 Yield,
115 UseAsConst,
116 UseAsStatic,
117 TypeAnnotation(AnnotationSource),
118 Cast {
119 is_implicit_coercion: bool,
121 unsize_to: Option<Ty<'tcx>>,
124 },
125
126 CallArgument(Option<Ty<'tcx>>),
128 CopyBound,
129 SizedBound,
130 Assignment,
131 Usage,
134 OpaqueType,
135 ClosureUpvar(FieldIdx),
136
137 Predicate(Span),
141
142 Boring,
146 BoringNoLocation,
148
149 Internal,
151
152 IllegalUniverse,
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<'tcx>, Ty<'tcx>)],
177}