Closed
Description
@erickt stumbled across a negative interaction between the current auto-ref/auto-deref rules, explicit self, and implementations for @T
.
If you write code like this:
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";
}
You get an assertion failure. What happens is that auto-ref derefs the @uint
to uint
and then auto-refs that to &uint
. This is because the current rule is "auto-deref until you can't, then auto-ref". It would be easy enough to make it try auto-refing at each stage. Probably it should, this seems like an important use case. This is a fairly small change to middle/typeck/check/method.rs
.