@@ -2,16 +2,13 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
22use rustc_serialize:: Decoder ;
33use rustc_serialize:: { Decodable , Encodable } ;
44use std:: fmt;
5- use std:: ops:: ControlFlow ;
65
7- use crate :: fold:: { FallibleTypeFolder , TypeFoldable } ;
8- use crate :: visit:: { TypeVisitable , TypeVisitor } ;
9- use crate :: { HashStableContext , Interner , BoringTraversable } ;
6+ use crate :: { HashStableContext , Interner } ;
107use crate :: { TyDecoder , TyEncoder } ;
118
129/// A clause is something that can appear in where bounds or be inferred
1310/// by implied bounds.
14- #[ derive( derivative:: Derivative ) ]
11+ #[ derive( derivative:: Derivative , TypeFoldable , TypeVisitable ) ]
1512#[ derivative( Clone ( bound = "" ) , Hash ( bound = "" ) ) ]
1613pub enum ClauseKind < I : Interner > {
1714 /// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
@@ -108,80 +105,6 @@ where
108105 }
109106}
110107
111- impl < I : Interner > TypeFoldable < I > for ClauseKind < I >
112- where
113- I :: Ty : TypeFoldable < I > ,
114- I :: Const : TypeFoldable < I > ,
115- I :: GenericArg : TypeFoldable < I > ,
116- I :: TraitPredicate : TypeFoldable < I > ,
117- I :: ProjectionPredicate : TypeFoldable < I > ,
118- I :: TypeOutlivesPredicate : TypeFoldable < I > ,
119- I :: RegionOutlivesPredicate : TypeFoldable < I > ,
120- {
121- fn try_fold_with < F : FallibleTypeFolder < I > > ( self , folder : & mut F ) -> Result < Self , F :: Error > {
122- Ok ( match self {
123- ClauseKind :: Trait ( p) => {
124- ClauseKind :: Trait ( noop_traversal_if_boring ! ( p. try_fold_with( folder) ) ?)
125- }
126- ClauseKind :: RegionOutlives ( p) => {
127- ClauseKind :: RegionOutlives ( noop_traversal_if_boring ! ( p. try_fold_with( folder) ) ?)
128- }
129- ClauseKind :: TypeOutlives ( p) => {
130- ClauseKind :: TypeOutlives ( noop_traversal_if_boring ! ( p. try_fold_with( folder) ) ?)
131- }
132- ClauseKind :: Projection ( p) => {
133- ClauseKind :: Projection ( noop_traversal_if_boring ! ( p. try_fold_with( folder) ) ?)
134- }
135- ClauseKind :: ConstArgHasType ( c, t) => ClauseKind :: ConstArgHasType (
136- noop_traversal_if_boring ! ( c. try_fold_with( folder) ) ?,
137- noop_traversal_if_boring ! ( t. try_fold_with( folder) ) ?,
138- ) ,
139- ClauseKind :: WellFormed ( p) => {
140- ClauseKind :: WellFormed ( noop_traversal_if_boring ! ( p. try_fold_with( folder) ) ?)
141- }
142- ClauseKind :: ConstEvaluatable ( p) => {
143- ClauseKind :: ConstEvaluatable ( noop_traversal_if_boring ! ( p. try_fold_with( folder) ) ?)
144- }
145- } )
146- }
147- }
148-
149- impl < I : Interner > TypeVisitable < I > for ClauseKind < I >
150- where
151- I :: Ty : TypeVisitable < I > ,
152- I :: Const : TypeVisitable < I > ,
153- I :: GenericArg : TypeVisitable < I > ,
154- I :: TraitPredicate : TypeVisitable < I > ,
155- I :: ProjectionPredicate : TypeVisitable < I > ,
156- I :: TypeOutlivesPredicate : TypeVisitable < I > ,
157- I :: RegionOutlivesPredicate : TypeVisitable < I > ,
158- {
159- fn visit_with < V : TypeVisitor < I > > ( & self , visitor : & mut V ) -> ControlFlow < V :: BreakTy > {
160- match self {
161- ClauseKind :: Trait ( p) => noop_traversal_if_boring ! ( p. visit_with( visitor) ) ,
162- ClauseKind :: RegionOutlives ( p) => {
163- noop_traversal_if_boring ! ( p. visit_with( visitor) )
164- }
165- ClauseKind :: TypeOutlives ( p) => {
166- noop_traversal_if_boring ! ( p. visit_with( visitor) )
167- }
168- ClauseKind :: Projection ( p) => {
169- noop_traversal_if_boring ! ( p. visit_with( visitor) )
170- }
171- ClauseKind :: ConstArgHasType ( c, t) => {
172- noop_traversal_if_boring ! ( c. visit_with( visitor) ) ?;
173- noop_traversal_if_boring ! ( t. visit_with( visitor) )
174- }
175- ClauseKind :: WellFormed ( p) => {
176- noop_traversal_if_boring ! ( p. visit_with( visitor) )
177- }
178- ClauseKind :: ConstEvaluatable ( p) => {
179- noop_traversal_if_boring ! ( p. visit_with( visitor) )
180- }
181- }
182- }
183- }
184-
185108impl < I : Interner , D : TyDecoder < I = I > > Decodable < D > for ClauseKind < I >
186109where
187110 I :: Ty : Decodable < D > ,
@@ -239,19 +162,23 @@ where
239162 }
240163}
241164
242- #[ derive( derivative:: Derivative ) ]
165+ #[ derive( derivative:: Derivative , TypeFoldable , TypeVisitable ) ]
243166#[ derivative( Clone ( bound = "" ) , Hash ( bound = "" ) ) ]
244167pub enum PredicateKind < I : Interner > {
245168 /// Prove a clause
246169 Clause ( ClauseKind < I > ) ,
247170
248171 /// Trait must be object-safe.
249- ObjectSafe ( I :: DefId ) ,
172+ ObjectSafe ( # [ skip_traversal ( because_boring ) ] I :: DefId ) ,
250173
251174 /// No direct syntax. May be thought of as `where T: FnFoo<...>`
252175 /// for some generic args `...` and `T` being a closure type.
253176 /// Satisfied (or refuted) once we know the closure's kind.
254- ClosureKind ( I :: DefId , I :: GenericArgs , I :: ClosureKind ) ,
177+ ClosureKind (
178+ #[ skip_traversal( because_boring) ] I :: DefId ,
179+ I :: GenericArgs ,
180+ #[ skip_traversal( because_boring) ] I :: ClosureKind ,
181+ ) ,
255182
256183 /// `T1 <: T2`
257184 ///
@@ -368,90 +295,6 @@ where
368295 }
369296}
370297
371- impl < I : Interner > TypeFoldable < I > for PredicateKind < I >
372- where
373- I :: DefId : BoringTraversable ,
374- I :: Const : TypeFoldable < I > ,
375- I :: GenericArgs : TypeFoldable < I > ,
376- I :: Term : TypeFoldable < I > ,
377- I :: CoercePredicate : TypeFoldable < I > ,
378- I :: SubtypePredicate : TypeFoldable < I > ,
379- I :: ClosureKind : BoringTraversable ,
380- ClauseKind < I > : TypeFoldable < I > ,
381- {
382- fn try_fold_with < F : FallibleTypeFolder < I > > ( self , folder : & mut F ) -> Result < Self , F :: Error > {
383- Ok ( match self {
384- PredicateKind :: Clause ( c) => {
385- PredicateKind :: Clause ( noop_traversal_if_boring ! ( c. try_fold_with( folder) ) ?)
386- }
387- PredicateKind :: ObjectSafe ( d) => {
388- PredicateKind :: ObjectSafe ( noop_traversal_if_boring ! ( d. try_fold_with( folder) ) ?)
389- }
390- PredicateKind :: ClosureKind ( d, g, k) => PredicateKind :: ClosureKind (
391- noop_traversal_if_boring ! ( d. try_fold_with( folder) ) ?,
392- noop_traversal_if_boring ! ( g. try_fold_with( folder) ) ?,
393- noop_traversal_if_boring ! ( k. try_fold_with( folder) ) ?,
394- ) ,
395- PredicateKind :: Subtype ( s) => {
396- PredicateKind :: Subtype ( noop_traversal_if_boring ! ( s. try_fold_with( folder) ) ?)
397- }
398- PredicateKind :: Coerce ( s) => {
399- PredicateKind :: Coerce ( noop_traversal_if_boring ! ( s. try_fold_with( folder) ) ?)
400- }
401- PredicateKind :: ConstEquate ( a, b) => PredicateKind :: ConstEquate (
402- noop_traversal_if_boring ! ( a. try_fold_with( folder) ) ?,
403- noop_traversal_if_boring ! ( b. try_fold_with( folder) ) ?,
404- ) ,
405- PredicateKind :: Ambiguous => PredicateKind :: Ambiguous ,
406- PredicateKind :: AliasRelate ( a, b, d) => PredicateKind :: AliasRelate (
407- noop_traversal_if_boring ! ( a. try_fold_with( folder) ) ?,
408- noop_traversal_if_boring ! ( b. try_fold_with( folder) ) ?,
409- noop_traversal_if_boring ! ( d. try_fold_with( folder) ) ?,
410- ) ,
411- } )
412- }
413- }
414-
415- impl < I : Interner > TypeVisitable < I > for PredicateKind < I >
416- where
417- I :: DefId : BoringTraversable ,
418- I :: Const : TypeVisitable < I > ,
419- I :: GenericArgs : TypeVisitable < I > ,
420- I :: Term : TypeVisitable < I > ,
421- I :: CoercePredicate : TypeVisitable < I > ,
422- I :: SubtypePredicate : TypeVisitable < I > ,
423- I :: ClosureKind : BoringTraversable ,
424- ClauseKind < I > : TypeVisitable < I > ,
425- {
426- fn visit_with < V : TypeVisitor < I > > ( & self , visitor : & mut V ) -> ControlFlow < V :: BreakTy > {
427- match self {
428- PredicateKind :: Clause ( p) => noop_traversal_if_boring ! ( p. visit_with( visitor) ) ,
429- PredicateKind :: ObjectSafe ( d) => {
430- noop_traversal_if_boring ! ( d. visit_with( visitor) )
431- }
432- PredicateKind :: ClosureKind ( d, g, k) => {
433- noop_traversal_if_boring ! ( d. visit_with( visitor) ) ?;
434- noop_traversal_if_boring ! ( g. visit_with( visitor) ) ?;
435- noop_traversal_if_boring ! ( k. visit_with( visitor) )
436- }
437- PredicateKind :: Subtype ( s) => {
438- noop_traversal_if_boring ! ( s. visit_with( visitor) )
439- }
440- PredicateKind :: Coerce ( s) => noop_traversal_if_boring ! ( s. visit_with( visitor) ) ,
441- PredicateKind :: ConstEquate ( a, b) => {
442- noop_traversal_if_boring ! ( a. visit_with( visitor) ) ?;
443- noop_traversal_if_boring ! ( b. visit_with( visitor) )
444- }
445- PredicateKind :: Ambiguous => ControlFlow :: Continue ( ( ) ) ,
446- PredicateKind :: AliasRelate ( a, b, d) => {
447- noop_traversal_if_boring ! ( a. visit_with( visitor) ) ?;
448- noop_traversal_if_boring ! ( b. visit_with( visitor) ) ?;
449- noop_traversal_if_boring ! ( d. visit_with( visitor) )
450- }
451- }
452- }
453- }
454-
455298impl < I : Interner , D : TyDecoder < I = I > > Decodable < D > for PredicateKind < I >
456299where
457300 I :: DefId : Decodable < D > ,
0 commit comments