about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-08-27 21:46:52 -0400
committerNiko Matsakis <niko@alum.mit.edu>2014-08-27 21:46:52 -0400
commit1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f (patch)
tree552fabade603ab0d148a49ae3cf1abd3f399740a /src/libstd
parent3ee047ae1ffab454270bc1859b3beef3556ef8f9 (diff)
downloadrust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.tar.gz
rust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.zip
Implement generalized object and type parameter bounds (Fixes #16462)
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hashmap.rs22
-rw-r--r--src/libstd/io/extensions.rs19
-rw-r--r--src/libstd/io/mod.rs107
-rw-r--r--src/libstd/io/util.rs4
-rw-r--r--src/libstd/lib.rs1
-rw-r--r--src/libstd/path/mod.rs10
-rw-r--r--src/libstd/rt/backtrace.rs2
7 files changed, 152 insertions, 13 deletions
diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs
index b8f8bd41a2d..714712d9eba 100644
--- a/src/libstd/collections/hashmap.rs
+++ b/src/libstd/collections/hashmap.rs
@@ -409,20 +409,38 @@ mod table {
         assert_eq!(size_of::<SafeHash>(), size_of::<u64>())
     }
 
-    /// Iterator over shared references to entries in a table.
+    /// Note: stage0-specific version that lacks bound.
+    #[cfg(stage0)]
     pub struct Entries<'a, K, V> {
         table: &'a RawTable<K, V>,
         idx: uint,
         elems_seen: uint,
     }
 
-    /// Iterator over mutable references to entries in a table.
+    /// Iterator over shared references to entries in a table.
+    #[cfg(not(stage0))]
+    pub struct Entries<'a, K:'a, V:'a> {
+        table: &'a RawTable<K, V>,
+        idx: uint,
+        elems_seen: uint,
+    }
+
+    /// Note: stage0-specific version that lacks bound.
+    #[cfg(stage0)]
     pub struct MutEntries<'a, K, V> {
         table: &'a mut RawTable<K, V>,
         idx: uint,
         elems_seen: uint,
     }
 
+    /// Iterator over mutable references to entries in a table.
+    #[cfg(not(stage0))]
+    pub struct MutEntries<'a, K:'a, V:'a> {
+        table: &'a mut RawTable<K, V>,
+        idx: uint,
+        elems_seen: uint,
+    }
+
     /// Iterator over the entries in a table, consuming the table.
     pub struct MoveEntries<K, V> {
         table: RawTable<K, V>,
diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs
index 12caa715865..ffbcdd87bfe 100644
--- a/src/libstd/io/extensions.rs
+++ b/src/libstd/io/extensions.rs
@@ -37,10 +37,29 @@ use ptr::RawPtr;
 ///
 /// Any error other than `EndOfFile` that is produced by the underlying Reader
 /// is returned by the iterator and should be handled by the caller.
+#[cfg(stage0)]
 pub struct Bytes<'r, T> {
     reader: &'r mut T,
 }
 
+/// An iterator that reads a single byte on each iteration,
+/// until `.read_byte()` returns `EndOfFile`.
+///
+/// # Notes about the Iteration Protocol
+///
+/// The `Bytes` may yield `None` and thus terminate
+/// an iteration, but continue to yield elements if iteration
+/// is attempted again.
+///
+/// # Error
+///
+/// Any error other than `EndOfFile` that is produced by the underlying Reader
+/// is returned by the iterator and should be handled by the caller.
+#[cfg(not(stage0))]
+pub struct Bytes<'r, T:'r> {
+    reader: &'r mut T,
+}
+
 impl<'r, R: Reader> Bytes<'r, R> {
     /// Constructs a new byte iterator from the given Reader instance.
     pub fn new(r: &'r mut R) -> Bytes<'r, R> {
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index dc6478df360..38aa58f1c6a 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -945,11 +945,11 @@ pub trait Reader {
     }
 }
 
-impl Reader for Box<Reader> {
+impl Reader for Box<Reader+'static> {
     fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) }
 }
 
-impl<'a> Reader for &'a mut Reader {
+impl<'a> Reader for &'a mut Reader+'a {
     fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) }
 }
 
@@ -976,6 +976,13 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -
     })
 }
 
+/// Note: stage0-specific version that lacks bound.
+#[cfg(stage0)]
+pub struct RefReader<'a, R> {
+    /// The underlying reader which this is referencing
+    inner: &'a mut R
+}
+
 /// A `RefReader` is a struct implementing `Reader` which contains a reference
 /// to another reader. This is often useful when composing streams.
 ///
