Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected "failed to find an implementation of trait" when combining mut self and impl for T where T is a type variable #6594

Closed
Dretch opened this issue May 18, 2013 · 1 comment

Comments

@Dretch
Copy link
Contributor

Dretch commented May 18, 2013

This code doesn't compile:

struct Foo { x: int }

impl io::Reader for Foo {
    fn read(&self, _bytes: &mut [u8], _len: uint) -> uint { fail!() }
    fn read_byte(&self) -> int { fail!() }
    fn eof(&self) -> bool { fail!() }
    fn seek(&self, _position: int, _style: io::SeekStyle) { fail!() }
    fn tell(&self) -> uint { fail!() }
}

impl Foo {
    fn bar(&mut self) {
        self.read_be_u32(); // read_be_u32 is defined by io::ReaderUtil, which is defined for all <T: io::Reader>
    }
}

fn main() {}

rustc fails with this error:

test-impl-for-t.rs:15:12: 15:31 error: failed to find an implementation of trait core::io::Reader for &mut Foo
test-impl-for-t.rs:15             self.read_be_u32();
                                   ^~~~~~~~~~~~~~~~~~~

I don't think that rustc should have a problem with this code.

Note that this error seems to be related to &mut pointers and immutable borrows, because if the bar function is changed to the following then rustc is happy:

let iself: &Foo = self;
iself.read_be_u32();
@emberian
Copy link
Member

Closing as WONTFIX, due to #5087

flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 11, 2022
More proc-macro detection

fixes rust-lang#6514
fixes rust-lang#8683
fixes rust-lang#6858
fixes rust-lang#6594

This is a more general way of checking if an expression comes from a macro and could be trivially applied to other lints. Ideally this would be fixed in rustc's proc-macro api, but I don't see that happening any time soon.

changelog: FPs: [`unit_arg`] [`default_trait_access`] [`missing_docs_in_private_items`]: No longer trigger in code generated from proc-macros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants