Skip to content

Commit 4dfa81f

Browse files
committed
Extract out the filter_to_traits functionality
1 parent ba1b5ee commit 4dfa81f

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/librustc/middle/traits/util.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ pub fn elaborate_predicates<'cx, 'tcx>(
110110
}
111111

112112
impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
113-
pub fn filter_to_traits(self) -> Supertraits<'cx, 'tcx> {
114-
Supertraits { elaborator: self }
113+
pub fn filter_to_traits(self) -> JustTraits<Elaborator<'cx, 'tcx>> {
114+
JustTraits::new(self)
115115
}
116116

117117
fn push(&mut self, predicate: &ty::Predicate<'tcx>) {
@@ -185,11 +185,7 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
185185
// Supertrait iterator
186186
///////////////////////////////////////////////////////////////////////////
187187

188-
/// A filter around the `Elaborator` that just yields up supertrait references,
189-
/// not other kinds of predicates.
190-
pub struct Supertraits<'cx, 'tcx:'cx> {
191-
elaborator: Elaborator<'cx, 'tcx>,
192-
}
188+
pub type Supertraits<'cx, 'tcx> = JustTraits<Elaborator<'cx, 'tcx>>;
193189

194190
pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
195191
trait_ref: ty::PolyTraitRef<'tcx>)
@@ -205,12 +201,28 @@ pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
205201
elaborate_trait_refs(tcx, bounds).filter_to_traits()
206202
}
207203

208-
impl<'cx, 'tcx> Iterator for Supertraits<'cx, 'tcx> {
204+
///////////////////////////////////////////////////////////////////////////
205+
// Other
206+
///////////////////////////////////////////////////////////////////////////
207+
208+
/// A filter around an iterator of predicates that makes it yield up
209+
/// just trait references.
210+
pub struct JustTraits<I> {
211+
base_iterator: I
212+
}
213+
214+
impl<I> JustTraits<I> {
215+
fn new(base: I) -> JustTraits<I> {
216+
JustTraits { base_iterator: base }
217+
}
218+
}
219+
220+
impl<'tcx,I:Iterator<Item=ty::Predicate<'tcx>>> Iterator for JustTraits<I> {
209221
type Item = ty::PolyTraitRef<'tcx>;
210222

211223
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
212224
loop {
213-
match self.elaborator.next() {
225+
match self.base_iterator.next() {
214226
None => {
215227
return None;
216228
}
@@ -224,6 +236,7 @@ impl<'cx, 'tcx> Iterator for Supertraits<'cx, 'tcx> {
224236
}
225237
}
226238

239+
227240
///////////////////////////////////////////////////////////////////////////
228241
// Other
229242
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)