@@ -1000,7 +1007,8 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -
 ///
 /// # }
 /// ```
-pub struct RefReader<'a, R> {
+#[cfg(not(stage0))]
+pub struct RefReader<'a, R:'a> {
     /// The underlying reader which this is referencing
     inner: &'a mut R
 }
@@ -1058,12 +1066,21 @@ pub trait Writer {
     ///
     /// This function will return any I/O error reported while formatting.
     fn write_fmt(&mut self, fmt: &fmt::Arguments) -> IoResult<()> {
+        // Note: stage0-specific version that lacks bound.
+        #[cfg(stage0)]
+        struct Adaptor<'a, T> {
+            inner: &'a mut T,
+            error: IoResult<()>,
+        }
+
         // Create a shim which translates a Writer to a FormatWriter and saves
         // off I/O errors. instead of discarding them
-        struct Adaptor<'a, T> {
+        #[cfg(not(stage0))]
+        struct Adaptor<'a, T:'a> {
             inner: &'a mut T,
             error: IoResult<()>,
         }
+
         impl<'a, T: Writer> fmt::FormatWriter for Adaptor<'a, T> {
             fn write(&mut self, bytes: &[u8]) -> fmt::Result {
                 match self.inner.write(bytes) {
@@ -1278,7 +1295,7 @@ pub trait Writer {
     }
 }
 
-impl Writer for Box<Writer> {
+impl Writer for Box<Writer+'static> {
     #[inline]
     fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) }
 
@@ -1286,7 +1303,7 @@ impl Writer for Box<Writer> {
     fn flush(&mut self) -> IoResult<()> { self.flush() }
 }
 
-impl<'a> Writer for &'a mut Writer {
+impl<'a> Writer for &'a mut Writer+'a {
     #[inline]
     fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) }
 
@@ -1318,11 +1335,42 @@ impl<'a> Writer for &'a mut Writer {
 /// println!("input processed: {}", output.unwrap());
 /// # }
 /// ```
+#[cfg(stage0)]
 pub struct RefWriter<'a, W> {
     /// The underlying writer which this is referencing
     inner: &'a mut W
 }
 
+/// A `RefWriter` is a struct implementing `Writer` which contains a reference
+/// to another writer. This is often useful when composing streams.
+///
+/// # Example
+///
+/// ```
+/// # fn main() {}
+/// # fn process_input<R: Reader>(r: R) {}
+/// # fn foo () {
+/// use std::io::util::TeeReader;
+/// use std::io::{stdin, MemWriter};
+///
+/// let mut output = MemWriter::new();
+///
+/// {
+///     // Don't give ownership of 'output' to the 'tee'. Instead we keep a
+///     // handle to it in the outer scope
+///     let mut tee = TeeReader::new(stdin(), output.by_ref());
+///     process_input(tee);
+/// }
+///
+/// println!("input processed: {}", output.unwrap());
+/// # }
+/// ```
+#[cfg(not(stage0))]
+pub struct RefWriter<'a, W:'a> {
+    /// The underlying writer which this is referencing
+    inner: &'a mut W
+}
+
 impl<'a, W: Writer> Writer for RefWriter<'a, W> {
     #[inline]
     fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.inner.write(buf) }
@@ -1351,10 +1399,29 @@ impl<T: Reader + Writer> Stream for T {}
 ///
 /// Any error other than `EndOfFile` that is produced by the underlying Reader
 /// is returned by the iterator and should be handled by the caller.
+#[cfg(stage0)]
 pub struct Lines<'r, T> {
     buffer: &'r mut T,
 }
 
