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

False positive: methods called new usually return Self #1724

Closed
hagsteel opened this issue May 4, 2017 · 0 comments · Fixed by #6952
Closed

False positive: methods called new usually return Self #1724

hagsteel opened this issue May 4, 2017 · 0 comments · Fixed by #6952
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@hagsteel
Copy link

hagsteel commented May 4, 2017

Consider this (rather silly) code:


struct FooRead<T: Read> {
    inner: T
}

impl<T: Read> Read for FooRead<T> {
    fn read(&mut self, _: &mut [u8]) -> Result<usize, std::io::Error> {
        Ok(1)
    }
}

struct Foo<T: Read> {
    foo: T
}

impl<T: Read> Foo<T> {
    fn new(t: T) -> Foo<FooRead<T>> {
        Foo {
            foo: FooRead { inner: t }
        }
    }
}

If the new function is changed to this:

impl<T: Read> Foo<T> {
    fn new(t: T) -> Self {
        Self {
            foo: FooRead { inner: t }
        }
    }
}

It errors with error[E0308]: mismatched types

@hagsteel hagsteel changed the title False positive False positive: methods called new usually return Self May 4, 2017
@oli-obk oli-obk added the C-bug Category: Clippy is not doing the correct thing label Jan 22, 2019
@bors bors closed this as completed in 4a1825a Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants