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 traits
::project
::Normalized
;
13 use ty
::fold
::{TypeFoldable, TypeFolder, TypeVisitor}
;
17 // structural impls for the structs in 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 let substs
= self.substs
.fold_with(folder
);
151 traits
::VtableImplData
{
152 impl_def_id
: self.impl_def_id
,
153 substs
: folder
.tcx().mk_substs(substs
),
154 nested
: self.nested
.fold_with(folder
),
158 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
159 self.substs
.visit_with(visitor
) || self.nested
.visit_with(visitor
)
163 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableClosureData
<'tcx
, N
> {
164 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
165 traits
::VtableClosureData
{
166 closure_def_id
: self.closure_def_id
,
167 substs
: self.substs
.fold_with(folder
),
168 nested
: self.nested
.fold_with(folder
),
172 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
173 self.substs
.visit_with(visitor
) || self.nested
.visit_with(visitor
)
177 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableDefaultImplData
<N
> {
178 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
179 traits
::VtableDefaultImplData
{
180 trait_def_id
: self.trait_def_id
,
181 nested
: self.nested
.fold_with(folder
),
185 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
186 self.nested
.visit_with(visitor
)
190 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::VtableBuiltinData
<N
> {
191 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
192 traits
::VtableBuiltinData
{
193 nested
: self.nested
.fold_with(folder
),
197 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
198 self.nested
.visit_with(visitor
)
202 impl<'tcx
> TypeFoldable
<'tcx
> for traits
::VtableObjectData
<'tcx
> {
203 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
204 traits
::VtableObjectData
{
205 upcast_trait_ref
: self.upcast_trait_ref
.fold_with(folder
),
206 vtable_base
: self.vtable_base
210 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
211 self.upcast_trait_ref
.visit_with(visitor
)
215 impl<'tcx
, N
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for traits
::Vtable
<'tcx
, N
> {
216 fn super_fold_with
<F
:TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
218 traits
::VtableImpl(ref v
) => traits
::VtableImpl(v
.fold_with(folder
)),
219 traits
::VtableDefaultImpl(ref t
) => traits
::VtableDefaultImpl(t
.fold_with(folder
)),
220 traits
::VtableClosure(ref d
) => {
221 traits
::VtableClosure(d
.fold_with(folder
))
223 traits
::VtableFnPointer(ref d
) => {
224 traits
::VtableFnPointer(d
.fold_with(folder
))
226 traits
::VtableParam(ref n
) => traits
::VtableParam(n
.fold_with(folder
)),
227 traits
::VtableBuiltin(ref d
) => traits
::VtableBuiltin(d
.fold_with(folder
)),
228 traits
::VtableObject(ref d
) => traits
::VtableObject(d
.fold_with(folder
)),
232 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
234 traits
::VtableImpl(ref v
) => v
.visit_with(visitor
),
235 traits
::VtableDefaultImpl(ref t
) => t
.visit_with(visitor
),
236 traits
::VtableClosure(ref d
) => d
.visit_with(visitor
),
237 traits
::VtableFnPointer(ref d
) => d
.visit_with(visitor
),
238 traits
::VtableParam(ref n
) => n
.visit_with(visitor
),
239 traits
::VtableBuiltin(ref d
) => d
.visit_with(visitor
),
240 traits
::VtableObject(ref d
) => d
.visit_with(visitor
),
245 impl<'tcx
, T
: TypeFoldable
<'tcx
>> TypeFoldable
<'tcx
> for Normalized
<'tcx
, T
> {
246 fn super_fold_with
<F
: TypeFolder
<'tcx
>>(&self, folder
: &mut F
) -> Self {
248 value
: self.value
.fold_with(folder
),
249 obligations
: self.obligations
.fold_with(folder
),
253 fn super_visit_with
<V
: TypeVisitor
<'tcx
>>(&self, visitor
: &mut V
) -> bool
{
254 self.value
.visit_with(visitor
) || self.obligations
.visit_with(visitor
)