+/// An iterator that reads a line on each iteration,
+/// until `.read_line()` encounters `EndOfFile`.
+///
+/// # Notes about the Iteration Protocol
+///
+/// The `Lines` may yield `None` and thus terminate
+/// an iteration, but continue to yield elements if iteration
+/// is attempted again.
+///
+/// # Error
+///
+/// Any error other than `EndOfFile` that is produced by the underlying Reader
+/// is returned by the iterator and should be handled by the caller.
+#[cfg(not(stage0))]
+pub struct Lines<'r, T:'r> {
+    buffer: &'r mut T,
+}
+
 impl<'r, T: Buffer> Iterator<IoResult<String>> for Lines<'r, T> {
     fn next(&mut self) -> Option<IoResult<String>> {
         match self.buffer.read_line() {
@@ -1378,10 +1445,29 @@ impl<'r, T: Buffer> Iterator<IoResult<String>> for Lines<'r, T> {
 ///
 /// Any error other than `EndOfFile` that is produced by the underlying Reader
 /// is returned by the iterator and should be handled by the caller.
+#[cfg(stage0)]
 pub struct Chars<'r, T> {
     buffer: &'r mut T
 }
 
+/// An iterator that reads a utf8-encoded character on each iteration,
+/// until `.read_char()` encounters `EndOfFile`.
+///
+/// # Notes about the Iteration Protocol
+///
+/// The `Chars` may yield `None` and thus terminate
+/// an iteration, but continue to yield elements if iteration
+/// is attempted again.
+///
+/// # Error
+///
+/// Any error other than `EndOfFile` that is produced by the underlying Reader
+/// is returned by the iterator and should be handled by the caller.
+#[cfg(not(stage0))]
+pub struct Chars<'r, T:'r> {
+    buffer: &'r mut T
+}
+
 impl<'r, T: Buffer> Iterator<IoResult<char>> for Chars<'r, T> {
     fn next(&mut self) -> Option<IoResult<char>> {
         match self.buffer.read_char() {
@@ -1611,6 +1697,12 @@ pub trait Acceptor<T> {
     }
 }
 
+/// Note: stage0-specific version that lacks bound on A.
+#[cfg(stage0)]
+pub struct IncomingConnections<'a, A> {
+    inc: &'a mut A,
+}
+
 /// An infinite iterator over incoming connection attempts.
 /// Calling `next` will block the task until a connection is attempted.
 ///
@@ -1618,7 +1710,8 @@ pub trait Acceptor<T> {
 /// `Some`. The `Some` contains the `IoResult` representing whether the
 /// connection attempt was successful.  A successful connection will be wrapped
 /// in `Ok`. A failed connection is represented as an `Err`.
-pub struct IncomingConnections<'a, A> {
+#[cfg(not(stage0))]
+pub struct IncomingConnections<'a, A:'a> {
     inc: &'a mut A,
 }
 
diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs
index 1fe0ba780a6..7fba0bc85a6 100644
--- a/src/libstd/io/util.rs
+++ b/src/libstd/io/util.rs
@@ -126,12 +126,12 @@ impl Buffer for NullReader {
 /// The `Writer`s are delegated to in order. If any `Writer` returns an error,
 /// that error is returned immediately and remaining `Writer`s are not called.
 pub struct MultiWriter {
-    writers: Vec<Box<Writer>>
+    writers: Vec<Box<Writer+'static>>
 }
 
 impl MultiWriter {
     /// Creates a new `MultiWriter`
-    pub fn new(writers: Vec<Box<Writer>>) -> MultiWriter {
+    pub fn new(writers: Vec<Box<Writer+'static>>) -> MultiWriter {
         MultiWriter { writers: writers }
     }
 }
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs
index d35b644b643..8c1ed7cfa8f 100644
--- a/src/libstd/lib.rs
+++ b/src/libstd/lib.rs
@@ -108,6 +108,7 @@
 #![feature(macro_rules, globs, managed_boxes, linkage)]
 #![feature(default_type_params, phase, lang_items, unsafe_destructor)]
 #![feature(import_shadowing)]
+#![feature(issue_5723_bootstrap)]
 
 // Don't link to std. We are std.
 #![no_std]
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs
index 50441cb534d..6a10be84a62 100644
--- a/src/libstd/path/mod.rs
+++ b/src/libstd/path/mod.rs
@@ -825,12 +825,20 @@ pub trait GenericPathUnsafe {
     unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T);
 }
 
-/// Helper struct for printing paths with format!()
+/// Note: stage0-specific version that lacks bound.
+#[cfg(stage0)]
 pub struct Display<'a, P> {
     path: &'a P,
     filename: bool
 }
 
+/// Helper struct for printing paths with format!()
+#[cfg(not(stage0))]
+pub struct Display<'a, P:'a> {
+    path: &'a P,
+    filename: bool
+}
+
 impl<'a, P: GenericPath> fmt::Show for Display<'a, P> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         self.as_maybe_owned().as_slice().fmt(f)
diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs
index 42384892e69..58b3179a297 100644
--- a/src/libstd/rt/backtrace.rs
+++ b/src/libstd/rt/backtrace.rs
@@ -291,7 +291,7 @@ mod imp {
 
         struct Context<'a> {
             idx: int,
-            writer: &'a mut Writer,
+            writer: &'a mut Writer+'a,
             last_error: Option<IoError>,
         }