Skip to content

Type-directed method resolution does not work through pointers #4270

Closed
@Dretch

Description

@Dretch

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions