mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-26 13:54:06 +00:00
librustc: Change self
as a type to Self
everywhere. r=brson
This commit is contained in:
parent
63b2b9c4a8
commit
366812a5c3
@ -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 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
|
||||
@ -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 }
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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)]
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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>;
|
||||
}
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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)));
|
||||
|
||||
|
@ -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>;
|
||||
|
@ -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 {
|
||||
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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> {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -12,7 +12,7 @@
|
||||
// issue 2258
|
||||
|
||||
trait to_opt {
|
||||
fn to_option() -> Option<self>;
|
||||
fn to_option() -> Option<Self>;
|
||||
}
|
||||
|
||||
impl uint: to_opt {
|
||||
|
@ -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 {
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
trait add {
|
||||
fn plus(++x: self) -> self;
|
||||
fn plus(++x: Self) -> Self;
|
||||
}
|
||||
|
||||
impl int: add {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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>() {} }
|
||||
|
||||
|
@ -13,7 +13,7 @@ trait Deserializer {
|
||||
}
|
||||
|
||||
trait Deserializable<D: Deserializer> {
|
||||
static fn deserialize(d: &D) -> self;
|
||||
static fn deserialize(d: &D) -> Self;
|
||||
}
|
||||
|
||||
impl<D: Deserializer> int: Deserializable<D> {
|
||||
@ -32,4 +32,4 @@ fn main() {
|
||||
let d = FromThinAir { dummy: () };
|
||||
let i: int = Deserializable::deserialize(&d);
|
||||
assert i == 22;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
// 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.)
|
||||
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 {
|
||||
@ -36,7 +36,7 @@ impl int: bool_like {
|
||||
// A trait for sequences that can be constructed imperatively.
|
||||
trait buildable<A> {
|
||||
static pure fn build_sized(size: uint,
|
||||
builder: fn(push: pure fn(+v: A))) -> self;
|
||||
builder: fn(push: pure fn(+v: A))) -> Self;
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
mod a {
|
||||
pub trait Foo {
|
||||
static pub fn foo() -> self;
|
||||
static pub fn foo() -> Self;
|
||||
}
|
||||
|
||||
impl int : Foo {
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 {
|
||||
@ -16,4 +16,4 @@ pub impl float: NumConv {
|
||||
|
||||
fn main() {
|
||||
let _: float = Number::from(0.0f);
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,8 @@
|
||||
use Num::from_int;
|
||||
|
||||
trait Num {
|
||||
static fn from_int(i: int) -> self;
|
||||
fn gt(&self, other: &self) -> bool;
|
||||
static fn from_int(i: int) -> Self;
|
||||
fn gt(&self, other: &Self) -> bool;
|
||||
}
|
||||
|
||||
pub trait NumExt: Num { }
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
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 }
|
||||
|
||||
|
@ -2,7 +2,7 @@ trait Foo<T> {
|
||||
fn f(&self, x: &T);
|
||||
}
|
||||
|
||||
trait Bar : Foo<self> {
|
||||
trait Bar : Foo<Self> {
|
||||
fn g(&self);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
trait MyNum {
|
||||
static fn from_int(int) -> self;
|
||||
static fn from_int(int) -> Self;
|
||||
}
|
||||
|
||||
pub trait NumExt: MyNum { }
|
||||
|
@ -11,7 +11,7 @@
|
||||
trait MyEq { }
|
||||
|
||||
trait MyNum {
|
||||
static fn from_int(int) -> self;
|
||||
static fn from_int(int) -> Self;
|
||||
}
|
||||
|
||||
pub trait NumExt: MyEq MyNum { }
|
||||
|
@ -12,7 +12,7 @@ pub trait Add<RHS,Result> {
|
||||
pure fn add(rhs: &RHS) -> Result;
|
||||
}
|
||||
|
||||
trait MyNum : Add<self,self> { }
|
||||
trait MyNum : Add<Self,Self> { }
|
||||
|
||||
struct MyInt { val: int }
|
||||
|
||||
|
@ -16,7 +16,7 @@ trait Add<RHS,Result>: Panda<RHS> {
|
||||
fn add(rhs: &RHS) -> Result;
|
||||
}
|
||||
|
||||
trait MyNum : Add<self,self> { }
|
||||
trait MyNum : Add<Self,Self> { }
|
||||
|
||||
struct MyInt { val: int }
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
// methods!
|
||||
|
||||
trait Equal {
|
||||
static fn isEq(a: self, b: self) -> bool;
|
||||
static fn isEq(a: Self, b: Self) -> bool;
|
||||
}
|
||||
|
||||
enum Color { cyan, magenta, yellow, black }
|
||||
@ -62,4 +62,4 @@ fn main() {
|
||||
branch(@leaf(magenta), @leaf(magenta)));
|
||||
|
||||
log(error, "Assertions all succeeded!");
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
// Example from lkuper's intern talk, August 2012.
|
||||
|
||||
trait Equal {
|
||||
fn isEq(a: self) -> bool;
|
||||
fn isEq(a: Self) -> bool;
|
||||
}
|
||||
|
||||
enum Color { cyan, magenta, yellow, black }
|
||||
@ -61,4 +61,4 @@ fn main() {
|
||||
.isEq(branch(@leaf(magenta), @leaf(magenta)));
|
||||
|
||||
log(error, "Assertions all succeeded!");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user