Change extensions traits to blanket impls

This commit is contained in:
Nick Cameron 2014-10-16 13:49:00 +13:00
parent c48a1ab158
commit dd2a1e3469
5 changed files with 27 additions and 25 deletions

View File

@ -619,14 +619,15 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
let tcx = self.tcx();
// It is illegal to invoke a method on a trait instance that
// refers to the `Self` type. An error will be reported by
// `enforce_object_limitations()` if the method refers to the
// `Self` type anywhere other than the receiver. Here, we use
// a substitution that replaces `Self` with the object type
// itself. Hence, a `&self` method will wind up with an
// argument type like `&Trait`.
let rcvr_substs = substs.with_self_ty(self_ty);
// It is illegal to create a trait object with methods which includes
// the Self type. An error will be reported when we coerce to a trait
// object if the method refers to the `Self` type. Substituting ty_err
// here allows compiler to soldier on.
//
// `confirm_candidate()` also relies upon this substitution
// for Self. (fix)
let rcvr_substs = substs.with_self_ty(ty::mk_err());
let trait_ref = Rc::new(TraitRef {
def_id: did,
substs: rcvr_substs.clone()

View File

@ -14,7 +14,7 @@
use cmp;
use collections::Collection;
use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult, AsRefReader};
use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
use iter::ExactSize;
use ops::Drop;
use option::{Some, None, Option};
@ -118,8 +118,6 @@ impl<R: Reader> Reader for BufferedReader<R> {
}
}
impl<R: Reader> AsRefReader for BufferedReader<R> {}
/// Wraps a Writer and buffers output to it
///
/// It can be excessively inefficient to work directly with a `Writer`. For

View File

@ -189,7 +189,6 @@ mod test {
}
}
}
impl BytesReader for InitialZeroByteReader {}
struct EofReader;
@ -198,7 +197,6 @@ mod test {
Err(io::standard_error(io::EndOfFile))
}
}
impl BytesReader for EofReader {}
struct ErroringReader;
@ -207,7 +205,6 @@ mod test {
Err(io::standard_error(io::InvalidInput))
}
}
impl BytesReader for ErroringReader {}
struct PartialReader {
count: int,

View File

@ -17,7 +17,7 @@ use collections::Collection;
use option::None;
use result::{Err, Ok};
use io;
use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult, AsRefReader, AsRefWriter};
use io::{Reader, Writer, Seek, Buffer, IoError, SeekStyle, IoResult};
use slice;
use slice::AsSlice;
use vec::Vec;
@ -97,8 +97,6 @@ impl Writer for MemWriter {
}
}
impl AsRefWriter for MemWriter {}
/// Reads from an owned byte vector
///
/// # Example
@ -165,8 +163,6 @@ impl Reader for MemReader {
}
}
impl AsRefReader for MemReader {}
impl Seek for MemReader {
#[inline]
fn tell(&self) -> IoResult<u64> { Ok(self.pos as u64) }
@ -313,8 +309,6 @@ impl<'a> Reader for BufReader<'a> {
}
}
impl<'a> AsRefReader for BufReader<'a> {}
impl<'a> Seek for BufReader<'a> {
#[inline]
fn tell(&self) -> IoResult<u64> { Ok(self.pos as u64) }

View File

@ -929,13 +929,17 @@ pub trait AsRefReader {
///
/// This is useful to allow applying adaptors while still
/// retaining ownership of the original value.
fn by_ref<'a>(&'a mut self) -> RefReader<'a, Self> {
fn by_ref<'a>(&'a mut self) -> RefReader<'a, Self>;
}
impl<T: Reader> AsRefReader for T {
fn by_ref<'a>(&'a mut self) -> RefReader<'a, T> {
RefReader { inner: self }
}
}
/// A reader which can be converted to bytes.
pub trait BytesReader: Reader {
pub trait BytesReader {
/// Create an iterator that reads a single byte on
/// each iteration, until EOF.
///
@ -943,7 +947,11 @@ pub trait BytesReader: Reader {
///
/// Any error other than `EndOfFile` that is produced by the underlying Reader
/// is returned by the iterator and should be handled by the caller.
fn bytes<'r>(&'r mut self) -> extensions::Bytes<'r, Self> {
fn bytes<'r>(&'r mut self) -> extensions::Bytes<'r, Self>;
}
impl<T: Reader> BytesReader for T {
fn bytes<'r>(&'r mut self) -> extensions::Bytes<'r, T> {
extensions::Bytes::new(self)
}
}
@ -1284,7 +1292,11 @@ pub trait AsRefWriter {
/// This is useful to allow applying wrappers while still
/// retaining ownership of the original value.
#[inline]
fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self> {
fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self>;
}
impl<T: Writer> AsRefWriter for T {
fn by_ref<'a>(&'a mut self) -> RefWriter<'a, T> {
RefWriter { inner: self }
}
}