1
Fork 0

librustc: Change self as a type to Self everywhere. r=brson

This commit is contained in:
Patrick Walton 2013-01-30 19:42:06 -08:00
parent 63b2b9c4a8
commit 366812a5c3
41 changed files with 87 additions and 90 deletions

View file

@ -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: following trait describes types that support an equality operation:
~~~~ ~~~~
// In a trait, `self` refers both to the self argument // In a trait, `self` refers to the self argument.
// and to the type implementing the trait // `Self` refers to the type implementing the trait.
trait Eq { 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 // In an impl, `self` refers just to the value of the receiver
@ -2015,7 +2015,7 @@ the method name with the trait name.
The compiler will use type inference to decide which implementation to call. 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::consts::pi;
# use float::sqrt; # use float::sqrt;
struct Circle { radius: float } struct Circle { radius: float }

View file

@ -12,7 +12,7 @@
Clonable types are copied with the clone method Clonable types are copied with the clone method
*/ */
pub trait Clone { pub trait Clone {
fn clone(&self) -> self; fn clone(&self) -> Self;
} }
impl (): Clone { impl (): Clone {

View file

@ -37,8 +37,8 @@ and `Eq` to overload the `==` and `!=` operators.
*/ */
#[lang="eq"] #[lang="eq"]
pub trait Eq { pub trait Eq {
pure fn eq(&self, other: &self) -> bool; pure fn eq(&self, other: &Self) -> bool;
pure fn ne(&self, other: &self) -> bool; pure fn ne(&self, other: &Self) -> bool;
} }
/** /**
@ -53,10 +53,10 @@ pub trait Eq {
*/ */
#[lang="ord"] #[lang="ord"]
pub trait Ord { pub trait Ord {
pure fn lt(&self, other: &self) -> bool; pure fn lt(&self, other: &Self) -> bool;
pure fn le(&self, other: &self) -> bool; pure fn le(&self, other: &Self) -> bool;
pure fn ge(&self, other: &self) -> bool; pure fn ge(&self, other: &Self) -> bool;
pure fn gt(&self, other: &self) -> bool; pure fn gt(&self, other: &Self) -> bool;
} }
#[inline(always)] #[inline(always)]

View file

@ -68,23 +68,23 @@ pub trait Set<T>: Mutable {
/// Return true if the set has no elements in common with `other`. /// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection. /// 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 /// 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 /// 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 /// 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 /// 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 /// 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 /// 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);
} }

View file

@ -17,6 +17,6 @@
use option::Option; use option::Option;
pub trait FromStr { pub trait FromStr {
static pure fn from_str(s: &str) -> Option<self>; static pure fn from_str(s: &str) -> Option<Self>;
} }

View file

@ -85,7 +85,7 @@ pub trait Buildable<A> {
* onto the sequence being constructed. * onto the sequence being constructed.
*/ */
static pure fn build_sized(size: uint, static pure fn build_sized(size: uint,
builder: fn(push: pure fn(A))) -> self; builder: fn(push: pure fn(A))) -> Self;
} }
#[inline(always)] #[inline(always)]

View file

@ -12,26 +12,26 @@
pub trait Num { pub trait Num {
// FIXME: Trait composition. (#2616) // FIXME: Trait composition. (#2616)
pure fn add(&self, other: &self) -> self; pure fn add(&self, other: &Self) -> Self;
pure fn sub(&self, other: &self) -> self; pure fn sub(&self, other: &Self) -> Self;
pure fn mul(&self, other: &self) -> self; pure fn mul(&self, other: &Self) -> Self;
pure fn div(&self, other: &self) -> self; pure fn div(&self, other: &Self) -> Self;
pure fn modulo(&self, other: &self) -> self; pure fn modulo(&self, other: &Self) -> Self;
pure fn neg(&self) -> self; pure fn neg(&self) -> Self;
pure fn to_int(&self) -> int; 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 { pub trait IntConvertible {
pure fn to_int(&self) -> int; 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 { pub trait Zero {
static pure fn zero() -> self; static pure fn zero() -> Self;
} }
pub trait One { pub trait One {
static pure fn one() -> self; static pure fn one() -> Self;
} }

View file

@ -48,28 +48,27 @@ pub pure fn PosixPath(s: &str) -> PosixPath {
} }
pub trait GenericPath { pub trait GenericPath {
static pure fn from_str(&str) -> Self;
static pure fn from_str(&str) -> self;
pure fn dirname() -> ~str; pure fn dirname() -> ~str;
pure fn filename() -> Option<~str>; pure fn filename() -> Option<~str>;
pure fn filestem() -> Option<~str>; pure fn filestem() -> Option<~str>;
pure fn filetype() -> Option<~str>; pure fn filetype() -> Option<~str>;
pure fn with_dirname((&str)) -> self; pure fn with_dirname((&str)) -> Self;
pure fn with_filename((&str)) -> self; pure fn with_filename((&str)) -> Self;
pure fn with_filestem((&str)) -> self; pure fn with_filestem((&str)) -> Self;
pure fn with_filetype((&str)) -> self; pure fn with_filetype((&str)) -> Self;
pure fn dir_path() -> self; pure fn dir_path() -> Self;
pure fn file_path() -> self; pure fn file_path() -> Self;
pure fn push((&str)) -> self; pure fn push((&str)) -> Self;
pure fn push_rel((&self)) -> self; pure fn push_rel((&Self)) -> Self;
pure fn push_many((&[~str])) -> self; pure fn push_many((&[~str])) -> Self;
pure fn pop() -> self; pure fn pop() -> Self;
pure fn normalize() -> self; pure fn normalize() -> Self;
} }
#[cfg(windows)] #[cfg(windows)]

View file

@ -187,7 +187,7 @@ pub pure fn ref_eq<T>(thing: &a/T, other: &b/T) -> bool {
pub trait Ptr<T> { pub trait Ptr<T> {
pure fn is_null() -> bool; pure fn is_null() -> bool;
pure fn is_not_null() -> bool; pure fn is_not_null() -> bool;
pure fn offset(count: uint) -> self; pure fn offset(count: uint) -> Self;
} }
#[cfg(stage0)] #[cfg(stage0)]

View file

@ -2119,9 +2119,9 @@ pub mod raw {
} }
pub trait Trimmable { pub trait Trimmable {
pure fn trim() -> self; pure fn trim() -> Self;
pure fn trim_left() -> self; pure fn trim_left() -> Self;
pure fn trim_right() -> self; pure fn trim_right() -> Self;
} }
/// Extension methods for strings /// Extension methods for strings

View file

@ -77,7 +77,7 @@ enum extended_decode_ctxt {
} }
trait tr { trait tr {
fn tr(xcx: extended_decode_ctxt) -> self; fn tr(xcx: extended_decode_ctxt) -> Self;
} }
trait tr_intern { trait tr_intern {

View file

@ -3581,8 +3581,6 @@ pub impl Resolver {
// Create a new rib for the self type. // Create a new rib for the self type.
let self_type_rib = @Rib(NormalRibKind); let self_type_rib = @Rib(NormalRibKind);
(*self.type_ribs).push(self_type_rib); (*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, self_type_rib.bindings.insert(self.type_self_ident,
dl_def(def_self_ty(item.id))); dl_def(def_self_ty(item.id)));

View file

@ -50,9 +50,9 @@ use middle::typeck::infer::to_str::InferStr;
use std::list; use std::list;
pub trait LatticeValue { pub trait LatticeValue {
static fn sub(cf: &CombineFields, a: &self, b: &self) -> ures; static fn sub(cf: &CombineFields, a: &Self, b: &Self) -> ures;
static fn lub(cf: &CombineFields, a: &self, b: &self) -> cres<self>; static fn lub(cf: &CombineFields, a: &Self, b: &Self) -> cres<Self>;
static fn glb(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>; pub type LatticeOp<T> = &fn(cf: &CombineFields, a: &T, b: &T) -> cres<T>;

View file

@ -39,7 +39,7 @@ pub struct Node<V, T> {
pub trait UnifyVid<T> { pub trait UnifyVid<T> {
static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt) static fn appropriate_vals_and_bindings(infcx: &v/InferCtxt)
-> &v/ValsAndBindings<self, T>; -> &v/ValsAndBindings<Self, T>;
} }
pub impl InferCtxt { pub impl InferCtxt {
@ -136,7 +136,7 @@ pub impl InferCtxt {
// doesn't have a subtyping relationship we need to worry about. // doesn't have a subtyping relationship we need to worry about.
pub trait SimplyUnifiable { 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, pub fn mk_err<T: SimplyUnifiable>(+a_is_expected: bool,

View file

@ -18,8 +18,8 @@ use core::float;
const fuzzy_epsilon: float = 1.0e-6; const fuzzy_epsilon: float = 1.0e-6;
pub trait FuzzyEq { pub trait FuzzyEq {
pure fn fuzzy_eq(&self, other: &self) -> bool; pure fn fuzzy_eq(&self, other: &Self) -> bool;
pure fn fuzzy_eq_eps(&self, other: &self, epsilon: &self) -> bool; pure fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Self) -> bool;
} }
impl float: FuzzyEq { impl float: FuzzyEq {

View file

@ -467,11 +467,11 @@ pub mod flatteners {
} }
pub trait FromReader { pub trait FromReader {
static fn from_reader(r: Reader) -> self; static fn from_reader(r: Reader) -> Self;
} }
pub trait FromWriter { pub trait FromWriter {
static fn from_writer(w: Writer) -> self; static fn from_writer(w: Writer) -> Self;
} }
impl json::Decoder: FromReader { impl json::Decoder: FromReader {

View file

@ -111,7 +111,7 @@ pub trait Encodable<S: Encoder> {
} }
pub trait Decodable<D: Decoder> { 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> { pub impl<S: Encoder> uint: Encodable<S> {

View file

@ -34,7 +34,7 @@ use core::vec;
use std::serialize::{Encodable, Decodable, Encoder, Decoder}; use std::serialize::{Encodable, Decodable, Encoder, Decoder};
pub trait Pos { 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; pure fn to_uint(&self) -> uint;
} }

View file

@ -14,7 +14,7 @@
#[crate_type = "lib"]; #[crate_type = "lib"];
pub trait read { pub trait read {
static fn readMaybe(s: ~str) -> Option<self>; static fn readMaybe(s: ~str) -> Option<Self>;
} }
impl int: read { impl int: read {

View file

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

View file

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

View file

@ -10,7 +10,7 @@
use cmp::Eq; 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 { pub struct MyInt {

View file

@ -12,7 +12,7 @@
// issue 2258 // issue 2258
trait to_opt { trait to_opt {
fn to_option() -> Option<self>; fn to_option() -> Option<Self>;
} }
impl uint: to_opt { impl uint: to_opt {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait MyEq { trait MyEq {
pure fn eq(&self, other: &self) -> bool; pure fn eq(&self, other: &Self) -> bool;
} }
struct A { struct A {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait add { trait add {
fn plus(++x: self) -> self; fn plus(++x: Self) -> Self;
} }
impl int: add { impl int: add {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait add { trait add {
fn plus(x: self) -> self; fn plus(x: Self) -> Self;
} }
fn do_add(x: add, y: add) -> add { fn do_add(x: add, y: add) -> add {

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait foo { trait foo {
fn bar(x: uint) -> self; fn bar(x: uint) -> Self;
} }
impl int: foo { impl int: foo {
fn bar() -> int { fn bar() -> int {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 int: bar { fn dup() -> int { self } fn blah<X>() {} }
impl uint: bar { fn dup() -> uint { self } fn blah<X>() {} } impl uint: bar { fn dup() -> uint { self } fn blah<X>() {} }

View file

@ -13,7 +13,7 @@ trait Deserializer {
} }
trait Deserializable<D: Deserializer> { trait Deserializable<D: Deserializer> {
static fn deserialize(d: &D) -> self; static fn deserialize(d: &D) -> Self;
} }
impl<D: Deserializer> int: Deserializable<D> { impl<D: Deserializer> int: Deserializable<D> {

View file

@ -14,7 +14,7 @@
// A trait for objects that can be used to do an if-then-else // A trait for objects that can be used to do an if-then-else
// (No actual need for this to be static, but it is a simple test.) // (No actual need for this to be static, but it is a simple test.)
trait bool_like { trait bool_like {
static fn select<A>(b: self, +x1: A, +x2: A) -> A; static fn select<A>(b: Self, +x1: A, +x2: A) -> A;
} }
fn andand<T: bool_like Copy>(x1: T, x2: T) -> T { fn andand<T: bool_like Copy>(x1: T, x2: T) -> T {
@ -36,7 +36,7 @@ impl int: bool_like {
// A trait for sequences that can be constructed imperatively. // A trait for sequences that can be constructed imperatively.
trait buildable<A> { trait buildable<A> {
static pure fn build_sized(size: uint, static pure fn build_sized(size: uint,
builder: fn(push: pure fn(+v: A))) -> self; builder: fn(push: pure fn(+v: A))) -> Self;
} }

View file

@ -10,7 +10,7 @@
mod a { mod a {
pub trait Foo { pub trait Foo {
static pub fn foo() -> self; static pub fn foo() -> Self;
} }
impl int : Foo { impl int : Foo {

View file

@ -1,5 +1,5 @@
pub trait Number: NumConv { pub trait Number: NumConv {
static pure fn from<T:Number>(n: T) -> self; static pure fn from<T:Number>(n: T) -> Self;
} }
pub impl float: Number { pub impl float: Number {

View file

@ -15,8 +15,8 @@
use Num::from_int; use Num::from_int;
trait Num { trait Num {
static fn from_int(i: int) -> self; static fn from_int(i: int) -> Self;
fn gt(&self, other: &self) -> bool; fn gt(&self, other: &Self) -> bool;
} }
pub trait NumExt: Num { } pub trait NumExt: Num { }

View file

@ -10,7 +10,7 @@
use cmp::Eq; use cmp::Eq;
trait MyNum : Add<self,self> Sub<self,self> Mul<self,self> Eq { } trait MyNum : Add<Self,Self> Sub<Self,Self> Mul<Self,Self> Eq { }
struct MyInt { val: int } struct MyInt { val: int }

View file

@ -2,7 +2,7 @@ trait Foo<T> {
fn f(&self, x: &T); fn f(&self, x: &T);
} }
trait Bar : Foo<self> { trait Bar : Foo<Self> {
fn g(&self); fn g(&self);
} }

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait MyNum { trait MyNum {
static fn from_int(int) -> self; static fn from_int(int) -> Self;
} }
pub trait NumExt: MyNum { } pub trait NumExt: MyNum { }

View file

@ -11,7 +11,7 @@
trait MyEq { } trait MyEq { }
trait MyNum { trait MyNum {
static fn from_int(int) -> self; static fn from_int(int) -> Self;
} }
pub trait NumExt: MyEq MyNum { } pub trait NumExt: MyEq MyNum { }

View file

@ -12,7 +12,7 @@ pub trait Add<RHS,Result> {
pure fn add(rhs: &RHS) -> Result; pure fn add(rhs: &RHS) -> Result;
} }
trait MyNum : Add<self,self> { } trait MyNum : Add<Self,Self> { }
struct MyInt { val: int } struct MyInt { val: int }

View file

@ -16,7 +16,7 @@ trait Add<RHS,Result>: Panda<RHS> {
fn add(rhs: &RHS) -> Result; fn add(rhs: &RHS) -> Result;
} }
trait MyNum : Add<self,self> { } trait MyNum : Add<Self,Self> { }
struct MyInt { val: int } struct MyInt { val: int }

View file

@ -12,7 +12,7 @@
// methods! // methods!
trait Equal { trait Equal {
static fn isEq(a: self, b: self) -> bool; static fn isEq(a: Self, b: Self) -> bool;
} }
enum Color { cyan, magenta, yellow, black } enum Color { cyan, magenta, yellow, black }

View file

@ -11,7 +11,7 @@
// Example from lkuper's intern talk, August 2012. // Example from lkuper's intern talk, August 2012.
trait Equal { trait Equal {
fn isEq(a: self) -> bool; fn isEq(a: Self) -> bool;
} }
enum Color { cyan, magenta, yellow, black } enum Color { cyan, magenta, yellow, black }