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 with new_ret_no_self if new is an async fn that returns a wrapper around Self. #4359

Closed
lukas-code opened this issue Aug 8, 2019 · 0 comments · Fixed by #4365
Labels
C-bug Category: Clippy is not doing the correct thing T-async-await Type: Issues related to async/await

Comments

@lukas-code
Copy link
Member

This code

#![feature(async_await)]

struct S;

impl S {
    async fn new() -> Result<Self, ()> {
        Ok(S)
    }
}

causes the following warning

warning: methods called `new` usually return `Self`
 --> src/lib.rs:7:5
  |
7 | /     async fn new() -> Result<Self, ()> {
8 | |         Ok(S)
9 | |     }
  | |_____^
  |
  = note: `#[warn(clippy::new_ret_no_self)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self

cargo clippy -V

clippy 0.0.212 (b041511 2019-08-07)
@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing T-async-await Type: Issues related to async/await labels Aug 9, 2019
bors added a commit that referenced this issue Aug 11, 2019
new_ret_no_self: allow Self in inner type for impl Trait return types

Check the inner types of associated types of a trait when checking for Self in the return type of a `new` method. This means that the following will no longer warn:
```rust
trait Trait {
    type Inner;
}

struct S;

impl S {
    fn new() -> impl Trait<Inner = Option<Self>> {
        struct TraitImpl;

        impl Trait for TraitImpl {
            type Inner = Option<S>;
        }

        TraitImpl
    }
}
```
```rust
#![feature(async_await)]

struct Connection;

impl Connection {
    async fn new() -> Result<Self, ()> {
        Ok(S)
    }
}
```
closes #4359
bors added a commit that referenced this issue Aug 11, 2019
new_ret_no_self: allow Self in inner type for impl Trait return types

Check the inner types of associated types of a trait when checking for Self in the return type of a `new` method. This means that the following will no longer warn:
```rust
trait Trait {
    type Inner;
}

struct S;

impl S {
    fn new() -> impl Trait<Inner = Option<Self>> {
        struct TraitImpl;

        impl Trait for TraitImpl {
            type Inner = Option<S>;
        }

        TraitImpl
    }
}
```
```rust
#![feature(async_await)]

struct Connection;

impl Connection {
    async fn new() -> Result<Self, ()> {
        Ok(S)
    }
}
```
closes #4359

changelog: fix `new_ret_no_self` lint for async `new` functions.
bors added a commit that referenced this issue Aug 12, 2019
new_ret_no_self: allow Self in inner type for impl Trait return types

Check the inner types of associated types of a trait when checking for Self in the return type of a `new` method. This means that the following will no longer warn:
```rust
trait Trait {
    type Inner;
}

struct S;

impl S {
    fn new() -> impl Trait<Inner = Option<Self>> {
        struct TraitImpl;

        impl Trait for TraitImpl {
            type Inner = Option<S>;
        }

        TraitImpl
    }
}
```
```rust
#![feature(async_await)]

struct Connection;

impl Connection {
    async fn new() -> Result<Self, ()> {
        Ok(S)
    }
}
```
closes #4359

changelog: fix `new_ret_no_self` lint for async `new` functions.
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 T-async-await Type: Issues related to async/await
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants