Skip to content
Merged
2 changes: 1 addition & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use kinds::Sized;

/// A common trait for cloning an object.
#[stable]
pub trait Clone {
pub trait Clone : Sized {
/// Returns a copy of the value.
#[stable]
fn clone(&self) -> Self;
Expand Down
24 changes: 20 additions & 4 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,26 @@ pub trait FormatWriter {
///
/// This method should generally not be invoked manually, but rather through
/// the `write!` macro itself.
fn write_fmt(&mut self, args: Arguments) -> Result { write(self, args) }
fn write_fmt(&mut self, args: Arguments) -> Result {
// This Adapter is needed to allow `self` (of type `&mut
// Self`) to be cast to a FormatWriter (below) without
// requiring a `Sized` bound.
struct Adapter<'a,Sized? T:'a>(&'a mut T);

impl<'a, Sized? T> FormatWriter for Adapter<'a, T>
where T: FormatWriter
{
fn write(&mut self, bytes: &[u8]) -> Result {
self.0.write(bytes)
}

fn write_fmt(&mut self, args: Arguments) -> Result {
self.0.write_fmt(args)
}
}

write(&mut Adapter(self), args)
}
}

/// A struct to represent both where to emit formatting strings to and how they
Expand Down Expand Up @@ -586,9 +605,6 @@ impl<'a, Sized? T: Show> Show for &'a T {
impl<'a, Sized? T: Show> Show for &'a mut T {
fn fmt(&self, f: &mut Formatter) -> Result { (**self).fmt(f) }
}
impl<'a> Show for &'a (Show+'a) {
fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
}

impl Show for bool {
fn fmt(&self, f: &mut Formatter) -> Result {
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use num::{ToPrimitive, Int};
use ops::{Add, Deref, FnMut};
use option::Option;
use option::Option::{Some, None};
use std::kinds::Sized;
use uint;

#[deprecated = "renamed to Extend"] pub use self::Extend as Extendable;
Expand Down Expand Up @@ -109,7 +110,7 @@ pub trait Extend<A> {

#[unstable = "new convention for extension traits"]
/// An extension trait providing numerous methods applicable to all iterators.
pub trait IteratorExt<A>: Iterator<A> {
pub trait IteratorExt<A>: Iterator<A> + Sized {
/// Chain this iterator with another, returning a new iterator that will
/// finish iterating over the current iterator, and then iterate
/// over the other specified iterator.
Expand Down Expand Up @@ -692,7 +693,7 @@ impl<A, I> IteratorExt<A> for I where I: Iterator<A> {}

/// Extention trait for iterators of pairs.
#[unstable = "newly added trait, likely to be merged with IteratorExt"]
pub trait IteratorPairExt<A, B>: Iterator<(A, B)> {
pub trait IteratorPairExt<A, B>: Iterator<(A, B)> + Sized {
/// Converts an iterator of pairs into a pair of containers.
///
/// Loops through the entire iterator, collecting the first component of
Expand Down Expand Up @@ -738,7 +739,7 @@ pub trait DoubleEndedIterator<A>: Iterator<A> {

/// Extension methods for double-ended iterators.
#[unstable = "new extension trait convention"]
pub trait DoubleEndedIteratorExt<A>: DoubleEndedIterator<A> {
pub trait DoubleEndedIteratorExt<A>: DoubleEndedIterator<A> + Sized {
/// Change the direction of the iterator
///
/// The flipped iterator swaps the ends on an iterator that can already
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ impl_to_primitive_float! { f64 }

/// A generic trait for converting a number to a value.
#[experimental = "trait is likely to be removed"]
pub trait FromPrimitive {
pub trait FromPrimitive : ::kinds::Sized {
/// Convert an `int` to return an optional value of this type. If the
/// value cannot be represented by this value, the `None` is returned.
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ use mem;
use clone::Clone;
use intrinsics;
use option::Option::{mod, Some, None};
use kinds::{Send, Sync};
use kinds::{Send, Sized, Sync};

use cmp::{PartialEq, Eq, Ord, PartialOrd, Equiv};
use cmp::Ordering::{mod, Less, Equal, Greater};
Expand Down Expand Up @@ -243,7 +243,7 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {

/// Methods on raw pointers
#[stable]
pub trait PtrExt<T> {
pub trait PtrExt<T> : Sized {
/// Returns the null pointer.
#[deprecated = "call ptr::null instead"]
fn null() -> Self;
Expand Down
4 changes: 2 additions & 2 deletions src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ pub mod reseeding;
mod rand_impls;

/// A type that can be randomly generated using an `Rng`.
pub trait Rand {
pub trait Rand : Sized {
/// Generates a random instance of this type using the specified source of
/// randomness.
fn rand<R: Rng>(rng: &mut R) -> Self;
}

/// A random number generator.
pub trait Rng {
pub trait Rng : Sized {
/// Return the next random u32.
///
/// This rarely needs to be called directly, prefer `r.gen()` to
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use syntax::ast;
use syntax::abi;
use syntax::codemap::Span;

pub trait Combine<'tcx> {
pub trait Combine<'tcx> : Sized {
fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx>;
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.infcx().tcx }
fn tag(&self) -> String;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<'a,T> Iterator<(ParamSpace, uint, &'a T)> for EnumeratedItems<'a,T> {
// `foo`. Or use `foo.subst_spanned(tcx, substs, Some(span))` when
// there is more information available (for better errors).

pub trait Subst<'tcx> {
pub trait Subst<'tcx> : Sized {
fn subst(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>) -> Self {
self.subst_spanned(tcx, substs, None)
}
Expand Down
20 changes: 20 additions & 0 deletions src/librustc/middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,27 @@ pub use self::fulfill::{FulfillmentContext, RegionObligation};
pub use self::project::MismatchedProjectionTypes;
pub use self::project::normalize;
pub use self::project::Normalized;
pub use self::object_safety::is_object_safe;
pub use self::object_safety::object_safety_violations;
pub use self::object_safety::ObjectSafetyViolation;
pub use self::object_safety::MethodViolationCode;
pub use self::select::SelectionContext;
pub use self::select::SelectionCache;
pub use self::select::{MethodMatchResult, MethodMatched, MethodAmbiguous, MethodDidNotMatch};
pub use self::select::{MethodMatchedData}; // intentionally don't export variants
pub use self::util::elaborate_predicates;
pub use self::util::get_vtable_index_of_object_method;
pub use self::util::trait_ref_for_builtin_bound;
pub use self::util::supertraits;
pub use self::util::Supertraits;
pub use self::util::transitive_bounds;
pub use self::util::upcast;

mod coherence;
mod error_reporting;
mod fulfill;
mod project;
mod object_safety;
mod select;
mod util;

Expand Down Expand Up @@ -210,6 +217,9 @@ pub enum Vtable<'tcx, N> {
/// for some type parameter.
VtableParam,

/// Virtual calls through an object
VtableObject(VtableObjectData<'tcx>),

/// Successful resolution for a builtin trait.
VtableBuiltin(VtableBuiltinData<N>),

Expand Down Expand Up @@ -245,6 +255,13 @@ pub struct VtableBuiltinData<N> {
pub nested: subst::VecPerParamSpace<N>
}

/// A vtable for some object-safe trait `Foo` automatically derived
/// for the object type `Foo`.
#[deriving(PartialEq,Eq,Clone)]
pub struct VtableObjectData<'tcx> {
pub object_ty: Ty<'tcx>,
}

/// True if neither the trait nor self type is local. Note that `impl_def_id` must refer to an impl
/// of a trait, not an inherent impl.
pub fn is_orphan_impl(tcx: &ty::ctxt,
Expand Down Expand Up @@ -365,6 +382,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
VtableFnPointer(..) => (&[]).iter(),
VtableUnboxedClosure(..) => (&[]).iter(),
VtableParam => (&[]).iter(),
VtableObject(_) => (&[]).iter(),
VtableBuiltin(ref i) => i.iter_nested(),
}
}
Expand All @@ -375,6 +393,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()),
VtableUnboxedClosure(d, ref s) => VtableUnboxedClosure(d, s.clone()),
VtableParam => VtableParam,
VtableObject(ref p) => VtableObject(p.clone()),
VtableBuiltin(ref b) => VtableBuiltin(b.map_nested(op)),
}
}
Expand All @@ -387,6 +406,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
VtableFnPointer(sig) => VtableFnPointer(sig),
VtableUnboxedClosure(d, s) => VtableUnboxedClosure(d, s),
VtableParam => VtableParam,
VtableObject(p) => VtableObject(p),
VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)),
}
}
Expand Down
Loading