Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1993,10 +1993,10 @@ trait, `self` is a type, and in an impl, `self` is a value. The
following trait describes types that support an equality operation:

~~~~
// In a trait, `self` refers both to the self argument
// and to the type implementing the trait
// In a trait, `self` refers both to the self argument.
// `Self` refers to the type implementing the trait.
trait Eq {
fn equals(&self, other: &self) -> bool;
fn equals(&self, other: &Self) -> bool;
}

// In an impl, `self` refers just to the value of the receiver
Expand All @@ -2015,7 +2015,7 @@ the method name with the trait name.
The compiler will use type inference to decide which implementation to call.

~~~~
trait Shape { static fn new(area: float) -> self; }
trait Shape { static fn new(area: float) -> Self; }
# use float::consts::pi;
# use float::sqrt;
struct Circle { radius: float }
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Clonable types are copied with the clone method
*/
pub trait Clone {
fn clone(&self) -> self;
fn clone(&self) -> Self;
}

impl (): Clone {
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ and `Eq` to overload the `==` and `!=` operators.
*/
#[lang="eq"]
pub trait Eq {
pure fn eq(&self, other: &self) -> bool;
pure fn ne(&self, other: &self) -> bool;
pure fn eq(&self, other: &Self) -> bool;
pure fn ne(&self, other: &Self) -> bool;
}

/**
Expand All @@ -53,10 +53,10 @@ pub trait Eq {
*/
#[lang="ord"]
pub trait Ord {
pure fn lt(&self, other: &self) -> bool;
pure fn le(&self, other: &self) -> bool;
pure fn ge(&self, other: &self) -> bool;
pure fn gt(&self, other: &self) -> bool;
pure fn lt(&self, other: &Self) -> bool;
pure fn le(&self, other: &Self) -> bool;
pure fn ge(&self, other: &Self) -> bool;
pure fn gt(&self, other: &Self) -> bool;
}

#[inline(always)]
Expand Down
14 changes: 7 additions & 7 deletions src/libcore/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ pub trait Set<T>: Mutable {

/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
pure fn is_disjoint(&self, other: &self) -> bool;
pure fn is_disjoint(&self, other: &Self) -> bool;

/// Return true if the set is a subset of another
pure fn is_subset(&self, other: &self) -> bool;
pure fn is_subset(&self, other: &Self) -> bool;

/// Return true if the set is a superset of another
pure fn is_superset(&self, other: &self) -> bool;
pure fn is_superset(&self, other: &Self) -> bool;

/// Visit the values representing the difference
pure fn difference(&self, other: &self, f: fn(&T) -> bool);
pure fn difference(&self, other: &Self, f: fn(&T) -> bool);

/// Visit the values representing the symmetric difference
pure fn symmetric_difference(&self, other: &self, f: fn(&T) -> bool);
pure fn symmetric_difference(&self, other: &Self, f: fn(&T) -> bool);

/// Visit the values representing the intersection
pure fn intersection(&self, other: &self, f: fn(&T) -> bool);
pure fn intersection(&self, other: &Self, f: fn(&T) -> bool);

/// Visit the values representing the union
pure fn union(&self, other: &self, f: fn(&T) -> bool);
pure fn union(&self, other: &Self, f: fn(&T) -> bool);
}
2 changes: 1 addition & 1 deletion src/libcore/from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
use option::Option;

pub trait FromStr {
static pure fn from_str(s: &str) -> Option<self>;
static pure fn from_str(s: &str) -> Option<Self>;
}

2 changes: 1 addition & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait Buildable<A> {
* onto the sequence being constructed.
*/
static pure fn build_sized(size: uint,
builder: fn(push: pure fn(A))) -> self;
builder: fn(push: pure fn(A))) -> Self;
}

#[inline(always)]
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@

