new_ret_no_self: allow Self in inner type for impl Trait return types by lukas-code · Pull Request #4365 · rust-lang/rust-clippy (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation16 Commits5 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

lukas-code

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:

trait Trait { type Inner; }

struct S;

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

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

    TraitImpl
}

}

#![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.

flip1995

struct AsyncNew;
impl AsyncNew {
fn new() -> impl Future<Output = Option> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just make this function async and use the async_await feature in this test?

Everything else LGTM.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the tests seem to use Rust 2015 (which does not have async fns) and I don't know how to change that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this again 😄

You have to add

// compile-flags: --edition 2018
#![feature(async_await)]

at the top of the test case. We should document this.

flip1995

@@ -23,10 +25,13 @@ use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::future::Future;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports are now unused.

Lukas Markeffsky added 3 commits

August 9, 2019 19:44

…ning for new_ret_no_self

@flip1995

@bors

📌 Commit d553158 has been approved by flip1995

@bors

bors added a commit that referenced this pull request

Aug 11, 2019

@bors

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:

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
    }
}
#![feature(async_await)]

struct Connection;

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

closes #4359

@bors

@flip1995

Forgot the changelog

@bors r+

@bors

💡 This pull request was already approved, no need to approve it again.

@bors

📌 Commit d553158 has been approved by flip1995

@bors

bors added a commit that referenced this pull request

Aug 11, 2019

@bors

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:

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
    }
}
#![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

bors added a commit that referenced this pull request

Aug 12, 2019

@bors

@phansch

@bors

bors added a commit that referenced this pull request

Aug 12, 2019

@bors

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:

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
    }
}
#![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