librustc: Stop parsing impl Type : Trait and fix several declarations that slipped through. r=tjc

This commit is contained in:
Patrick Walton 2013-02-14 21:17:26 -08:00
parent 566bcf2225
commit bb833ca0f0
82 changed files with 327 additions and 424 deletions

View file

@ -17,7 +17,7 @@ pub mod kitty {
name : ~str,
}
pub impl cat : ToStr {
pub impl ToStr for cat {
pure fn to_str(&self) -> ~str { copy self.name }
}

View file

@ -19,7 +19,7 @@ pub mod name_pool {
fn add(s: ~str);
}
pub impl name_pool: add {
pub impl add for name_pool {
fn add(s: ~str) {
}
}
@ -34,7 +34,7 @@ pub mod rust {
fn cx();
}
pub impl rt: cx {
pub impl cx for rt {
fn cx() {
}
}

View file

@ -16,7 +16,7 @@ pub mod socket {
sockfd: libc::c_int,
}
pub impl socket_handle : Drop {
pub impl Drop for socket_handle {
fn finalize(&self) {
/* c::close(self.sockfd); */
}

View file

@ -15,7 +15,7 @@ pub struct rsrc {
x: i32,
}
pub impl rsrc : Drop {
pub impl Drop for rsrc {
fn finalize(&self) {
foo(self.x);
}

View file

@ -17,25 +17,25 @@ pub struct MyInt {
val: int
}
pub impl MyInt : Add<MyInt, MyInt> {
pub impl Add<MyInt, MyInt> for MyInt {
pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
}
pub impl MyInt : Sub<MyInt, MyInt> {
pub impl Sub<MyInt, MyInt> for MyInt {
pure fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) }
}
pub impl MyInt : Mul<MyInt, MyInt> {
pub impl Mul<MyInt, MyInt> for MyInt {
pure fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) }
}
pub impl MyInt : Eq {
pub impl Eq for MyInt {
pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
}
pub impl MyInt : MyNum;
pub impl MyNum for MyInt;
pure fn mi(v: int) -> MyInt { MyInt { val: v } }

View file

@ -19,7 +19,7 @@ trait Hahaha: Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq Eq //~ ERROR Duplicat
enum Lol = int;
pub impl Lol: Hahaha { }
pub impl Hahaha for Lol { }
impl Eq for Lol {
pure fn eq(&self, other: &Lol) -> bool { **self != **other }

View file

@ -16,7 +16,7 @@ trait BikeMethods {
fn woops(&const self) -> ~str;
}
pub impl Bike : BikeMethods {
pub impl BikeMethods for Bike {
static fn woops(&const self) -> ~str { ~"foo" }
//~^ ERROR method `woops` is declared as static in its impl, but not in its trait
}

View file

@ -20,7 +20,7 @@ impl MyEq for int {
pure fn eq(&self, other: &int) -> bool { *self == *other }
}
impl A : MyEq; //~ ERROR missing method
impl MyEq for A; //~ ERROR missing method
fn main() {
}

View file

@ -20,6 +20,7 @@ pub mod pipes {
mut payload: Option<T>
}
#[deriving_eq]
pub enum state {
empty,
full,
@ -27,13 +28,6 @@ pub mod pipes {
terminated
}
pub impl state : cmp::Eq {
pure fn eq(&self, other: &state) -> bool {
((*self) as uint) == ((*other) as uint)
}
pure fn ne(&self, other: &state) -> bool { !(*self).eq(other) }
}
pub type packet<T> = {
mut state: state,
mut blocked_task: Option<task::Task>,
@ -161,7 +155,7 @@ pub mod pipes {
mut p: Option<*packet<T>>,
}
pub impl<T: Owned> send_packet<T> : Drop {
pub impl<T: Owned> Drop for send_packet<T> {
fn finalize(&self) {
if self.p != None {
let mut p = None;
@ -189,7 +183,7 @@ pub mod pipes {
mut p: Option<*packet<T>>,
}
pub impl<T: Owned> recv_packet<T> : Drop {
pub impl<T: Owned> Drop for recv_packet<T> {
fn finalize(&self) {
if self.p != None {
let mut p = None;

View file

@ -23,8 +23,7 @@ extern mod std;
use io::WriterUtil;
// Represents a position on a canvas.
struct Point
{
struct Point {
x: int,
y: int,
}
@ -108,8 +107,7 @@ impl AsciiArt
// Allows AsciiArt to be converted to a string using the libcore ToStr trait.
// Note that the %s fmt! specifier will not call this automatically.
impl AsciiArt : ToStr
{
impl ToStr for AsciiArt {
pure fn to_str(&self) -> ~str
{
// Convert each line into a string.
@ -139,8 +137,7 @@ trait Canvas
// Here we provide an implementation of the Canvas methods for AsciiArt.
// Other implementations could also be provided (e.g. for PDF or Apple's Quartz)
// and code can use them polymorphically via the Canvas trait.
impl AsciiArt : Canvas
{
impl Canvas for AsciiArt {
fn add_point(&mut self, shape: Point)
{
self.add_pt(shape.x, shape.y);

View file

@ -31,7 +31,7 @@ impl Positioned for Point {
}
}
impl Point: Movable;
impl Movable for Point;
pub fn main() {
let p = Point{ x: 1, y: 2};

View file

@ -81,7 +81,7 @@ pub struct Buffer {
}
pub impl Buffer : Drop {
pub impl Drop for Buffer {
fn finalize(&self) {}
}

View file

@ -17,12 +17,12 @@ pub trait plus {
mod a {
use plus;
pub impl uint: plus { fn plus() -> int { self as int + 20 } }
pub impl plus for uint { fn plus() -> int { self as int + 20 } }
}
mod b {
use plus;
pub impl ~str: plus { fn plus() -> int { 200 } }
pub impl plus for ~str { fn plus() -> int { 200 } }
}
trait uint_utils {

View file

@ -2,7 +2,7 @@ pub trait Number: NumConv {
static pure fn from<T:Number>(n: T) -> Self;
}
pub impl float: Number {
pub impl Number for float {
static pure fn from<T:Number>(n: T) -> float { n.to_float() }
}
@ -10,7 +10,7 @@ pub trait NumConv {
pure fn to_float(&self) -> float;
}
pub impl float: NumConv {
pub impl NumConv for float {
pure fn to_float(&self) -> float { *self }
}

View file

@ -21,84 +21,84 @@ use std::cmp::FuzzyEq;
pub trait TypeExt {}
pub impl u8: TypeExt {}
pub impl u16: TypeExt {}
pub impl u32: TypeExt {}
pub impl u64: TypeExt {}
pub impl uint: TypeExt {}
pub impl TypeExt for u8 {}
pub impl TypeExt for u16 {}
pub impl TypeExt for u32 {}
pub impl TypeExt for u64 {}
pub impl TypeExt for uint {}
pub impl i8: TypeExt {}
pub impl i16: TypeExt {}
pub impl i32: TypeExt {}
pub impl i64: TypeExt {}
pub impl int: TypeExt {}
pub impl TypeExt for i8 {}
pub impl TypeExt for i16 {}
pub impl TypeExt for i32 {}
pub impl TypeExt for i64 {}
pub impl TypeExt for int {}
pub impl f32: TypeExt {}
pub impl f64: TypeExt {}
pub impl float: TypeExt {}
pub impl TypeExt for f32 {}
pub impl TypeExt for f64 {}
pub impl TypeExt for float {}
pub trait NumExt: TypeExt Eq Ord NumCast {}
pub impl u8: NumExt {}
pub impl u16: NumExt {}
pub impl u32: NumExt {}
pub impl u64: NumExt {}
pub impl uint: NumExt {}
pub impl NumExt for u8 {}
pub impl NumExt for u16 {}
pub impl NumExt for u32 {}
pub impl NumExt for u64 {}
pub impl NumExt for uint {}
pub impl i8: NumExt {}
pub impl i16: NumExt {}
pub impl i32: NumExt {}
pub impl i64: NumExt {}
pub impl int: NumExt {}
pub impl NumExt for i8 {}
pub impl NumExt for i16 {}
pub impl NumExt for i32 {}
pub impl NumExt for i64 {}
pub impl NumExt for int {}
pub impl f32: NumExt {}
pub impl f64: NumExt {}
pub impl float: NumExt {}
pub impl NumExt for f32 {}
pub impl NumExt for f64 {}
pub impl NumExt for float {}
pub trait UnSignedExt: NumExt {}
pub impl u8: UnSignedExt {}
pub impl u16: UnSignedExt {}
pub impl u32: UnSignedExt {}
pub impl u64: UnSignedExt {}
pub impl uint: UnSignedExt {}
pub impl UnSignedExt for u8 {}
pub impl UnSignedExt for u16 {}
pub impl UnSignedExt for u32 {}
pub impl UnSignedExt for u64 {}
pub impl UnSignedExt for uint {}
pub trait SignedExt: NumExt {}
pub impl i8: SignedExt {}
pub impl i16: SignedExt {}
pub impl i32: SignedExt {}
pub impl i64: SignedExt {}
pub impl int: SignedExt {}
pub impl SignedExt for i8 {}
pub impl SignedExt for i16 {}
pub impl SignedExt for i32 {}
pub impl SignedExt for i64 {}
pub impl SignedExt for int {}
pub impl f32: SignedExt {}
pub impl f64: SignedExt {}
pub impl float: SignedExt {}
pub impl SignedExt for f32 {}
pub impl SignedExt for f64 {}
pub impl SignedExt for float {}
pub trait IntegerExt: NumExt {}
pub impl u8: IntegerExt {}
pub impl u16: IntegerExt {}
pub impl u32: IntegerExt {}
pub impl u64: IntegerExt {}
pub impl uint: IntegerExt {}
pub impl IntegerExt for u8 {}
pub impl IntegerExt for u16 {}
pub impl IntegerExt for u32 {}
pub impl IntegerExt for u64 {}
pub impl IntegerExt for uint {}
pub impl i8: IntegerExt {}
pub impl i16: IntegerExt {}
pub impl i32: IntegerExt {}
pub impl i64: IntegerExt {}
pub impl int: IntegerExt {}
pub impl IntegerExt for i8 {}
pub impl IntegerExt for i16 {}
pub impl IntegerExt for i32 {}
pub impl IntegerExt for i64 {}
pub impl IntegerExt for int {}
pub trait FloatExt: NumExt FuzzyEq<Self> {}
pub impl f32: FloatExt {}
pub impl f64: FloatExt {}
pub impl float: FloatExt {}
pub impl FloatExt for f32 {}
pub impl FloatExt for f64 {}
pub impl FloatExt for float {}
fn test_float_ext<T:FloatExt>(n: T) { io::println(fmt!("%?", n < n)) }

View file

@ -13,7 +13,7 @@ use num::NumCast::from;
pub trait NumExt: Eq Ord NumCast {}
pub impl f32: NumExt {}
pub impl NumExt for f32 {}
fn num_eq_one<T:NumExt>(n: T) { io::println(fmt!("%?", n == from(1))) }

View file

@ -13,8 +13,8 @@ use num::NumCast::from;
pub trait NumExt: Eq NumCast {}
pub impl f32: NumExt {}
pub impl int: NumExt {}
pub impl NumExt for f32 {}
pub impl NumExt for int {}
fn num_eq_one<T:NumExt>() -> T {
from(1)

View file

@ -19,7 +19,7 @@ impl Eq for MyInt {
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
}
impl MyInt : MyNum;
impl MyNum for MyInt;
fn f<T:MyNum>(x: T, y: T) -> bool {
return x == y;

View file

@ -31,7 +31,7 @@ impl Eq for MyInt {
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
}
impl MyInt : MyNum;
impl MyNum for MyInt;
fn f<T:Copy MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y);

View file

@ -20,7 +20,7 @@ impl Add<MyInt, MyInt> for MyInt {
pure fn add(other: &MyInt) -> MyInt { mi(self.val + other.val) }
}
impl MyInt : MyNum;
impl MyNum for MyInt;
fn f<T:MyNum>(x: T, y: T) -> T {
return x.add(&y);

View file

@ -30,7 +30,7 @@ impl Add<MyInt, MyInt> for MyInt {
fn add(other: &MyInt) -> MyInt { self.chomp(other) }
}
impl MyInt : MyNum;
impl MyNum for MyInt;
fn f<T:MyNum>(x: T, y: T) -> T {
return x.add(&y).chomp(&y);

View file

@ -19,7 +19,7 @@ struct A { x: int }
impl Foo for A { fn f() -> int { 10 } }
impl Bar for A { fn g() -> int { 20 } }
impl Baz for A { fn h() -> int { 30 } }
impl A : Quux;
impl Quux for A;
fn f<T: Quux Foo Bar Baz>(a: &T) {
assert a.f() == 10;

View file

@ -19,7 +19,7 @@ mod base {
dummy: (),
}
pub impl Foo : ::base::HasNew<Foo> {
pub impl ::base::HasNew<Foo> for Foo {
static pure fn new() -> Foo {
unsafe { io::println("Foo"); }
Foo { dummy: () }
@ -30,7 +30,7 @@ mod base {
dummy: (),
}
pub impl Bar : ::base::HasNew<Bar> {
pub impl ::base::HasNew<Bar> for Bar {
static pure fn new() -> Bar {
unsafe { io::println("Bar"); }
Bar { dummy: () }