@@ -74,44 +74,58 @@ pub struct Elaborator<'tcx> {
74
74
pub fn elaborate_trait_ref < ' tcx > (
75
75
tcx : TyCtxt < ' tcx > ,
76
76
trait_ref : ty:: PolyTraitRef < ' tcx > ,
77
- ) -> Elaborator < ' tcx > {
77
+ ) -> impl Iterator < Item = ty :: Predicate < ' tcx > > {
78
78
elaborate_predicates ( tcx, std:: iter:: once ( trait_ref. without_const ( ) . to_predicate ( tcx) ) )
79
79
}
80
80
81
81
pub fn elaborate_trait_refs < ' tcx > (
82
82
tcx : TyCtxt < ' tcx > ,
83
83
trait_refs : impl Iterator < Item = ty:: PolyTraitRef < ' tcx > > ,
84
- ) -> Elaborator < ' tcx > {
85
- let predicates = trait_refs. map ( |trait_ref| trait_ref. without_const ( ) . to_predicate ( tcx) ) ;
84
+ ) -> impl Iterator < Item = ty :: Predicate < ' tcx > > {
85
+ let predicates = trait_refs. map ( move |trait_ref| trait_ref. without_const ( ) . to_predicate ( tcx) ) ;
86
86
elaborate_predicates ( tcx, predicates)
87
87
}
88
88
89
89
pub fn elaborate_predicates < ' tcx > (
90
90
tcx : TyCtxt < ' tcx > ,
91
91
predicates : impl Iterator < Item = ty:: Predicate < ' tcx > > ,
92
- ) -> Elaborator < ' tcx > {
93
- let obligations = predicates
94
- . map ( |predicate| {
95
- predicate_obligation ( predicate, ty:: ParamEnv :: empty ( ) , ObligationCause :: dummy ( ) )
96
- } )
97
- . collect ( ) ;
98
- elaborate_obligations ( tcx, obligations)
92
+ ) -> impl Iterator < Item = ty:: Predicate < ' tcx > > {
93
+ elaborate_obligations (
94
+ tcx,
95
+ predicates
96
+ . map ( |predicate| {
97
+ Obligation :: new (
98
+ tcx,
99
+ // We'll dump the cause/param-env later
100
+ ObligationCause :: dummy ( ) ,
101
+ ty:: ParamEnv :: empty ( ) ,
102
+ predicate,
103
+ )
104
+ } )
105
+ . collect ( ) ,
106
+ )
107
+ . map ( |obl| obl. predicate )
99
108
}
100
109
101
110
pub fn elaborate_predicates_with_span < ' tcx > (
102
111
tcx : TyCtxt < ' tcx > ,
103
112
predicates : impl Iterator < Item = ( ty:: Predicate < ' tcx > , Span ) > ,
104
- ) -> Elaborator < ' tcx > {
105
- let obligations = predicates
106
- . map ( |( predicate, span) | {
107
- predicate_obligation (
108
- predicate,
109
- ty:: ParamEnv :: empty ( ) ,
110
- ObligationCause :: dummy_with_span ( span) ,
111
- )
112
- } )
113
- . collect ( ) ;
114
- elaborate_obligations ( tcx, obligations)
113
+ ) -> impl Iterator < Item = ( ty:: Predicate < ' tcx > , Span ) > {
114
+ elaborate_obligations (
115
+ tcx,
116
+ predicates
117
+ . map ( |( predicate, span) | {
118
+ Obligation :: new (
119
+ tcx,
120
+ // We'll dump the cause/param-env later
121
+ ObligationCause :: dummy_with_span ( span) ,
122
+ ty:: ParamEnv :: empty ( ) ,
123
+ predicate,
124
+ )
125
+ } )
126
+ . collect ( ) ,
127
+ )
128
+ . map ( |obl| ( obl. predicate , obl. cause . span ) )
115
129
}
116
130
117
131
pub fn elaborate_obligations < ' tcx > (
@@ -141,10 +155,6 @@ impl<'tcx> Elaborator<'tcx> {
141
155
self . stack . extend ( obligations. into_iter ( ) . filter ( |o| self . visited . insert ( o. predicate ) ) ) ;
142
156
}
143
157
144
- pub fn filter_to_traits ( self ) -> FilterToTraits < Self > {
145
- FilterToTraits :: new ( self )
146
- }
147
-
148
158
fn elaborate ( & mut self , obligation : & PredicateObligation < ' tcx > ) {
149
159
let tcx = self . visited . tcx ;
150
160
@@ -325,20 +335,18 @@ impl<'tcx> Iterator for Elaborator<'tcx> {
325
335
// Supertrait iterator
326
336
///////////////////////////////////////////////////////////////////////////
327
337
328
- pub type Supertraits < ' tcx > = FilterToTraits < Elaborator < ' tcx > > ;
329
-
330
338
pub fn supertraits < ' tcx > (
331
339
tcx : TyCtxt < ' tcx > ,
332
340
trait_ref : ty:: PolyTraitRef < ' tcx > ,
333
- ) -> Supertraits < ' tcx > {
334
- elaborate_trait_ref ( tcx, trait_ref) . filter_to_traits ( )
341
+ ) -> impl Iterator < Item = ty :: PolyTraitRef < ' tcx > > {
342
+ FilterToTraits :: new ( elaborate_trait_ref ( tcx, trait_ref) )
335
343
}
336
344
337
345
pub fn transitive_bounds < ' tcx > (
338
346
tcx : TyCtxt < ' tcx > ,
339
- bounds : impl Iterator < Item = ty:: PolyTraitRef < ' tcx > > ,
340
- ) -> Supertraits < ' tcx > {
341
- elaborate_trait_refs ( tcx, bounds ) . filter_to_traits ( )
347
+ trait_refs : impl Iterator < Item = ty:: PolyTraitRef < ' tcx > > ,
348
+ ) -> impl Iterator < Item = ty :: PolyTraitRef < ' tcx > > {
349
+ FilterToTraits :: new ( elaborate_trait_refs ( tcx, trait_refs ) )
342
350
}
343
351
344
352
/// A specialized variant of `elaborate_trait_refs` that only elaborates trait references that may
@@ -393,12 +401,12 @@ impl<I> FilterToTraits<I> {
393
401
}
394
402
}
395
403
396
- impl < ' tcx , I : Iterator < Item = PredicateObligation < ' tcx > > > Iterator for FilterToTraits < I > {
404
+ impl < ' tcx , I : Iterator < Item = ty :: Predicate < ' tcx > > > Iterator for FilterToTraits < I > {
397
405
type Item = ty:: PolyTraitRef < ' tcx > ;
398
406
399
407
fn next ( & mut self ) -> Option < ty:: PolyTraitRef < ' tcx > > {
400
- while let Some ( obligation ) = self . base_iterator . next ( ) {
401
- if let Some ( data) = obligation . predicate . to_opt_poly_trait_pred ( ) {
408
+ while let Some ( pred ) = self . base_iterator . next ( ) {
409
+ if let Some ( data) = pred . to_opt_poly_trait_pred ( ) {
402
410
return Some ( data. map_bound ( |t| t. trait_ref ) ) ;
403
411
}
404
412
}
0 commit comments