2 use crate::ty::{Lift, TyCtxt};
7 // Structural impls for the structs in `traits`.
9 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12 super::ImplSourceUserDefined(ref v) => write!(f, "{:?}", v),
14 super::ImplSourceAutoImpl(ref t) => write!(f, "{:?}", t),
16 super::ImplSourceClosure(ref d) => write!(f, "{:?}", d),
18 super::ImplSourceGenerator(ref d) => write!(f, "{:?}", d),
20 super::ImplSourceFnPointer(ref d) => write!(f, "ImplSourceFnPointer({:?})", d),
22 super::ImplSourceDiscriminantKind(ref d) => write!(f, "{:?}", d),
24 super::ImplSourceObject(ref d) => write!(f, "{:?}", d),
26 super::ImplSourceParam(ref n) => write!(f, "ImplSourceParam({:?})", n),
28 super::ImplSourceBuiltin(ref d) => write!(f, "{:?}", d),
30 super::ImplSourceTraitAlias(ref d) => write!(f, "{:?}", d),
35 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceUserDefinedData<'tcx, N> {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 "ImplSourceUserDefinedData(impl_def_id={:?}, substs={:?}, nested={:?})",
40 self.impl_def_id, self.substs, self.nested
45 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceGeneratorData<'tcx, N> {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 "ImplSourceGeneratorData(generator_def_id={:?}, substs={:?}, nested={:?})",
50 self.generator_def_id, self.substs, self.nested
55 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceClosureData<'tcx, N> {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 "ImplSourceClosureData(closure_def_id={:?}, substs={:?}, nested={:?})",
60 self.closure_def_id, self.substs, self.nested
65 impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceBuiltinData<N> {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 write!(f, "ImplSourceBuiltinData(nested={:?})", self.nested)
71 impl<N: fmt::Debug> fmt::Debug for traits::ImplSourceAutoImplData<N> {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 "ImplSourceAutoImplData(trait_def_id={:?}, nested={:?})",
76 self.trait_def_id, self.nested
81 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceObjectData<'tcx, N> {
82 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
85 "ImplSourceObjectData(upcast={:?}, vtable_base={}, nested={:?})",
86 self.upcast_trait_ref, self.vtable_base, self.nested
91 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceFnPointerData<'tcx, N> {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 write!(f, "ImplSourceFnPointerData(fn_ty={:?}, nested={:?})", self.fn_ty, self.nested)
97 impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx, N> {
98 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101 "ImplSourceTraitAlias(alias_def_id={:?}, substs={:?}, nested={:?})",
102 self.alias_def_id, self.substs, self.nested
107 ///////////////////////////////////////////////////////////////////////////
108 // Lift implementations
110 impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> {
111 type Lifted = traits::SelectionError<'tcx>;
112 fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
114 super::Unimplemented => Some(super::Unimplemented),
115 super::OutputTypeParameterMismatch(a, b, ref err) => {
116 tcx.lift(&(a, b)).and_then(|(a, b)| {
117 tcx.lift(err).map(|err| super::OutputTypeParameterMismatch(a, b, err))
120 super::TraitNotObjectSafe(def_id) => Some(super::TraitNotObjectSafe(def_id)),
121 super::ConstEvalFailure(err) => Some(super::ConstEvalFailure(err)),
122 super::Overflow => Some(super::Overflow),
127 impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
128 type Lifted = traits::ObligationCauseCode<'tcx>;
129 fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
131 super::ReturnNoExpression => Some(super::ReturnNoExpression),
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)),
137 super::BindingObligation(def_id, span) => Some(super::BindingObligation(def_id, span)),
138 super::ReferenceOutlivesReferent(ty) => {
139 tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
141 super::ObjectTypeBound(ty, r) => {
142 tcx.lift(&ty).and_then(|ty| tcx.lift(&r).map(|r| super::ObjectTypeBound(ty, r)))
144 super::ObjectCastObligation(ty) => tcx.lift(&ty).map(super::ObjectCastObligation),
145 super::Coercion { source, target } => {
146 Some(super::Coercion { source: tcx.lift(&source)?, target: tcx.lift(&target)? })
148 super::AssignmentLhsSized => Some(super::AssignmentLhsSized),
149 super::TupleInitializerSized => Some(super::TupleInitializerSized),
150 super::StructInitializerSized => Some(super::StructInitializerSized),
151 super::VariableType(id) => Some(super::VariableType(id)),
152 super::ReturnValue(id) => Some(super::ReturnValue(id)),
153 super::ReturnType => Some(super::ReturnType),
154 super::SizedArgumentType(sp) => Some(super::SizedArgumentType(sp)),
155 super::SizedReturnType => Some(super::SizedReturnType),
156 super::SizedYieldType => Some(super::SizedYieldType),
157 super::InlineAsmSized => Some(super::InlineAsmSized),
158 super::RepeatVec(suggest_flag) => Some(super::RepeatVec(suggest_flag)),
159 super::FieldSized { adt_kind, span, last } => {
160 Some(super::FieldSized { adt_kind, span, last })
162 super::ConstSized => Some(super::ConstSized),
163 super::ConstPatternStructural => Some(super::ConstPatternStructural),
164 super::SharedStatic => Some(super::SharedStatic),
165 super::BuiltinDerivedObligation(ref cause) => {
166 tcx.lift(cause).map(super::BuiltinDerivedObligation)
168 super::ImplDerivedObligation(ref cause) => {
169 tcx.lift(cause).map(super::ImplDerivedObligation)
171 super::DerivedObligation(ref cause) => tcx.lift(cause).map(super::DerivedObligation),
172 super::CompareImplConstObligation => Some(super::CompareImplConstObligation),
173 super::CompareImplMethodObligation {
177 } => Some(super::CompareImplMethodObligation {
182 super::CompareImplTypeObligation { item_name, impl_item_def_id, trait_item_def_id } => {
183 Some(super::CompareImplTypeObligation {
189 super::ExprAssignable => Some(super::ExprAssignable),
190 super::MatchExpressionArm(box super::MatchExpressionArmCause {
196 }) => tcx.lift(&last_ty).map(|last_ty| {
197 super::MatchExpressionArm(box super::MatchExpressionArmCause {
200 prior_arms: prior_arms.clone(),
205 super::Pattern { span, root_ty, origin_expr } => {
206 tcx.lift(&root_ty).map(|root_ty| super::Pattern { span, root_ty, origin_expr })
208 super::IfExpression(box super::IfExpressionCause { then, outer, semicolon }) => {
209 Some(super::IfExpression(box super::IfExpressionCause { then, outer, semicolon }))
211 super::IfExpressionWithNoElse => Some(super::IfExpressionWithNoElse),
212 super::MainFunctionType => Some(super::MainFunctionType),
213 super::StartFunctionType => Some(super::StartFunctionType),
214 super::IntrinsicType => Some(super::IntrinsicType),
215 super::MethodReceiver => Some(super::MethodReceiver),
216 super::BlockTailExpression(id) => Some(super::BlockTailExpression(id)),
217 super::TrivialBound => Some(super::TrivialBound),
222 impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> {
223 type Lifted = traits::DerivedObligationCause<'tcx>;
224 fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
225 tcx.lift(&self.parent_trait_ref).and_then(|trait_ref| {
226 tcx.lift(&*self.parent_code).map(|code| traits::DerivedObligationCause {
227 parent_trait_ref: trait_ref,
228 parent_code: Rc::new(code),
234 impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCause<'a> {
235 type Lifted = traits::ObligationCause<'tcx>;
236 fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
237 tcx.lift(&self.code).map(|code| traits::ObligationCause::new(self.span, self.body_id, code))
242 impl<'a, 'tcx> Lift<'tcx> for traits::ImplSource<'a, ()> {
243 type Lifted = traits::ImplSource<'tcx, ()>;
244 fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
246 traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
250 }) => tcx.lift(&substs).map(|substs| {
251 traits::ImplSourceUserDefined(traits::ImplSourceUserDefinedData {
257 traits::ImplSourceAutoImpl(t) => Some(traits::ImplSourceAutoImpl(t)),
258 traits::ImplSourceGenerator(traits::ImplSourceGeneratorData {
262 }) => tcx.lift(&substs).map(|substs| {
263 traits::ImplSourceGenerator(traits::ImplSourceGeneratorData {
269 traits::ImplSourceClosure(traits::ImplSourceClosureData {
273 }) => tcx.lift(&substs).map(|substs| {
274 traits::ImplSourceClosure(traits::ImplSourceClosureData {
280 traits::ImplSourceFnPointer(traits::ImplSourceFnPointerData { fn_ty, nested }) => {
281 tcx.lift(&fn_ty).map(|fn_ty| {
282 traits::ImplSourceFnPointer(traits::ImplSourceFnPointerData { fn_ty, nested })
285 traits::ImplSourceDiscriminantKind(traits::ImplSourceDiscriminantKindData) => {
286 Some(traits::ImplSourceDiscriminantKind(traits::ImplSourceDiscriminantKindData))
288 traits::ImplSourceParam(n) => Some(traits::ImplSourceParam(n)),
289 traits::ImplSourceBuiltin(n) => Some(traits::ImplSourceBuiltin(n)),
290 traits::ImplSourceObject(traits::ImplSourceObjectData {
294 }) => tcx.lift(&upcast_trait_ref).map(|trait_ref| {
295 traits::ImplSourceObject(traits::ImplSourceObjectData {
296 upcast_trait_ref: trait_ref,
301 traits::ImplSourceTraitAlias(traits::ImplSourceTraitAliasData {
305 }) => tcx.lift(&substs).map(|substs| {
306 traits::ImplSourceTraitAlias(traits::ImplSourceTraitAliasData {