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_implicit_coercion: bool,
113 unsize_to: Option<Ty<'tcx>>,
116 },
117
118 CallArgument(Option<Ty<'tcx>>),
120 CopyBound,
121 SizedBound,
122 Assignment,
123 Usage,
126 OpaqueType,
127 ClosureUpvar(FieldIdx),
128
129 Predicate(Span),
133
134 Boring,
138 BoringNoLocation,
140
141 Internal,
143
144 OutlivesUnnameablePlaceholder(
149 #[type_foldable(identity)]
150 #[type_visitable(ignore)]
151 ty::RegionVid,
152 ),
153}
154
155#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
156#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
157pub enum ReturnConstraint {
158 Normal,
159 ClosureUpvar(FieldIdx),
160}
161
162#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
163#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
164pub enum AnnotationSource {
165 Ascription,
166 Declaration,
167 OpaqueCast,
168 GenericArg,
169}
170
171#[derive(Copy, Clone, Debug, HashStable)]
173pub struct DestructuredConstant<'tcx> {
174 pub variant: Option<VariantIdx>,
175 pub fields: &'tcx [(ConstValue, Ty<'tcx>)],
176}