pub trait Num {
// FIXME: Trait composition. (#2616)
pure fn add(&self, other: &self) -> self;
pure fn sub(&self, other: &self) -> self;
pure fn mul(&self, other: &self) -> self;
pure fn div(&self, other: &self) -> self;
pure fn modulo(&self, other: &self) -> self;
pure fn neg(&self) -> self;
pure fn add(&self, other: &Self) -> Self;
pure fn sub(&self, other: &Self) -> Self;
pure fn mul(&self, other: &Self) -> Self;
pure fn div(&self, other: &Self) -> Self;
pure fn modulo(&self, other: &Self) -> Self;
pure fn neg(&self) -> Self;

pure fn to_int(&self) -> int;
static pure fn from_int(n: int) -> self;
static pure fn from_int(n: int) -> Self;
}

pub trait IntConvertible {
pure fn to_int(&self) -> int;
static pure fn from_int(n: int) -> self;
static pure fn from_int(n: int) -> Self;
}

pub trait Zero {
static pure fn zero() -> self;
static pure fn zero() -> Self;
}

pub trait One {
static pure fn one() -> self;
static pure fn one() -> Self;
}
25 changes: 12 additions & 13 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,27 @@ pub pure fn PosixPath(s: &str) -> PosixPath {
}

pub trait GenericPath {

static pure fn from_str(&str) -> self;
static pure fn from_str(&str) -> Self;

pure fn dirname() -> ~str;
pure fn filename() -> Option<~str>;
pure fn filestem() -> Option<~str>;
pure fn filetype() -> Option<~str>;

pure fn with_dirname((&str)) -> self;
pure fn with_filename((&str)) -> self;
pure fn with_filestem((&str)) -> self;
pure fn with_filetype((&str)) -> self;
pure fn with_dirname((&str)) -> Self;
pure fn with_filename((&str)) -> Self;
pure fn with_filestem((&str)) -> Self;
pure fn with_filetype((&str)) -> Self;

pure fn dir_path() -> self;
pure fn file_path() -> self;
pure fn dir_path() -> Self;
pure fn file_path() -> Self;

pure fn push((&str)) -> self;
pure fn push_rel((&self)) -> self;
pure fn push_many((&[~str])) -> self;
pure fn pop() -> self;
pure fn push((&str)) -> Self;
pure fn push_rel((&Self)) -> Self;
pure fn push_many((&[~str])) -> Self;
pure fn pop() -> Self;

pure fn normalize() -> self;
pure fn normalize() -> Self;
}

#[cfg(windows)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub pure fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
pub trait Ptr<T> {
pure fn is_null() -> bool;
pure fn is_not_null() -> bool;
pure fn offset(count: uint) -> self;
pure fn offset(count: uint) -> Self;
}

#[cfg(stage0)]
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2119,9 +2119,9 @@ pub mod raw {
}

pub trait Trimmable {
pure fn trim() -> self;
pure fn trim_left() -> self;
pure fn trim_right() -> self;
pure fn trim() -> Self;
pure fn trim_left() -> Self;
pure fn trim_right() -> Self;
}

/// Extension methods for strings
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum extended_decode_ctxt {
}

trait tr {
fn tr(xcx: extended_decode_ctxt) -> self;
fn tr(xcx: extended_decode_ctxt) -> Self;
}

