|
| 1 | +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use middle::traits; |
| 12 | +use middle::traits::project::Normalized; |
| 13 | +use middle::ty::{HasTypeFlags, TypeFlags, RegionEscape}; |
| 14 | +use middle::ty::fold::{TypeFoldable, TypeFolder}; |
| 15 | + |
| 16 | +use std::fmt; |
| 17 | + |
| 18 | +// structural impls for the structs in middle::traits |
| 19 | + |
| 20 | +impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> { |
| 21 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 22 | + write!(f, "Normalized({:?},{:?})", |
| 23 | + self.value, |
| 24 | + self.obligations) |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +impl<'tcx> fmt::Debug for traits::RegionObligation<'tcx> { |
| 29 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 30 | + write!(f, "RegionObligation(sub_region={:?}, sup_type={:?})", |
| 31 | + self.sub_region, |
| 32 | + self.sup_type) |
| 33 | + } |
| 34 | +} |
| 35 | +impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> { |
| 36 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 37 | + write!(f, "Obligation(predicate={:?},depth={})", |
| 38 | + self.predicate, |
| 39 | + self.recursion_depth) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +impl<'tcx, N: fmt::Debug> fmt::Debug for traits::Vtable<'tcx, N> { |
| 44 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 45 | + match *self { |
| 46 | + super::VtableImpl(ref v) => |
| 47 | + write!(f, "{:?}", v), |
| 48 | + |
| 49 | + super::VtableDefaultImpl(ref t) => |
| 50 | + write!(f, "{:?}", t), |
| 51 | + |
| 52 | + super::VtableClosure(ref d) => |
| 53 | + write!(f, "{:?}", d), |
| 54 | + |
| 55 | + super::VtableFnPointer(ref d) => |
| 56 | + write!(f, "VtableFnPointer({:?})", d), |
| 57 | + |
| 58 | + super::VtableObject(ref d) => |
| 59 | + write!(f, "{:?}", d), |
| 60 | + |
| 61 | + super::VtableParam(ref n) => |
| 62 | + write!(f, "VtableParam({:?})", n), |
| 63 | + |
| 64 | + super::VtableBuiltin(ref d) => |
| 65 | + write!(f, "{:?}", d) |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableImplData<'tcx, N> { |
| 71 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 72 | + write!(f, "VtableImpl(impl_def_id={:?}, substs={:?}, nested={:?})", |
| 73 | + self.impl_def_id, |
| 74 | + self.substs, |
| 75 | + self.nested) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableClosureData<'tcx, N> { |
| 80 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 81 | + write!(f, "VtableClosure(closure_def_id={:?}, substs={:?}, nested={:?})", |
| 82 | + self.closure_def_id, |
| 83 | + self.substs, |
| 84 | + self.nested) |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableBuiltinData<N> { |
| 89 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 90 | + write!(f, "VtableBuiltin(nested={:?})", self.nested) |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableDefaultImplData<N> { |
| 95 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 96 | + write!(f, "VtableDefaultImplData(trait_def_id={:?}, nested={:?})", |
| 97 | + self.trait_def_id, |
| 98 | + self.nested) |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +impl<'tcx> fmt::Debug for traits::VtableObjectData<'tcx> { |
| 103 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 104 | + write!(f, "VtableObject(upcast={:?}, vtable_base={})", |
| 105 | + self.upcast_trait_ref, |
| 106 | + self.vtable_base) |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> { |
| 111 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 112 | + write!(f, "FulfillmentError({:?},{:?})", |
| 113 | + self.obligation, |
| 114 | + self.code) |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> { |
| 119 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 120 | + match *self { |
| 121 | + super::CodeSelectionError(ref e) => write!(f, "{:?}", e), |
| 122 | + super::CodeProjectionError(ref e) => write!(f, "{:?}", e), |
| 123 | + super::CodeAmbiguity => write!(f, "Ambiguity") |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> { |
| 129 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 130 | + write!(f, "MismatchedProjectionTypes({:?})", self.err) |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +impl<'tcx, P: RegionEscape> RegionEscape for traits::Obligation<'tcx,P> { |
| 135 | + fn has_regions_escaping_depth(&self, depth: u32) -> bool { |
| 136 | + self.predicate.has_regions_escaping_depth(depth) |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +impl<'tcx, T: HasTypeFlags> HasTypeFlags for traits::Obligation<'tcx, T> { |
| 141 | + fn has_type_flags(&self, flags: TypeFlags) -> bool { |
| 142 | + self.predicate.has_type_flags(flags) |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +impl<'tcx, T: HasTypeFlags> HasTypeFlags for Normalized<'tcx, T> { |
| 147 | + fn has_type_flags(&self, flags: TypeFlags) -> bool { |
| 148 | + self.value.has_type_flags(flags) || |
| 149 | + self.obligations.has_type_flags(flags) |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> |
| 154 | +{ |
| 155 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::Obligation<'tcx, O> { |
| 156 | + traits::Obligation { |
| 157 | + cause: self.cause.clone(), |
| 158 | + recursion_depth: self.recursion_depth, |
| 159 | + predicate: self.predicate.fold_with(folder), |
| 160 | + } |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> { |
| 165 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableImplData<'tcx, N> { |
| 166 | + traits::VtableImplData { |
| 167 | + impl_def_id: self.impl_def_id, |
| 168 | + substs: self.substs.fold_with(folder), |
| 169 | + nested: self.nested.fold_with(folder), |
| 170 | + } |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableClosureData<'tcx, N> { |
| 175 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableClosureData<'tcx, N> { |
| 176 | + traits::VtableClosureData { |
| 177 | + closure_def_id: self.closure_def_id, |
| 178 | + substs: self.substs.fold_with(folder), |
| 179 | + nested: self.nested.fold_with(folder), |
| 180 | + } |
| 181 | + } |
| 182 | +} |
| 183 | + |
| 184 | +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableDefaultImplData<N> { |
| 185 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableDefaultImplData<N> { |
| 186 | + traits::VtableDefaultImplData { |
| 187 | + trait_def_id: self.trait_def_id, |
| 188 | + nested: self.nested.fold_with(folder), |
| 189 | + } |
| 190 | + } |
| 191 | +} |
| 192 | + |
| 193 | +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::VtableBuiltinData<N> { |
| 194 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableBuiltinData<N> { |
| 195 | + traits::VtableBuiltinData { |
| 196 | + nested: self.nested.fold_with(folder), |
| 197 | + } |
| 198 | + } |
| 199 | +} |
| 200 | + |
| 201 | +impl<'tcx, N: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Vtable<'tcx, N> { |
| 202 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::Vtable<'tcx, N> { |
| 203 | + match *self { |
| 204 | + traits::VtableImpl(ref v) => traits::VtableImpl(v.fold_with(folder)), |
| 205 | + traits::VtableDefaultImpl(ref t) => traits::VtableDefaultImpl(t.fold_with(folder)), |
| 206 | + traits::VtableClosure(ref d) => { |
| 207 | + traits::VtableClosure(d.fold_with(folder)) |
| 208 | + } |
| 209 | + traits::VtableFnPointer(ref d) => { |
| 210 | + traits::VtableFnPointer(d.fold_with(folder)) |
| 211 | + } |
| 212 | + traits::VtableParam(ref n) => traits::VtableParam(n.fold_with(folder)), |
| 213 | + traits::VtableBuiltin(ref d) => traits::VtableBuiltin(d.fold_with(folder)), |
| 214 | + traits::VtableObject(ref d) => traits::VtableObject(d.fold_with(folder)), |
| 215 | + } |
| 216 | + } |
| 217 | +} |
| 218 | + |
| 219 | +impl<'tcx> TypeFoldable<'tcx> for traits::VtableObjectData<'tcx> { |
| 220 | + fn fold_with<F:TypeFolder<'tcx>>(&self, folder: &mut F) -> traits::VtableObjectData<'tcx> { |
| 221 | + traits::VtableObjectData { |
| 222 | + upcast_trait_ref: self.upcast_trait_ref.fold_with(folder), |
| 223 | + vtable_base: self.vtable_base |
| 224 | + } |
| 225 | + } |
| 226 | +} |
| 227 | + |
| 228 | +impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Normalized<'tcx, T> { |
| 229 | + fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Normalized<'tcx, T> { |
| 230 | + Normalized { |
| 231 | + value: self.value.fold_with(folder), |
| 232 | + obligations: self.obligations.fold_with(folder), |
| 233 | + } |
| 234 | + } |
| 235 | +} |
0 commit comments