]>
Commit | Line | Data |
---|---|---|
9fa01778 | 1 | use crate::traits; |
f9f354fc | 2 | use crate::ty::{Lift, TyCtxt}; |
e9174d1e SL |
3 | |
4 | use std::fmt; | |
5bcae85e | 5 | use std::rc::Rc; |
e9174d1e | 6 | |
dc9dc135 | 7 | // Structural impls for the structs in `traits`. |
e9174d1e | 8 | |
f035d41b | 9 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> { |
0bf4aa26 | 10 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
e9174d1e | 11 | match *self { |
f035d41b | 12 | super::ImplSourceUserDefined(ref v) => write!(f, "{:?}", v), |
e9174d1e | 13 | |
f035d41b | 14 | super::ImplSourceAutoImpl(ref t) => write!(f, "{:?}", t), |
e9174d1e | 15 | |
f035d41b | 16 | super::ImplSourceClosure(ref d) => write!(f, "{:?}", d), |
e9174d1e | 17 | |
f035d41b | 18 | super::ImplSourceGenerator(ref d) => write!(f, "{:?}", d), |
ea8adc8c | 19 | |
f035d41b | 20 | super::ImplSourceFnPointer(ref d) => write!(f, "ImplSourceFnPointer({:?})", d), |
e9174d1e | 21 | |
f035d41b | 22 | super::ImplSourceDiscriminantKind(ref d) => write!(f, "{:?}", d), |
f9f354fc | 23 | |
f035d41b | 24 | super::ImplSourceObject(ref d) => write!(f, "{:?}", d), |
e9174d1e | 25 | |
f035d41b | 26 | super::ImplSourceParam(ref n) => write!(f, "ImplSourceParam({:?})", n), |
e9174d1e | 27 | |
f035d41b | 28 | super::ImplSourceBuiltin(ref d) => write!(f, "{:?}", d), |
a1dfa0c6 | 29 | |
f035d41b | 30 | super::ImplSourceTraitAlias(ref d) => write!(f, "{:?}", d), |
e9174d1e SL |
31 | } |
32 | } | |
33 | } | |
34 | ||
f035d41b | 35 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceUserDefinedData<'tcx, N> { |
0bf4aa26 | 36 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
94b46f34 XL |
37 | write!( |
38 | f, | |
f035d41b | 39 | "ImplSourceUserDefinedData(impl_def_id={:?}, substs={:?}, nested={:?})", |
94b46f34 XL |
40 | self.impl_def_id, self.substs, self.nested |
41 | ) | |
e9174d1e SL |
42 | } |
43 | } | |
44 | ||
f035d41b | 45 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceGeneratorData<'tcx, N> { |
0bf4aa26 | 46 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
94b46f34 XL |
47 | write!( |
48 | f, | |
f035d41b | 49 | "ImplSourceGeneratorData(generator_def_id={:?}, substs={:?}, nested={:?})", |
94b46f34 XL |
50 | self.generator_def_id, self.substs, self.nested |
51 | ) | |
ea8adc8c XL |
52 | } |
53 | } | |
54 | ||
f035d41b | 55 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceClosureData<'tcx, N> { |
0bf4aa26 | 56 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
94b46f34 XL |
57 | write!( |
58 | f, | |
f035d41b | 59 | "ImplSourceClosureData(closure_def_id={:?}, substs={:?}, nested={:?})", |
94b46f34 XL |
60 | self.closure_def_id, self.substs, self.nested |
61 | ) | |
e9174d1e SL |
62 | } |
63 | } | |
64 | ||
f035d41b | 65 | impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceBuiltinData<N> { |
0bf4aa26 | 66 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
f035d41b | 67 | write!(f, "ImplSourceBuiltinData(nested={:?})", self.nested) |
e9174d1e SL |
68 | } |
69 | } | |
70 | ||
f035d41b | 71 | impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceAutoImplData<N> { |
0bf4aa26 | 72 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
94b46f34 XL |
73 | write!( |
74 | f, | |
f035d41b | 75 | "ImplSourceAutoImplData(trait_def_id={:?}, nested={:?})", |
94b46f34 XL |
76 | self.trait_def_id, self.nested |
77 | ) | |
e9174d1e SL |
78 | } |
79 | } | |
80 | ||
f035d41b | 81 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<'tcx, N> { |
0bf4aa26 | 82 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
94b46f34 XL |
83 | write!( |
84 | f, | |
f035d41b | 85 | "ImplSourceObjectData(upcast={:?}, vtable_base={}, nested={:?})", |
94b46f34 XL |
86 | self.upcast_trait_ref, self.vtable_base, self.nested |
87 | ) | |
a7813a04 XL |
88 | } |
89 | } | |
90 | ||
f035d41b | 91 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceFnPointerData<'tcx, N> { |
0bf4aa26 | 92 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
f035d41b | 93 | write!(f, "ImplSourceFnPointerData(fn_ty={:?}, nested={:?})", self.fn_ty, self.nested) |
e9174d1e SL |
94 | } |
95 | } | |
96 | ||
f035d41b | 97 | impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx, N> { |
a1dfa0c6 XL |
98 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
99 | write!( | |
100 | f, | |
f035d41b | 101 | "ImplSourceTraitAlias(alias_def_id={:?}, substs={:?}, nested={:?})", |
a1dfa0c6 XL |
102 | self.alias_def_id, self.substs, self.nested |
103 | ) | |
104 | } | |
105 | } | |
106 | ||
a7813a04 XL |
107 | /////////////////////////////////////////////////////////////////////////// |
108 | // Lift implementations | |
109 | ||
110 | impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> { | |
111 | type Lifted = traits::SelectionError<'tcx>; | |
dc9dc135 | 112 | fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { |
a7813a04 XL |
113 | match *self { |
114 | super::Unimplemented => Some(super::Unimplemented), | |
115 | super::OutputTypeParameterMismatch(a, b, ref err) => { | |
dfeec247 XL |
116 | tcx.lift(&(a, b)).and_then(|(a, b)| { |
117 | tcx.lift(err).map(|err| super::OutputTypeParameterMismatch(a, b, err)) | |
118 | }) | |
a7813a04 | 119 | } |
94b46f34 | 120 | super::TraitNotObjectSafe(def_id) => Some(super::TraitNotObjectSafe(def_id)), |
a1dfa0c6 | 121 | super::ConstEvalFailure(err) => Some(super::ConstEvalFailure(err)), |
0bf4aa26 | 122 | super::Overflow => Some(super::Overflow), |
a7813a04 XL |
123 | } |
124 | } | |
125 | } | |
126 | ||
5bcae85e SL |
127 | impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> { |
128 | type Lifted = traits::ObligationCauseCode<'tcx>; | |
dc9dc135 | 129 | fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { |
5bcae85e | 130 | match *self { |
cc61c64b | 131 | super::ReturnNoExpression => Some(super::ReturnNoExpression), |
5bcae85e SL |
132 | super::MiscObligation => Some(super::MiscObligation), |
133 | super::SliceOrArrayElem => Some(super::SliceOrArrayElem), | |
134 | super::TupleElem => Some(super::TupleElem), | |
135 | super::ProjectionWf(proj) => tcx.lift(&proj).map(super::ProjectionWf), | |
136 | super::ItemObligation(def_id) => Some(super::ItemObligation(def_id)), | |
e1599b0c | 137 | super::BindingObligation(def_id, span) => Some(super::BindingObligation(def_id, span)), |
5bcae85e SL |
138 | super::ReferenceOutlivesReferent(ty) => { |
139 | tcx.lift(&ty).map(super::ReferenceOutlivesReferent) | |
140 | } | |
74b04a01 XL |
141 | super::ObjectTypeBound(ty, r) => { |
142 | tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r))) | |
143 | } | |
94b46f34 | 144 | super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation), |
dfeec247 XL |
145 | super::Coercion { source, target } => { |
146 | Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? }) | |
147 | } | |
5bcae85e | 148 | super::AssignmentLhsSized => Some(super::AssignmentLhsSized), |
041b39d2 | 149 | super::TupleInitializerSized => Some(super::TupleInitializerSized), |
5bcae85e SL |
150 | super::StructInitializerSized => Some(super::StructInitializerSized), |
151 | super::VariableType(id) => Some(super::VariableType(id)), | |
e74abb32 XL |
152 | super::ReturnValue(id) => Some(super::ReturnValue(id)), |
153 | super::ReturnType => Some(super::ReturnType), | |
b7449926 | 154 | super::SizedArgumentType => Some(super::SizedArgumentType), |
041b39d2 | 155 | super::SizedReturnType => Some(super::SizedReturnType), |
2c00a5a8 | 156 | super::SizedYieldType => Some(super::SizedYieldType), |
f9f354fc | 157 | super::InlineAsmSized => Some(super::InlineAsmSized), |
e74abb32 | 158 | super::RepeatVec(suggest_flag) => Some(super::RepeatVec(suggest_flag)), |
b7449926 | 159 | super::FieldSized { adt_kind, last } => Some(super::FieldSized { adt_kind, last }), |
5bcae85e | 160 | super::ConstSized => Some(super::ConstSized), |
e74abb32 | 161 | super::ConstPatternStructural => Some(super::ConstPatternStructural), |
5bcae85e SL |
162 | super::SharedStatic => Some(super::SharedStatic), |
163 | super::BuiltinDerivedObligation(ref cause) => { | |
164 | tcx.lift(cause).map(super::BuiltinDerivedObligation) | |
165 | } | |
166 | super::ImplDerivedObligation(ref cause) => { | |
167 | tcx.lift(cause).map(super::ImplDerivedObligation) | |
168 | } | |
ba9703b0 | 169 | super::DerivedObligation(ref cause) => tcx.lift(cause).map(super::DerivedObligation), |
f9f354fc | 170 | super::CompareImplConstObligation => Some(super::CompareImplConstObligation), |
94b46f34 XL |
171 | super::CompareImplMethodObligation { |
172 | item_name, | |
173 | impl_item_def_id, | |
174 | trait_item_def_id, | |
175 | } => Some(super::CompareImplMethodObligation { | |
176 | item_name, | |
177 | impl_item_def_id, | |
178 | trait_item_def_id, | |
179 | }), | |
dfeec247 XL |
180 | super::CompareImplTypeObligation { item_name, impl_item_def_id, trait_item_def_id } => { |
181 | Some(super::CompareImplTypeObligation { | |
182 | item_name, | |
183 | impl_item_def_id, | |
184 | trait_item_def_id, | |
185 | }) | |
186 | } | |
041b39d2 | 187 | super::ExprAssignable => Some(super::ExprAssignable), |
e1599b0c | 188 | super::MatchExpressionArm(box super::MatchExpressionArmCause { |
94b46f34 | 189 | arm_span, |
9fa01778 XL |
190 | source, |
191 | ref prior_arms, | |
192 | last_ty, | |
dfeec247 XL |
193 | scrut_hir_id, |
194 | }) => tcx.lift(&last_ty).map(|last_ty| { | |
195 | super::MatchExpressionArm(box super::MatchExpressionArmCause { | |
196 | arm_span, | |
197 | source, | |
198 | prior_arms: prior_arms.clone(), | |
199 | last_ty, | |
200 | scrut_hir_id, | |
9fa01778 | 201 | }) |
dfeec247 XL |
202 | }), |
203 | super::Pattern { span, root_ty, origin_expr } => { | |
204 | tcx.lift(&root_ty).map(|root_ty| super::Pattern { span, root_ty, origin_expr }) | |
0731742a | 205 | } |
e1599b0c | 206 | super::IfExpression(box super::IfExpressionCause { then, outer, semicolon }) => { |
dfeec247 | 207 | Some(super::IfExpression(box super::IfExpressionCause { then, outer, semicolon })) |
e1599b0c | 208 | } |
041b39d2 | 209 | super::IfExpressionWithNoElse => Some(super::IfExpressionWithNoElse), |
041b39d2 XL |
210 | super::MainFunctionType => Some(super::MainFunctionType), |
211 | super::StartFunctionType => Some(super::StartFunctionType), | |
212 | super::IntrinsicType => Some(super::IntrinsicType), | |
213 | super::MethodReceiver => Some(super::MethodReceiver), | |
214 | super::BlockTailExpression(id) => Some(super::BlockTailExpression(id)), | |
94b46f34 | 215 | super::TrivialBound => Some(super::TrivialBound), |
5bcae85e SL |
216 | } |
217 | } | |
218 | } | |
219 | ||
220 | impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> { | |
221 | type Lifted = traits::DerivedObligationCause<'tcx>; | |
dc9dc135 | 222 | fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { |
dfeec247 XL |
223 | tcx.lift(&self.parent_trait_ref).and_then(|trait_ref| { |
224 | tcx.lift(&*self.parent_code).map(|code| traits::DerivedObligationCause { | |
225 | parent_trait_ref: trait_ref, | |
226 | parent_code: Rc::new(code), | |
227 | }) | |
228 | }) | |
5bcae85e SL |
229 | } |
230 | } | |
231 | ||
232 | impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCause<'a> { | |
233 | type Lifted = traits::ObligationCause<'tcx>; | |
dc9dc135 | 234 | fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { |
f035d41b | 235 | tcx.lift(&self.code).map(|code| traits::ObligationCause::new(self.span, self.body_id, code)) |
5bcae85e SL |
236 | } |
237 | } | |
238 | ||
94b46f34 | 239 | // For codegen only. |
f035d41b XL |
240 | impl<'a, 'tcx> Lift<'tcx> for traits::ImplSource<'a, ()> { |
241 | type Lifted = traits::ImplSource<'tcx, ()>; | |
dc9dc135 | 242 | fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> { |
a7813a04 | 243 | match self.clone() { |
f035d41b XL |
244 | traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData { |
245 | impl_def_id, | |
246 | substs, | |
247 | nested, | |
248 | }) => tcx.lift(&substs).map(|substs| { | |
249 | traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData { | |
250 | impl_def_id, | |
251 | substs, | |
252 | nested, | |
a7813a04 | 253 | }) |
f035d41b XL |
254 | }), |
255 | traits::ImplSourceAutoImpl(t) => Some(traits::ImplSourceAutoImpl(t)), | |
256 | traits::ImplSourceGenerator(traits::ImplSourceGeneratorData { | |
94b46f34 | 257 | generator_def_id, |
ea8adc8c | 258 | substs, |
94b46f34 | 259 | nested, |
dfeec247 | 260 | }) => tcx.lift(&substs).map(|substs| { |
f035d41b | 261 | traits::ImplSourceGenerator(traits::ImplSourceGeneratorData { |
74b04a01 XL |
262 | generator_def_id, |
263 | substs, | |
264 | nested, | |
ea8adc8c | 265 | }) |
dfeec247 | 266 | }), |
f035d41b XL |
267 | traits::ImplSourceClosure(traits::ImplSourceClosureData { |
268 | closure_def_id, | |
269 | substs, | |
270 | nested, | |
271 | }) => tcx.lift(&substs).map(|substs| { | |
272 | traits::ImplSourceClosure(traits::ImplSourceClosureData { | |
273 | closure_def_id, | |
274 | substs, | |
275 | nested, | |
a7813a04 | 276 | }) |
f035d41b XL |
277 | }), |
278 | traits::ImplSourceFnPointer(traits::ImplSourceFnPointerData { fn_ty, nested }) => { | |
dfeec247 | 279 | tcx.lift(&fn_ty).map(|fn_ty| { |
f035d41b | 280 | traits::ImplSourceFnPointer(traits::ImplSourceFnPointerData { fn_ty, nested }) |
dfeec247 | 281 | }) |
a7813a04 | 282 | } |
f035d41b XL |
283 | traits::ImplSourceDiscriminantKind(traits::ImplSourceDiscriminantKindData) => { |
284 | Some(traits::ImplSourceDiscriminantKind(traits::ImplSourceDiscriminantKindData)) | |
f9f354fc | 285 | } |
f035d41b XL |
286 | traits::ImplSourceParam(n) => Some(traits::ImplSourceParam(n)), |
287 | traits::ImplSourceBuiltin(n) => Some(traits::ImplSourceBuiltin(n)), | |
288 | traits::ImplSourceObject(traits::ImplSourceObjectData { | |
a7813a04 XL |
289 | upcast_trait_ref, |
290 | vtable_base, | |
94b46f34 | 291 | nested, |
dfeec247 | 292 | }) => tcx.lift(&upcast_trait_ref).map(|trait_ref| { |
f035d41b | 293 | traits::ImplSourceObject(traits::ImplSourceObjectData { |
94b46f34 XL |
294 | upcast_trait_ref: trait_ref, |
295 | vtable_base, | |
296 | nested, | |
a7813a04 | 297 | }) |
dfeec247 | 298 | }), |
f035d41b | 299 | traits::ImplSourceTraitAlias(traits::ImplSourceTraitAliasData { |
a1dfa0c6 XL |
300 | alias_def_id, |
301 | substs, | |
302 | nested, | |
dfeec247 | 303 | }) => tcx.lift(&substs).map(|substs| { |
f035d41b | 304 | traits::ImplSourceTraitAlias(traits::ImplSourceTraitAliasData { |
a1dfa0c6 XL |
305 | alias_def_id, |
306 | substs, | |
307 | nested, | |
308 | }) | |
dfeec247 | 309 | }), |
a7813a04 XL |
310 | } |
311 | } | |
312 | } |