trait tr_intern {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3581,8 +3581,6 @@ pub impl Resolver {
// Create a new rib for the self type.
let self_type_rib = @Rib(NormalRibKind);
(*self.type_ribs).push(self_type_rib);
self_type_rib.bindings.insert(self.self_ident,
dl_def(def_self_ty(item.id)));
self_type_rib.bindings.insert(self.type_self_ident,
dl_def(def_self_ty(item.id)));

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/typeck/infer/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ use middle::typeck::infer::to_str::InferStr;
use std::list;

pub trait LatticeValue {
static fn sub(cf: &CombineFields, a: &self, b: &self) -> ures;
static fn lub(cf: &CombineFields, a: &self, b: &self) -> cres<self>;
static fn glb(cf: &CombineFields, a: &self, b: &self) -> cres<self>;
static fn sub(cf: &CombineFields, a: &Self, b: &Self) -> ures;
static fn lub(cf: &CombineFields, a: &Self, b: &Self) -> cres<Self>;
static fn glb(cf: &CombineFields, a: &Self, b: &Self) -> cres<Self>;
}

pub type LatticeOp<T> = &fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct Node<V, T> {

pub trait UnifyVid<T> {
static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt)
-> &v/ValsAndBindings<self, T>;
-> &v/ValsAndBindings<Self, T>;
}

pub impl InferCtxt {
Expand Down Expand Up @@ -136,7 +136,7 @@ pub impl InferCtxt {
// doesn't have a subtyping relationship we need to worry about.

pub trait SimplyUnifiable {
static fn to_type_err(expected_found<self>) -> ty::type_err;
static fn to_type_err(expected_found<Self>) -> ty::type_err;
}

pub fn mk_err<T: SimplyUnifiable>(+a_is_expected: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use core::float;
const fuzzy_epsilon: float = 1.0e-6;

pub trait FuzzyEq {
pure fn fuzzy_eq(&self, other: &self) -> bool;
pure fn fuzzy_eq_eps(&self, other: &self, epsilon: &self) -> bool;
pure fn fuzzy_eq(&self, other: &Self) -> bool;
pure fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Self) -> bool;
}

impl float: FuzzyEq {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ pub mod flatteners {
}

pub trait FromReader {
static fn from_reader(r: Reader) -> self;
static fn from_reader(r: Reader) -> Self;
}

pub trait FromWriter {
static fn from_writer(w: Writer) -> self;
static fn from_writer(w: Writer) -> Self;
}

impl json::Decoder: FromReader {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub trait Encodable<S: Encoder> {
}

pub trait Decodable<D: Decoder> {
static fn decode(&self, d: &D) -> self;
static fn decode(&self, d: &D) -> Self;
}

pub impl<S: Encoder> uint: Encodable<S> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use core::vec;
use std::serialize::{Encodable, Decodable, Encoder, Decoder};

pub trait Pos {
static pure fn from_uint(n: uint) -> self;
static pure fn from_uint(n: uint) -> Self;
pure fn to_uint(&self) -> uint;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/static-methods-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#[crate_type = "lib"];

pub trait read {
static fn readMaybe(s: ~str) -> Option<self>;
static fn readMaybe(s: ~str) -> Option<Self>;
}

impl int: read {
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/static_fn_inline_xc_aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

pub mod num {
pub trait Num2 {
static pure fn from_int2(n: int) -> self;
static pure fn from_int2(n: int) -> Self;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/static_fn_trait_xc_aux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod num {
pub trait Num2 {
static pure fn from_int2(n: int) -> self;
static pure fn from_int2(n: int) -> Self;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/trait_inheritance_overloading_xc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use cmp::Eq;

pub trait MyNum : Add<self,self> Sub<self,self> Mul<self,self> Eq {
pub trait MyNum : Add<Self,Self> Sub<Self,Self> Mul<Self,Self> Eq {
}

pub struct MyInt {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/infinite-instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// issue 2258

trait to_opt {
fn to_option() -> Option<self>;
fn to_option() -> Option<Self>;
}

impl uint: to_opt {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/missing-derivable-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

trait MyEq {
pure fn eq(&self, other: &self) -> bool;
pure fn eq(&self, other: &Self) -> bool;
}

struct A {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/selftype-astparam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

trait add {
fn plus(++x: self) -> self;
fn plus(++x: Self) -> Self;
}

impl int: add {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/selftype-traittype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

trait add {
fn plus(x: self) -> self;
fn plus(x: Self) -> Self;
}

fn do_add(x: add, y: add) -> add {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/trait-impl-different-num-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

trait foo {
fn bar(x: uint) -> self;
fn bar(x: uint) -> Self;
}
impl int: foo {
fn bar() -> int {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/trait-test-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

trait bar { fn dup() -> self; fn blah<X>(); }
trait bar { fn dup() -> Self; fn blah<X>(); }
impl int: bar { fn dup() -> int { self } fn blah<X>() {} }
impl uint: bar { fn dup() -> uint { self } fn blah<X>() {} }

Expand Down
Loading