Closed
Description
I think that the following code should work, but it does not compile:
use io::WriterUtil;
struct NotAWriter {x: int}
pub impl NotAWriter {
fn write_be_u32(y: u32) {}
}
fn main() {
let x = &(NotAWriter {x: 1});
x.write_be_u32(0);
}
The error from rustc is:
test-method-scope.rs:15:4: 15:22 error: failed to find an implementation of trait @core::io::Writer for <V2>
test-method-scope.rs:15 x.write_be_u32(0);
^~~~~~~~~~~~~~~~~~
I don't think there should be an error here. NotAWriter is not a Writer, it just shares a method name with WriterUtil (which is defined for all Writers).
If x is not a pointer then rustc works fine, i.e.:
let x = NotAWriter {x: 1};
x.write_be_u32(0);