Fix the issue-3979 tests and add a new test.

This commit is contained in:
Michael Sullivan 2013-07-23 13:46:51 -07:00
parent ffc879c2e4
commit 387df4e127
6 changed files with 53 additions and 14 deletions

View File

@ -14,12 +14,13 @@
#[crate_type = "lib"];
trait Positioned {
fn SetX(&self, int);
fn SetX(&mut self, int);
fn X(&self) -> int;
}
trait Movable: Positioned {
fn translate(&self, dx: int) {
self.SetX(self.X() + dx);
fn translate(&mut self, dx: int) {
let x = self.X() + dx;
self.SetX(x);
}
}

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test
trait A {
fn a_method(&self);
}

View File

@ -8,15 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test FIXME #5946
trait Positioned<S> {
fn SetX(&mut self, S);
fn X(&self) -> S;
}
trait Movable<S, T>: Positioned<T> {
fn translate(&self, dx: T) {
self.SetX(self.X() + dx);
trait Movable<S: Add<S, S>>: Positioned<S> {
fn translate(&mut self, dx: S) {
let x = self.X() + dx;
self.SetX(x);
}
}
@ -31,10 +31,10 @@ impl Positioned<int> for Point {
}
}
impl Movable<int, int> for Point;
impl Movable<int> for Point;
pub fn main() {
let p = Point{ x: 1, y: 2};
let mut p = Point{ x: 1, y: 2};
p.translate(3);
assert_eq!(p.X(), 4);
}

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-test // tjc: ???
// xfail-fast
// aux-build:issue_3979_traits.rs
extern mod issue_3979_traits;
use issue_3979_traits::*;

View File

@ -1,5 +1,3 @@
// xfail-test
// Reason: ICE with explicit self
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at

View File

@ -0,0 +1,42 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// There is some other borrowck bug, so we make the stuff not mut.
trait Positioned<S> {
fn SetX(&mut self, S);
fn X(&self) -> S;
}
trait Movable<S: Add<S, S>>: Positioned<S> {
fn translate(&mut self, dx: S) {
let x = self.X() + dx;
self.SetX(x);
}
}
struct Point<S> { x: S, y: S }
impl<S: Clone> Positioned<S> for Point<S> {
fn SetX(&mut self, x: S) {
self.x = x;
}
fn X(&self) -> S {
self.x.clone()
}
}
impl<S: Clone + Add<S, S>> Movable<S> for Point<S>;
pub fn main() {
let mut p = Point{ x: 1, y: 2};
p.translate(3);
assert_eq!(p.X(), 4);
}