Skip to content

Commit

Permalink
Change extensions traits to blanket impls
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Oct 30, 2014
1 parent c48a1ab commit dd2a1e3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
17 changes: 9 additions & 8 deletions src/librustc/middle/typeck/check/method.rs
Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/io/buffered.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/libstd/io/extensions.rs
Expand Up @@ -189,7 +189,6 @@ mod test {
}
}
}
impl BytesReader for InitialZeroByteReader {}

struct EofReader;

Expand All @@ -198,7 +197,6 @@ mod test {
Err(io::standard_error(io::EndOfFile))
}
}
impl BytesReader for EofReader {}

struct ErroringReader;

Expand All @@ -207,7 +205,6 @@ mod test {
Err(io::standard_error(io::InvalidInput))
}
}
impl BytesReader for ErroringReader {}

struct PartialReader {
count: int,
Expand Down
8 changes: 1 addition & 7 deletions src/libstd/io/mem.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -97,8 +97,6 @@ impl Writer for MemWriter {
}
}

impl AsRefWriter for MemWriter {}

/// Reads from an owned byte vector
///
/// # Example
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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) }
Expand Down
20 changes: 16 additions & 4 deletions src/libstd/io/mod.rs
Expand Up @@ -929,21 +929,29 @@ 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.
///
/// # 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.
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)
}
}
Expand Down Expand Up @@ -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 }
}
}
Expand Down

0 comments on commit dd2a1e3

Please sign in to comment.