]> git.lizzy.rs Git - rust.git/commitdiff
Move EnumSet into libextra
authorSangeun Kim <sammy.kim@samsung.com>
Fri, 26 Jul 2013 04:53:29 +0000 (13:53 +0900)
committerSangeun Kim <sammy.kim@samsung.com>
Tue, 6 Aug 2013 05:45:02 +0000 (14:45 +0900)
src/libextra/enum_set.rs [new file with mode: 0644]
src/libextra/extra.rs
src/librustc/metadata/tyencode.rs
src/librustc/middle/kind.rs
src/librustc/middle/ty.rs
src/librustc/rustc.rs
src/librustc/util/enum_set.rs [deleted file]
src/librustc/util/ppaux.rs

diff --git a/src/libextra/enum_set.rs b/src/libextra/enum_set.rs
new file mode 100644 (file)
index 0000000..25501fa
--- /dev/null
@@ -0,0 +1,288 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::iterator::Iterator;
+
+#[deriving(Clone, Eq, IterBytes, ToStr)]
+/// A specialized Set implementation to use enum types.
+pub struct EnumSet<E> {
+    // We must maintain the invariant that no bits are set
+    // for which no variant exists
+    priv bits: uint
+}
+
+/// An iterface for casting C-like enum to uint and back.
+pub trait CLike {
+    /// Converts C-like enum to uint.
+    pub fn to_uint(&self) -> uint;
+    /// Converts uint to C-like enum.
+    pub fn from_uint(uint) -> Self;
+}
+
+fn bit<E:CLike>(e: E) -> uint {
+    1 << e.to_uint()
+}
+
+impl<E:CLike> EnumSet<E> {
+    /// Returns an empty EnumSet.
+    pub fn empty() -> EnumSet<E> {
+        EnumSet {bits: 0}
+    }
+
+    /// Returns true if an EnumSet is empty.
+    pub fn is_empty(&self) -> bool {
+        self.bits == 0
+    }
+
+    /// Returns true if an EnumSet contains any enum of a given EnumSet
+    pub fn intersects(&self, e: EnumSet<E>) -> bool {
+        (self.bits & e.bits) != 0
+    }
+
+    /// Returns an intersection of both EnumSets.
+    pub fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
+        EnumSet {bits: self.bits & e.bits}
+    }
+
+    /// Returns true if a given EnumSet is included in an EnumSet.
+    pub fn contains(&self, e: EnumSet<E>) -> bool {
+        (self.bits & e.bits) == e.bits
+    }
+
+    /// Returns a union of both EnumSets.
+    pub fn union(&self, e: EnumSet<E>) -> EnumSet<E> {
+        EnumSet {bits: self.bits | e.bits}
+    }
+
+    /// Add an enum to an EnumSet
+    pub fn add(&mut self, e: E) {
+        self.bits |= bit(e);
+    }
+
+    /// Returns true if an EnumSet contains a given enum
+    pub fn contains_elem(&self, e: E) -> bool {
+        (self.bits & bit(e)) != 0
+    }
+
+    /// Returns an iterator over an EnumSet
+    pub fn iter(&self) -> EnumSetIterator<E> {
+        EnumSetIterator::new(self.bits)
+    }
+}
+
+impl<E:CLike> Sub<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
+    fn sub(&self, e: &EnumSet<E>) -> EnumSet<E> {
+        EnumSet {bits: self.bits & !e.bits}
+    }
+}
+
+impl<E:CLike> BitOr<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
+    fn bitor(&self, e: &EnumSet<E>) -> EnumSet<E> {
+        EnumSet {bits: self.bits | e.bits}
+    }
+}
+
+impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
+    fn bitand(&self, e: &EnumSet<E>) -> EnumSet<E> {
+        EnumSet {bits: self.bits & e.bits}
+    }
+}
+
+/// An iterator over an EnumSet
+pub struct EnumSetIterator<E> {
+    priv index: uint,
+    priv bits: uint,
+}
+
+impl<E:CLike> EnumSetIterator<E> {
+    fn new(bits: uint) -> EnumSetIterator<E> {
+        EnumSetIterator { index: 0, bits: bits }
+    }
+}
+
+impl<E:CLike> Iterator<E> for EnumSetIterator<E> {
+    fn next(&mut self) -> Option<E> {
+        if (self.bits == 0) {
+            return None;
+        }
+
+        while (self.bits & 1) == 0 {
+            self.index += 1;
+            self.bits >>= 1;
+        }
+        let elem = CLike::from_uint(self.index);
+        self.index += 1;
+        self.bits >>= 1;
+        Some(elem)
+    }
+
+    fn size_hint(&self) -> (uint, Option<uint>) {
+        let exact = self.bits.population_count();
+        (exact, Some(exact))
+    }
+}
+
+#[cfg(test)]
+mod test {
+
+    use std::cast;
+
+    use enum_set::*;
+
+    #[deriving(Eq)]
+    enum Foo {
+        A, B, C
+    }
+
+    impl CLike for Foo {
+        pub fn to_uint(&self) -> uint {
+            *self as uint
+        }
+
+        pub fn from_uint(v: uint) -> Foo {
+            unsafe { cast::transmute(v) }
+        }
+    }
+
+    #[test]
+    fn test_empty() {
+        let e: EnumSet<Foo> = EnumSet::empty();
+        assert!(e.is_empty());
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    // intersect
+
+    #[test]
+    fn test_two_empties_do_not_intersect() {
+        let e1: EnumSet<Foo> = EnumSet::empty();
+        let e2: EnumSet<Foo> = EnumSet::empty();
+        assert!(!e1.intersects(e2));
+    }
+
+    #[test]
+    fn test_empty_does_not_intersect_with_full() {
+        let e1: EnumSet<Foo> = EnumSet::empty();
+
+        let mut e2: EnumSet<Foo> = EnumSet::empty();
+        e2.add(A);
+        e2.add(B);
+        e2.add(C);
+
+        assert!(!e1.intersects(e2));
+    }
+
+    #[test]
+    fn test_disjoint_intersects() {
+        let mut e1: EnumSet<Foo> = EnumSet::empty();
+        e1.add(A);
+
+        let mut e2: EnumSet<Foo> = EnumSet::empty();
+        e2.add(B);
+
+        assert!(!e1.intersects(e2));
+    }
+
+    #[test]
+    fn test_overlapping_intersects() {
+        let mut e1: EnumSet<Foo> = EnumSet::empty();
+        e1.add(A);
+
+        let mut e2: EnumSet<Foo> = EnumSet::empty();
+        e2.add(A);
+        e2.add(B);
+
+        assert!(e1.intersects(e2));
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    // contains and contains_elem
+
+    #[test]
+    fn test_contains() {
+        let mut e1: EnumSet<Foo> = EnumSet::empty();
+        e1.add(A);
+
+        let mut e2: EnumSet<Foo> = EnumSet::empty();
+        e2.add(A);
+        e2.add(B);
+
+        assert!(!e1.contains(e2));
+        assert!(e2.contains(e1));
+    }
+
+    #[test]
+    fn test_contains_elem() {
+        let mut e1: EnumSet<Foo> = EnumSet::empty();
+        e1.add(A);
+        assert!(e1.contains_elem(A));
+        assert!(!e1.contains_elem(B));
+        assert!(!e1.contains_elem(C));
+
+        e1.add(A);
+        e1.add(B);
+        assert!(e1.contains_elem(A));
+        assert!(e1.contains_elem(B));
+        assert!(!e1.contains_elem(C));
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    // iter
+
+    #[test]
+    fn test_iterator() {
+        let mut e1: EnumSet<Foo> = EnumSet::empty();
+
+        let elems: ~[Foo] = e1.iter().collect();
+        assert_eq!(~[], elems)
+
+        e1.add(A);
+        let elems: ~[Foo] = e1.iter().collect();
+        assert_eq!(~[A], elems)
+
+        e1.add(C);
+        let elems: ~[Foo] = e1.iter().collect();
+        assert_eq!(~[A,C], elems)
+
+        e1.add(C);
+        let elems: ~[Foo] = e1.iter().collect();
+        assert_eq!(~[A,C], elems)
+
+        e1.add(B);
+        let elems: ~[Foo] = e1.iter().collect();
+        assert_eq!(~[A,B,C], elems)
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    // operators
+
+    #[test]
+    fn test_operators() {
+        let mut e1: EnumSet<Foo> = EnumSet::empty();
+        e1.add(A);
+        e1.add(C);
+
+        let mut e2: EnumSet<Foo> = EnumSet::empty();
+        e2.add(B);
+        e2.add(C);
+
+        let e_union = e1 | e2;
+        let elems: ~[Foo] = e_union.iter().collect();
+        assert_eq!(~[A,B,C], elems)
+
+        let e_intersection = e1 & e2;
+        let elems: ~[Foo] = e_intersection.iter().collect();
+        assert_eq!(~[C], elems)
+
+        let e_subtract = e1 - e2;
+        let elems: ~[Foo] = e_subtract.iter().collect();
+        assert_eq!(~[A], elems)
+    }
+}
index e6134bb340cd8c45b708ab71d6f3539b45b4061d..58929778a59e20f6afb11105979894b771755207 100644 (file)
@@ -91,6 +91,7 @@
 pub mod base64;
 pub mod rl;
 pub mod workcache;
+pub mod enum_set;
 #[path="num/bigint.rs"]
 pub mod bigint;
 #[path="num/rational.rs"]
index ec50f564385c3a9d3f777d0f9073f2f785deef79..ffd79433b76930fe7186c138a71fdaaed995436a 100644 (file)
@@ -413,15 +413,14 @@ fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
 }
 
 fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) {
-    do bs.builtin_bounds.each |bound| {
+    for bound in bs.builtin_bounds.iter() {
         match bound {
             ty::BoundSend => w.write_char('S'),
             ty::BoundFreeze => w.write_char('K'),
             ty::BoundStatic => w.write_char('O'),
             ty::BoundSized => w.write_char('Z'),
         }
-        true
-    };
+    }
 
     for &tp in bs.trait_bounds.iter() {
         w.write_char('I');
index 3bdf0c0f6dcb84c32db21792a769cb9c923b17a4..84eb371d7b34ac49a51b99bbde139804bd918fbc 100644 (file)
@@ -338,12 +338,11 @@ pub fn check_builtin_bounds(cx: Context, ty: ty::t, bounds: ty::BuiltinBounds,
 {
     let kind = ty::type_contents(cx.tcx, ty);
     let mut missing = ty::EmptyBuiltinBounds();
-    do bounds.each |bound| {
+    for bound in bounds.iter() {
         if !kind.meets_bound(cx.tcx, bound) {
             missing.add(bound);
         }
-        true
-    };
+    }
     if !missing.is_empty() {
         any_missing(missing);
     }
index 48a003ddaf157522b44e040584708362aeb56fb8..a53bdff85f9dc2cb4903f2ef47d67b2b69969ce0 100644 (file)
@@ -25,7 +25,6 @@
 use util::ppaux::{trait_store_to_str, ty_to_str, vstore_to_str};
 use util::ppaux::{Repr, UserString};
 use util::common::{indenter};
-use util::enum_set::{EnumSet, CLike};
 
 use std::cast;
 use std::cmp;
@@ -48,6 +47,7 @@
 use syntax::opt_vec;
 use syntax::abi::AbiSet;
 use syntax;
+use extra::enum_set::{EnumSet, CLike};
 
 pub static INITIAL_DISCRIMINANT_VALUE: uint = 0;
 
@@ -2287,7 +2287,7 @@ fn trait_contents(store: TraitStore, mutbl: ast::mutability,
         // This is like with typarams below, but less "pessimistic" and also
         // dependent on the trait store.
         let mut bt = TC_NONE;
-        do (AllBuiltinBounds() - bounds).each |bound| {
+        for bound in (AllBuiltinBounds() - bounds).iter() {
             bt = bt + match bound {
                 BoundStatic if bounds.contains_elem(BoundSend)
                             => TC_NONE, // Send bound implies static bound.
@@ -2296,8 +2296,7 @@ fn trait_contents(store: TraitStore, mutbl: ast::mutability,
                 BoundFreeze => TC_MUTABLE,
                 BoundSized  => TC_NONE, // don't care if interior is sized
             };
-            true
-        };
+        }
         st + mt + bt
     }
 
@@ -2308,7 +2307,7 @@ fn type_param_def_to_contents(cx: ctxt,
         let _i = indenter();
 
         let mut tc = TC_ALL;
-        do type_param_def.bounds.builtin_bounds.each |bound| {
+        for bound in type_param_def.bounds.builtin_bounds.iter() {
             debug!("tc = %s, bound = %?", tc.to_str(), bound);
             tc = tc - match bound {
                 BoundStatic => TypeContents::nonstatic(cx),
@@ -2317,8 +2316,7 @@ fn type_param_def_to_contents(cx: ctxt,
                 // The dynamic-size bit can be removed at pointer-level, etc.
                 BoundSized => TypeContents::dynamically_sized(cx),
             };
-            true
-        };
+        }
 
         debug!("result = %s", tc.to_str());
         return tc;
index c48b30e81416439ad86c9e9217e8bfb10f43ee5a..46414a7a5e23e0cc13e0e886d94db7c872a2c20c 100644 (file)
@@ -96,7 +96,6 @@ pub mod back {
 pub mod util {
     pub mod common;
     pub mod ppaux;
-    pub mod enum_set;
 }
 
 pub mod lib {
diff --git a/src/librustc/util/enum_set.rs b/src/librustc/util/enum_set.rs
deleted file mode 100644 (file)
index ced29f1..0000000
+++ /dev/null
@@ -1,318 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::iterator::Iterator;
-
-#[deriving(Clone, Eq, IterBytes, ToStr)]
-pub struct EnumSet<E> {
-    // We must maintain the invariant that no bits are set
-    // for which no variant exists
-    priv bits: uint
-}
-
-pub trait CLike {
-    pub fn to_uint(&self) -> uint;
-    pub fn from_uint(uint) -> Self;
-}
-
-fn bit<E:CLike>(e: E) -> uint {
-    1 << e.to_uint()
-}
-
-impl<E:CLike> EnumSet<E> {
-    pub fn empty() -> EnumSet<E> {
-        EnumSet {bits: 0}
-    }
-
-    pub fn is_empty(&self) -> bool {
-        self.bits == 0
-    }
-
-    pub fn intersects(&self, e: EnumSet<E>) -> bool {
-        (self.bits & e.bits) != 0
-    }
-
-    pub fn intersection(&self, e: EnumSet<E>) -> EnumSet<E> {
-        EnumSet {bits: self.bits & e.bits}
-    }
-
-    pub fn contains(&self, e: EnumSet<E>) -> bool {
-        (self.bits & e.bits) == e.bits
-    }
-
-    pub fn union(&self, e: EnumSet<E>) -> EnumSet<E> {
-        EnumSet {bits: self.bits | e.bits}
-    }
-
-    pub fn add(&mut self, e: E) {
-        self.bits |= bit(e);
-    }
-
-    pub fn contains_elem(&self, e: E) -> bool {
-        (self.bits & bit(e)) != 0
-    }
-
-    pub fn each(&self, f: &fn(E) -> bool) -> bool {
-        let mut bits = self.bits;
-        let mut index = 0;
-        while bits != 0 {
-            if (bits & 1) != 0 {
-                let e = CLike::from_uint(index);
-                if !f(e) {
-                    return false;
-                }
-            }
-            index += 1;
-            bits >>= 1;
-        }
-        return true;
-    }
-
-    pub fn iter(&self) -> EnumSetIterator<E> {
-        EnumSetIterator::new(self.bits)
-    }
-}
-
-impl<E:CLike> Sub<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
-    fn sub(&self, e: &EnumSet<E>) -> EnumSet<E> {
-        EnumSet {bits: self.bits & !e.bits}
-    }
-}
-
-impl<E:CLike> BitOr<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
-    fn bitor(&self, e: &EnumSet<E>) -> EnumSet<E> {
-        EnumSet {bits: self.bits | e.bits}
-    }
-}
-
-impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
-    fn bitand(&self, e: &EnumSet<E>) -> EnumSet<E> {
-        EnumSet {bits: self.bits & e.bits}
-    }
-}
-
-pub struct EnumSetIterator<E> {
-    priv index: uint,
-    priv bits: uint,
-}
-
-impl<E:CLike> EnumSetIterator<E> {
-    fn new(bits: uint) -> EnumSetIterator<E> {
-        EnumSetIterator { index: 0, bits: bits }
-    }
-}
-
-impl<E:CLike> Iterator<E> for EnumSetIterator<E> {
-    fn next(&mut self) -> Option<E> {
-        if (self.bits == 0) {
-            return None;
-        }
-
-        while (self.bits & 1) == 0 {
-            self.index += 1;
-            self.bits >>= 1;
-        }
-        let elem = CLike::from_uint(self.index);
-        self.index += 1;
-        self.bits >>= 1;
-        Some(elem)
-    }
-
-    fn size_hint(&self) -> (uint, Option<uint>) {
-        let exact = self.bits.population_count();
-        (exact, Some(exact))
-    }
-}
-
-#[cfg(test)]
-mod test {
-
-    use std::cast;
-
-    use util::enum_set::*;
-
-    #[deriving(Eq)]
-    enum Foo {
-        A, B, C
-    }
-
-    impl CLike for Foo {
-        pub fn to_uint(&self) -> uint {
-            *self as uint
-        }
-
-        pub fn from_uint(v: uint) -> Foo {
-            unsafe { cast::transmute(v) }
-        }
-    }
-
-    #[test]
-    fn test_empty() {
-        let e: EnumSet<Foo> = EnumSet::empty();
-        assert!(e.is_empty());
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    // intersect
-
-    #[test]
-    fn test_two_empties_do_not_intersect() {
-        let e1: EnumSet<Foo> = EnumSet::empty();
-        let e2: EnumSet<Foo> = EnumSet::empty();
-        assert!(!e1.intersects(e2));
-    }
-
-    #[test]
-    fn test_empty_does_not_intersect_with_full() {
-        let e1: EnumSet<Foo> = EnumSet::empty();
-
-        let mut e2: EnumSet<Foo> = EnumSet::empty();
-        e2.add(A);
-        e2.add(B);
-        e2.add(C);
-
-        assert!(!e1.intersects(e2));
-    }
-
-    #[test]
-    fn test_disjoint_intersects() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-        e1.add(A);
-
-        let mut e2: EnumSet<Foo> = EnumSet::empty();
-        e2.add(B);
-
-        assert!(!e1.intersects(e2));
-    }
-
-    #[test]
-    fn test_overlapping_intersects() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-        e1.add(A);
-
-        let mut e2: EnumSet<Foo> = EnumSet::empty();
-        e2.add(A);
-        e2.add(B);
-
-        assert!(e1.intersects(e2));
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    // contains and contains_elem
-
-    #[test]
-    fn test_contains() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-        e1.add(A);
-
-        let mut e2: EnumSet<Foo> = EnumSet::empty();
-        e2.add(A);
-        e2.add(B);
-
-        assert!(!e1.contains(e2));
-        assert!(e2.contains(e1));
-    }
-
-    #[test]
-    fn test_contains_elem() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-        e1.add(A);
-        assert!(e1.contains_elem(A));
-        assert!(!e1.contains_elem(B));
-        assert!(!e1.contains_elem(C));
-
-        e1.add(A);
-        e1.add(B);
-        assert!(e1.contains_elem(A));
-        assert!(e1.contains_elem(B));
-        assert!(!e1.contains_elem(C));
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    // iter / each
-
-    #[test]
-    fn test_iterator() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-
-        let elems: ~[Foo] = e1.iter().collect();
-        assert_eq!(~[], elems)
-
-        e1.add(A);
-        let elems: ~[Foo] = e1.iter().collect();
-        assert_eq!(~[A], elems)
-
-        e1.add(C);
-        let elems: ~[Foo] = e1.iter().collect();
-        assert_eq!(~[A,C], elems)
-
-        e1.add(C);
-        let elems: ~[Foo] = e1.iter().collect();
-        assert_eq!(~[A,C], elems)
-
-        e1.add(B);
-        let elems: ~[Foo] = e1.iter().collect();
-        assert_eq!(~[A,B,C], elems)
-    }
-
-    #[test]
-    fn test_each() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-
-        assert_eq!(~[], collect(e1))
-
-        e1.add(A);
-        assert_eq!(~[A], collect(e1))
-
-        e1.add(C);
-        assert_eq!(~[A,C], collect(e1))
-
-        e1.add(C);
-        assert_eq!(~[A,C], collect(e1))
-
-        e1.add(B);
-        assert_eq!(~[A,B,C], collect(e1))
-    }
-
-    fn collect(e: EnumSet<Foo>) -> ~[Foo] {
-        let mut elems = ~[];
-        e.each(|elem| {
-           elems.push(elem);
-           true
-        });
-        elems
-    }
-
-    ///////////////////////////////////////////////////////////////////////////
-    // operators
-
-    #[test]
-    fn test_operators() {
-        let mut e1: EnumSet<Foo> = EnumSet::empty();
-        e1.add(A);
-        e1.add(C);
-
-        let mut e2: EnumSet<Foo> = EnumSet::empty();
-        e2.add(B);
-        e2.add(C);
-
-        let e_union = e1 | e2;
-        let elems: ~[Foo] = e_union.iter().collect();
-        assert_eq!(~[A,B,C], elems)
-
-        let e_intersection = e1 & e2;
-        let elems: ~[Foo] = e_intersection.iter().collect();
-        assert_eq!(~[C], elems)
-
-        let e_subtract = e1 - e2;
-        let elems: ~[Foo] = e_subtract.iter().collect();
-        assert_eq!(~[A], elems)
-    }
-}
index 8f0dd51457074c23bdd2e2a7cb219e4f8cd40301..8329ad2cdf1de34ca864f5919f6681ed36b90ecf 100644 (file)
@@ -589,15 +589,14 @@ fn repr(&self, tcx: ctxt) -> ~str {
 impl Repr for ty::ParamBounds {
     fn repr(&self, tcx: ctxt) -> ~str {
         let mut res = ~[];
-        do self.builtin_bounds.each |b| {
+        for b in self.builtin_bounds.iter() {
             res.push(match b {
                 ty::BoundStatic => ~"'static",
                 ty::BoundSend => ~"Send",
                 ty::BoundFreeze => ~"Freeze",
                 ty::BoundSized => ~"Sized",
             });
-            true
-        };
+        }
         for t in self.trait_bounds.iter() {
             res.push(t.repr(tcx));
         }
@@ -833,10 +832,9 @@ impl UserString for ty::BuiltinBounds {
     fn user_string(&self, tcx: ctxt) -> ~str {
         if self.is_empty() { ~"<no-bounds>" } else {
             let mut result = ~[];
-            do self.each |bb| {
+            for bb in self.iter() {
                 result.push(bb.user_string(tcx));
-                true
-            };
+            }
             result.connect("+")
         }
     }