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.
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.
12 use middle
::traits
::project
::Normalized
;
13 use middle
::ty
::fold
::{TypeFoldable, TypeFolder, TypeVisitor}
;
17 // structural impls for the structs in middle::traits
19 impl<'tcx
, T
: fmt
::Debug
> fmt
::Debug
for Normalized
<'tcx
, T
> {
20 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
21 write
!(f
, "Normalized({:?},{:?})",
27 impl<'tcx
> fmt
::Debug
for traits
::RegionObligation
<'tcx
> {
28 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
29 write
!(f
, "RegionObligation(sub_region={:?}, sup_type={:?})",
34 impl<'tcx
, O
: fmt
::Debug
> fmt
::Debug
for traits
::Obligation
<'tcx
, O
> {
35 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
36 write
!(f
, "Obligation(predicate={:?},depth={})",
42 impl<'tcx
, N
: fmt
::Debug
> fmt
::Debug
for traits
::Vtable
<'tcx
, N
> {
43 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
45 super::VtableImpl(ref v
) =>
48 super::VtableDefaultImpl(ref t
) =>
51 super::VtableClosure(ref d
) =>
54 super::VtableFnPointer(ref d
) =>
55 write
!(f
, "VtableFnPointer({:?})", d
),
57 super::VtableObject(ref d
) =>
60 super::VtableParam(ref n
) =>
61 write
!(f
, "VtableParam({:?})", n
),
63 super::VtableBuiltin(ref d
) =>
69 impl<'tcx
, N
: fmt
::Debug
> fmt
::Debug
for traits
::VtableImplData
<'tcx
, N
> {
70 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
71 write
!(f
, "VtableImpl(impl_def_id={:?}, substs={:?}, nested={:?})",
78 impl<'tcx
, N
: fmt
::Debug
> fmt
::Debug
for traits
::VtableClosureData
<'tcx
, N
> {
79 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
80 write
!(f
, "VtableClosure(closure_def_id={:?}, substs={:?}, nested={:?})",
87 impl<'tcx
, N
: fmt
::Debug
> fmt
::Debug
for traits
::VtableBuiltinData
<N
> {
88 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
89 write
!(f
, "VtableBuiltin(nested={:?})", self.nested
)
93 impl<'tcx
, N
: fmt
::Debug
> fmt
::Debug
for traits
::VtableDefaultImplData
<N
> {
94 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
95 write
!(f
, "VtableDefaultImplData(trait_def_id={:?}, nested={:?})",
101 impl<'tcx
> fmt
::Debug
for traits
::VtableObjectData
<'tcx
> {
102 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
103 write
!(f
, "VtableObject(upcast={:?}, vtable_base={})",
104 self.upcast_trait_ref
,
109 impl<'tcx
> fmt
::Debug
for traits
::FulfillmentError
<'tcx
> {
110 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
111 write
!(f
, "FulfillmentError({:?},{:?})",
117 impl<'tcx
> fmt
::Debug
for traits
::FulfillmentErrorCode
<'tcx
> {
118 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
120 super::CodeSelectionError(ref e
) => write
!(f
, "{:?}", e
),
121 super::CodeProjectionError(ref e
) => write
!(f
, "{:?}", e
),
122 super::CodeAmbiguity
=> write
!(f
, "Ambiguity")
127 impl<'tcx
> fmt
::Debug
for traits
::MismatchedProjectionTypes
<'tcx
> {
128 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
129 write
!(f
, "MismatchedProjectionTypes({:?})", self.err
)
133 impl<'tcx
, O
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::Obligation
<'tcx
, O
>
135 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
137 cause
: self.cause
.clone(),
138 recursion_depth
: self.recursion_depth
,
139 predicate
: self.predicate
.fold_with(folder
),
143 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
144 self.predicate
.visit_with(visitor
)
148 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableImplData
<'tcx
, N
> {
149 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
150 traits
::VtableImplData
{
151 impl_def_id
: self.impl_def_id
,
152 substs
: self.substs
.fold_with(folder
),
153 nested
: self.nested
.fold_with(folder
),
157 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
158 self.substs
.visit_with(visitor
) || self.nested
.visit_with(visitor
)
162 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableClosureData
<'tcx
, N
> {
163 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
164 traits
::VtableClosureData
{
165 closure_def_id
: self.closure_def_id
,
166 substs
: self.substs
.fold_with(folder
),
167 nested
: self.nested
.fold_with(folder
),
171 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
172 self.substs
.visit_with(visitor
) || self.nested
.visit_with(visitor
)
176 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableDefaultImplData
<N
> {
177 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
178 traits
::VtableDefaultImplData
{
179 trait_def_id
: self.trait_def_id
,
180 nested
: self.nested
.fold_with(folder
),
184 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
185 self.nested
.visit_with(visitor
)
189 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableBuiltinData
<N
> {
190 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
191 traits
::VtableBuiltinData
{
192 nested
: self.nested
.fold_with(folder
),
196 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
197 self.nested
.visit_with(visitor
)
201 impl<'tcx
> TypeFoldable
<'tcx
> for traits
::VtableObjectData
<'tcx
> {
202 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
203 traits
::VtableObjectData
{
204 upcast_trait_ref
: self.upcast_trait_ref
.fold_with(folder
),
205 vtable_base
: self.vtable_base
209 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
210 self.upcast_trait_ref
.visit_with(visitor
)
214 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::Vtable
<'tcx
, N
> {
215 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
217 traits
::VtableImpl(ref v
) => traits
::VtableImpl(v
.fold_with(folder
)),
218 traits
::VtableDefaultImpl(ref t
) => traits
::VtableDefaultImpl(t
.fold_with(folder
)),
219 traits
::VtableClosure(ref d
) => {
220 traits
::VtableClosure(d
.fold_with(folder
))
222 traits
::VtableFnPointer(ref d
) => {
223 traits
::VtableFnPointer(d
.fold_with(folder
))
225 traits
::VtableParam(ref n
) => traits
::VtableParam(n
.fold_with(folder
)),
226 traits
::VtableBuiltin(ref d
) => traits
::VtableBuiltin(d
.fold_with(folder
)),
227 traits
::VtableObject(ref d
) => traits
::VtableObject(d
.fold_with(folder
)),
231 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
233 traits
::VtableImpl(ref v
) => v
.visit_with(visitor
),
234 traits
::VtableDefaultImpl(ref t
) => t
.visit_with(visitor
),
235 traits
::VtableClosure(ref d
) => d
.visit_with(visitor
),
236 traits
::VtableFnPointer(ref d
) => d
.visit_with(visitor
),
237 traits
::VtableParam(ref n
) => n
.visit_with(visitor
),
238 traits
::VtableBuiltin(ref d
) => d
.visit_with(visitor
),
239 traits
::VtableObject(ref d
) => d
.visit_with(visitor
),
244 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Normalized
<'tcx
, T
> {
245 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
247 value
: self.value
.fold_with(folder
),
248 obligations
: self.obligations
.fold_with(folder
),
252 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
253 self.value
.visit_with(visitor
) || self.obligations
.visit_with(visitor
)