1use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
9use rustc_span::Span;
10
11use crate::error::DropCheckOverflow;
12use crate::infer::canonical::{Canonical, CanonicalQueryInput, QueryResponse};
13pub use crate::traits::solve::NoSolution;
14use crate::ty::{self, GenericArg, Ty, TyCtxt};
15
16pub mod type_op {
17 use rustc_macros::{HashStable, TypeFoldable, TypeVisitable};
18
19 use crate::ty::{Predicate, Ty, UserType};
20
21 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
22 pub struct AscribeUserType<'tcx> {
23 pub mir_ty: Ty<'tcx>,
24 pub user_ty: UserType<'tcx>,
25 }
26
27 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
28 pub struct Eq<'tcx> {
29 pub a: Ty<'tcx>,
30 pub b: Ty<'tcx>,
31 }
32
33 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
34 pub struct Subtype<'tcx> {
35 pub sub: Ty<'tcx>,
36 pub sup: Ty<'tcx>,
37 }
38
39 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
40 pub struct ProvePredicate<'tcx> {
41 pub predicate: Predicate<'tcx>,
42 }
43
44 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
46 pub struct Normalize<T> {
47 pub value: T,
48 }
49
50 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
52 pub struct DeeplyNormalize<T> {
53 pub value: T,
54 }
55
56 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
57 pub struct ImpliedOutlivesBounds<'tcx> {
58 pub ty: Ty<'tcx>,
59 }
60
61 #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
62 pub struct DropckOutlives<'tcx> {
63 pub dropped_ty: Ty<'tcx>,
64 }
65}
66
67pub type CanonicalAliasGoal<'tcx> =
68 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>;
69
70pub type CanonicalTyGoal<'tcx> = CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, Ty<'tcx>>>;
71
72pub type CanonicalPredicateGoal<'tcx> =
73 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, ty::Predicate<'tcx>>>;
74
75pub type CanonicalTypeOpAscribeUserTypeGoal<'tcx> =
76 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>;
77
78pub type CanonicalTypeOpEqGoal<'tcx> =
79 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Eq<'tcx>>>;
80
81pub type CanonicalTypeOpSubtypeGoal<'tcx> =
82 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Subtype<'tcx>>>;
83
84pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
85 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ProvePredicate<'tcx>>>;
86
87pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
88 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
89
90pub type CanonicalTypeOpDeeplyNormalizeGoal<'tcx, T> =
91 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::DeeplyNormalize<T>>>;
92
93pub type CanonicalImpliedOutlivesBoundsGoal<'tcx> =
94 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ImpliedOutlivesBounds<'tcx>>>;
95
96pub type CanonicalDropckOutlivesGoal<'tcx> =
97 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::DropckOutlives<'tcx>>>;
98
99#[derive(Clone, Debug, Default, HashStable, TypeFoldable, TypeVisitable)]
100pub struct DropckOutlivesResult<'tcx> {
101 pub kinds: Vec<GenericArg<'tcx>>,
102 pub overflows: Vec<Ty<'tcx>>,
103}
104
105impl<'tcx> DropckOutlivesResult<'tcx> {
106 pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
107 if let Some(overflow_ty) = self.overflows.get(0) {
108 tcx.dcx().emit_err(DropCheckOverflow { span, ty, overflow_ty: *overflow_ty });
109 }
110 }
111}
112
113#[derive(Clone, Debug, HashStable)]
116pub struct DropckConstraint<'tcx> {
117 pub outlives: Vec<ty::GenericArg<'tcx>>,
120
121 pub dtorck_types: Vec<Ty<'tcx>>,
123
124 pub overflows: Vec<Ty<'tcx>>,
128}
129
130impl<'tcx> DropckConstraint<'tcx> {
131 pub fn empty() -> DropckConstraint<'tcx> {
132 DropckConstraint { outlives: vec![], dtorck_types: vec![], overflows: vec![] }
133 }
134}
135
136impl<'tcx> FromIterator<DropckConstraint<'tcx>> for DropckConstraint<'tcx> {
137 fn from_iter<I: IntoIterator<Item = DropckConstraint<'tcx>>>(iter: I) -> Self {
138 let mut result = Self::empty();
139
140 for DropckConstraint { outlives, dtorck_types, overflows } in iter {
141 result.outlives.extend(outlives);
142 result.dtorck_types.extend(dtorck_types);
143 result.overflows.extend(overflows);
144 }
145
146 result
147 }
148}
149
150#[derive(Debug, HashStable)]
151pub struct CandidateStep<'tcx> {
152 pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
153 pub autoderefs: usize,
154 pub from_unsafe_deref: bool,
160 pub unsize: bool,
161 pub reachable_via_deref: bool,
170}
171
172#[derive(Copy, Clone, Debug, HashStable)]
173pub struct MethodAutoderefStepsResult<'tcx> {
174 pub steps: &'tcx [CandidateStep<'tcx>],
177 pub opt_bad_ty: Option<&'tcx MethodAutoderefBadTy<'tcx>>,
179 pub reached_recursion_limit: bool,
182}
183
184#[derive(Debug, HashStable)]
185pub struct MethodAutoderefBadTy<'tcx> {
186 pub reached_raw_pointer: bool,
187 pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
188}
189
190#[derive(Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
192pub struct NormalizationResult<'tcx> {
193 pub normalized_ty: Ty<'tcx>,
195}
196
197#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, HashStable)]
205pub enum OutlivesBound<'tcx> {
206 RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
207 RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
208 RegionSubAlias(ty::Region<'tcx>, ty::AliasTy<'tcx>),
209}