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 CanonicalTypeOpProvePredicateGoal<'tcx> =
79 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ProvePredicate<'tcx>>>;
80
81pub type CanonicalTypeOpNormalizeGoal<'tcx, T> =
82 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::Normalize<T>>>;
83
84pub type CanonicalTypeOpDeeplyNormalizeGoal<'tcx, T> =
85 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::DeeplyNormalize<T>>>;
86
87pub type CanonicalImpliedOutlivesBoundsGoal<'tcx> =
88 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::ImpliedOutlivesBounds<'tcx>>>;
89
90pub type CanonicalDropckOutlivesGoal<'tcx> =
91 CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, type_op::DropckOutlives<'tcx>>>;
92
93#[derive(Clone, Debug, Default, HashStable, TypeFoldable, TypeVisitable)]
94pub struct DropckOutlivesResult<'tcx> {
95 pub kinds: Vec<GenericArg<'tcx>>,
96 pub overflows: Vec<Ty<'tcx>>,
97}
98
99impl<'tcx> DropckOutlivesResult<'tcx> {
100 pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
101 if let Some(overflow_ty) = self.overflows.get(0) {
102 tcx.dcx().emit_err(DropCheckOverflow { span, ty, overflow_ty: *overflow_ty });
103 }
104 }
105}
106
107#[derive(Clone, Debug, HashStable)]
110pub struct DropckConstraint<'tcx> {
111 pub outlives: Vec<ty::GenericArg<'tcx>>,
114
115 pub dtorck_types: Vec<Ty<'tcx>>,
117
118 pub overflows: Vec<Ty<'tcx>>,
122}
123
124impl<'tcx> DropckConstraint<'tcx> {
125 pub fn empty() -> DropckConstraint<'tcx> {
126 DropckConstraint { outlives: vec![], dtorck_types: vec![], overflows: vec![] }
127 }
128}
129
130impl<'tcx> FromIterator<DropckConstraint<'tcx>> for DropckConstraint<'tcx> {
131 fn from_iter<I: IntoIterator<Item = DropckConstraint<'tcx>>>(iter: I) -> Self {
132 let mut result = Self::empty();
133
134 for DropckConstraint { outlives, dtorck_types, overflows } in iter {
135 result.outlives.extend(outlives);
136 result.dtorck_types.extend(dtorck_types);
137 result.overflows.extend(overflows);
138 }
139
140 result
141 }
142}
143
144#[derive(Debug, HashStable)]
145pub struct CandidateStep<'tcx> {
146 pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
147 pub autoderefs: usize,
148 pub from_unsafe_deref: bool,
154 pub unsize: bool,
155 pub reachable_via_deref: bool,
164}
165
166#[derive(Copy, Clone, Debug, HashStable)]
167pub struct MethodAutoderefStepsResult<'tcx> {
168 pub steps: &'tcx [CandidateStep<'tcx>],
171 pub opt_bad_ty: Option<&'tcx MethodAutoderefBadTy<'tcx>>,
173 pub reached_recursion_limit: bool,
176}
177
178#[derive(Debug, HashStable)]
179pub struct MethodAutoderefBadTy<'tcx> {
180 pub reached_raw_pointer: bool,
181 pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
182}
183
184#[derive(Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
186pub struct NormalizationResult<'tcx> {
187 pub normalized_ty: Ty<'tcx>,
189}
190
191#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, HashStable)]
199pub enum OutlivesBound<'tcx> {
200 RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
201 RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
202 RegionSubAlias(ty::Region<'tcx>, ty::AliasTy<'tcx>),
203}