Skip to content

Commit 4459b1d

Browse files
committed
rollup merge of rust-lang#20341: nikomatsakis/impl-trait-for-trait-2
Conflicts: src/librustc/middle/traits/mod.rs src/libstd/io/mod.rs src/test/run-pass/builtin-superkinds-self-type.rs
2 parents e921e3f + 704ed4c commit 4459b1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1114
-392
lines changed

src/libcore/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use kinds::Sized;
2525

2626
/// A common trait for cloning an object.
2727
#[stable]
28-
pub trait Clone {
28+
pub trait Clone : Sized {
2929
/// Returns a copy of the value.
3030
#[stable]
3131
fn clone(&self) -> Self;

src/libcore/fmt/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,26 @@ pub trait Writer {
7474
///
7575
/// This method should generally not be invoked manually, but rather through
7676
/// the `write!` macro itself.
77-
fn write_fmt(&mut self, args: Arguments) -> Result { write(self, args) }
77+
fn write_fmt(&mut self, args: Arguments) -> Result {
78+
// This Adapter is needed to allow `self` (of type `&mut
79+
// Self`) to be cast to a FormatWriter (below) without
80+
// requiring a `Sized` bound.
81+
struct Adapter<'a,Sized? T:'a>(&'a mut T);
82+
83+
impl<'a, Sized? T> Writer for Adapter<'a, T>
84+
where T: Writer
85+
{
86+
fn write_str(&mut self, s: &str) -> Result {
87+
self.0.write_str(s)
88+
}
89+
90+
fn write_fmt(&mut self, args: Arguments) -> Result {
91+
self.0.write_fmt(args)
92+
}
93+
}
94+
95+
write(&mut Adapter(self), args)
96+
}
7897
}
7998

8099
/// A struct to represent both where to emit formatting strings to and how they
@@ -579,9 +598,6 @@ impl<'a, Sized? T: Show> Show for &'a T {
579598
impl<'a, Sized? T: Show> Show for &'a mut T {
580599
fn fmt(&self, f: &mut Formatter) -> Result { (**self).fmt(f) }
581600
}
582-
impl<'a> Show for &'a (Show+'a) {
583-
fn fmt(&self, f: &mut Formatter) -> Result { (*self).fmt(f) }
584-
}
585601

586602
impl Show for bool {
587603
fn fmt(&self, f: &mut Formatter) -> Result {

src/libcore/iter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use num::{ToPrimitive, Int};
6565
use ops::{Add, Deref, FnMut};
6666
use option::Option;
6767
use option::Option::{Some, None};
68+
use std::kinds::Sized;
6869
use uint;
6970

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

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

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

739740
/// Extension methods for double-ended iterators.
740741
#[unstable = "new extension trait convention"]
741-
pub trait DoubleEndedIteratorExt<A>: DoubleEndedIterator<A> {
742+
pub trait DoubleEndedIteratorExt<A>: DoubleEndedIterator<A> + Sized {
742743
/// Change the direction of the iterator
743744
///
744745
/// The flipped iterator swaps the ends on an iterator that can already

src/libcore/num/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ impl_to_primitive_float! { f64 }
980980

981981
/// A generic trait for converting a number to a value.
982982
#[experimental = "trait is likely to be removed"]
983-
pub trait FromPrimitive {
983+
pub trait FromPrimitive : ::kinds::Sized {
984984
/// Convert an `int` to return an optional value of this type. If the
985985
/// value cannot be represented by this value, the `None` is returned.
986986
#[inline]

src/libcore/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ use mem;
9292
use clone::Clone;
9393
use intrinsics;
9494
use option::Option::{mod, Some, None};
95-
use kinds::{Send, Sync};
95+
use kinds::{Send, Sized, Sync};
9696

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

244244
/// Methods on raw pointers
245245
#[stable]
246-
pub trait PtrExt<T> {
246+
pub trait PtrExt<T> : Sized {
247247
/// Returns the null pointer.
248248
#[deprecated = "call ptr::null instead"]
249249
fn null() -> Self;

src/librand/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ pub mod reseeding;
5252
mod rand_impls;
5353

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

6161
/// A random number generator.
62-
pub trait Rng {
62+
pub trait Rng : Sized {
6363
/// Return the next random u32.
6464
///
6565
/// This rarely needs to be called directly, prefer `r.gen()` to

src/librustc/middle/infer/combine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use syntax::ast;
5757
use syntax::abi;
5858
use syntax::codemap::Span;
5959

60-
pub trait Combine<'tcx> {
60+
pub trait Combine<'tcx> : Sized {
6161
fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx>;
6262
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.infcx().tcx }
6363
fn tag(&self) -> String;

src/librustc/middle/subst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'a,T> Iterator<(ParamSpace, uint, &'a T)> for EnumeratedItems<'a,T> {
519519
// `foo`. Or use `foo.subst_spanned(tcx, substs, Some(span))` when
520520
// there is more information available (for better errors).
521521

522-
pub trait Subst<'tcx> {
522+
pub trait Subst<'tcx> : Sized {
523523
fn subst(&self, tcx: &ty::ctxt<'tcx>, substs: &Substs<'tcx>) -> Self {
524524
self.subst_spanned(tcx, substs, None)
525525
}

src/librustc/middle/traits/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,27 @@ pub use self::fulfill::{FulfillmentContext, RegionObligation};
3131
pub use self::project::MismatchedProjectionTypes;
3232
pub use self::project::normalize;
3333
pub use self::project::Normalized;
34+
pub use self::object_safety::is_object_safe;
35+
pub use self::object_safety::object_safety_violations;
36+
pub use self::object_safety::ObjectSafetyViolation;
37+
pub use self::object_safety::MethodViolationCode;
3438
pub use self::select::SelectionContext;
3539
pub use self::select::SelectionCache;
3640
pub use self::select::{MethodMatchResult, MethodMatched, MethodAmbiguous, MethodDidNotMatch};
3741
pub use self::select::{MethodMatchedData}; // intentionally don't export variants
3842
pub use self::util::elaborate_predicates;
43+
pub use self::util::get_vtable_index_of_object_method;
3944
pub use self::util::trait_ref_for_builtin_bound;
4045
pub use self::util::supertraits;
4146
pub use self::util::Supertraits;
4247
pub use self::util::transitive_bounds;
48+
pub use self::util::upcast;
4349

4450
mod coherence;
4551
mod error_reporting;
4652
mod fulfill;
4753
mod project;
54+
mod object_safety;
4855
mod select;
4956
mod util;
5057

@@ -212,6 +219,9 @@ pub enum Vtable<'tcx, N> {
212219
/// for some type parameter.
213220
VtableParam,
214221

222+
/// Virtual calls through an object
223+
VtableObject(VtableObjectData<'tcx>),
224+
215225
/// Successful resolution for a builtin trait.
216226
VtableBuiltin(VtableBuiltinData<N>),
217227

@@ -247,6 +257,13 @@ pub struct VtableBuiltinData<N> {
247257
pub nested: subst::VecPerParamSpace<N>
248258
}
249259

260+
/// A vtable for some object-safe trait `Foo` automatically derived
261+
/// for the object type `Foo`.
262+
#[deriving(PartialEq,Eq,Clone)]
263+
pub struct VtableObjectData<'tcx> {
264+
pub object_ty: Ty<'tcx>,
265+
}
266+
250267
/// True if there exist types that satisfy both of the two given impls.
251268
pub fn overlapping_impls(infcx: &InferCtxt,
252269
impl1_def_id: ast::DefId,
@@ -358,6 +375,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
358375
VtableFnPointer(..) => (&[]).iter(),
359376
VtableUnboxedClosure(..) => (&[]).iter(),
360377
VtableParam => (&[]).iter(),
378+
VtableObject(_) => (&[]).iter(),
361379
VtableBuiltin(ref i) => i.iter_nested(),
362380
}
363381
}
@@ -368,6 +386,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
368386
VtableFnPointer(ref sig) => VtableFnPointer((*sig).clone()),
369387
VtableUnboxedClosure(d, ref s) => VtableUnboxedClosure(d, s.clone()),
370388
VtableParam => VtableParam,
389+
VtableObject(ref p) => VtableObject(p.clone()),
371390
VtableBuiltin(ref b) => VtableBuiltin(b.map_nested(op)),
372391
}
373392
}
@@ -380,6 +399,7 @@ impl<'tcx, N> Vtable<'tcx, N> {
380399
VtableFnPointer(sig) => VtableFnPointer(sig),
381400
VtableUnboxedClosure(d, s) => VtableUnboxedClosure(d, s),
382401
VtableParam => VtableParam,
402+
VtableObject(p) => VtableObject(p),
383403
VtableBuiltin(no) => VtableBuiltin(no.map_move_nested(op)),
384404
}
385405
}

0 commit comments

Comments
 (0)