Skip to content

Commit 387df4e

Browse files
committed
Fix the issue-3979 tests and add a new test.
1 parent ffc879c commit 387df4e

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

src/test/auxiliary/issue_3979_traits.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
#[crate_type = "lib"];
1515

1616
trait Positioned {
17-
fn SetX(&self, int);
17+
fn SetX(&mut self, int);
1818
fn X(&self) -> int;
1919
}
2020

2121
trait Movable: Positioned {
22-
fn translate(&self, dx: int) {
23-
self.SetX(self.X() + dx);
22+
fn translate(&mut self, dx: int) {
23+
let x = self.X() + dx;
24+
self.SetX(x);
2425
}
2526
}

src/test/run-pass/issue-3979-2.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
12-
1311
trait A {
1412
fn a_method(&self);
1513
}

src/test/run-pass/issue-3979-generics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test FIXME #5946
1211
trait Positioned<S> {
1312
fn SetX(&mut self, S);
1413
fn X(&self) -> S;
1514
}
1615

17-
trait Movable<S, T>: Positioned<T> {
18-
fn translate(&self, dx: T) {
19-
self.SetX(self.X() + dx);
16+
trait Movable<S: Add<S, S>>: Positioned<S> {
17+
fn translate(&mut self, dx: S) {
18+
let x = self.X() + dx;
19+
self.SetX(x);
2020
}
2121
}
2222

@@ -31,10 +31,10 @@ impl Positioned<int> for Point {
3131
}
3232
}
3333

34-
impl Movable<int, int> for Point;
34+
impl Movable<int> for Point;
3535

3636
pub fn main() {
37-
let p = Point{ x: 1, y: 2};
37+
let mut p = Point{ x: 1, y: 2};
3838
p.translate(3);
3939
assert_eq!(p.X(), 4);
4040
}

src/test/run-pass/issue-3979-xcrate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test // tjc: ???
11+
// xfail-fast
1212
// aux-build:issue_3979_traits.rs
1313
extern mod issue_3979_traits;
1414
use issue_3979_traits::*;

src/test/run-pass/issue-3979.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// xfail-test
2-
// Reason: ICE with explicit self
31

42
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
53
// file at the top-level directory of this distribution and at
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// There is some other borrowck bug, so we make the stuff not mut.
12+
13+
trait Positioned<S> {
14+
fn SetX(&mut self, S);
15+
fn X(&self) -> S;
16+
}
17+
18+
trait Movable<S: Add<S, S>>: Positioned<S> {
19+
fn translate(&mut self, dx: S) {
20+
let x = self.X() + dx;
21+
self.SetX(x);
22+
}
23+
}
24+
25+
struct Point<S> { x: S, y: S }
26+
27+
impl<S: Clone> Positioned<S> for Point<S> {
28+
fn SetX(&mut self, x: S) {
29+
self.x = x;
30+
}
31+
fn X(&self) -> S {
32+
self.x.clone()
33+
}
34+
}
35+
36+
impl<S: Clone + Add<S, S>> Movable<S> for Point<S>;
37+
38+
pub fn main() {
39+
let mut p = Point{ x: 1, y: 2};
40+
p.translate(3);
41+
assert_eq!(p.X(), 4);
42+
}

0 commit comments

Comments
 (0)