Change method res to try autoref more often. Fixes #3585.

This commit is contained in:
Niko Matsakis 2012-09-25 15:15:42 -07:00
parent a770d86201
commit 12a0401d84
3 changed files with 48 additions and 53 deletions

View file

@ -0,0 +1,20 @@
trait Foo {
fn foo(&self) -> ~str;
}
impl<T: Foo> @T: Foo {
fn foo(&self) -> ~str {
fmt!("@%s", (**self).foo())
}
}
impl uint: Foo {
fn foo(&self) -> ~str {
fmt!("%u", *self)
}
}
fn main() {
let x = @3u;
assert x.foo() == ~"@3";
}

View file

@ -0,0 +1,17 @@
trait VecPush<T> {
fn push(&mut self, +t: T);
}
impl<T> ~[T]: VecPush<T> {
fn push(&mut self, +t: T) {
vec::push(*self, t);
}
}
fn main() {
let mut x = ~[];
x.push(1);
x.push(2);
x.push(3);
assert x == ~[1, 2, 3];
}