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 }})
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.
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.
@@ -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
…ning for new_ret_no_self
📌 Commit d553158 has been approved by flip1995
bors added a commit that referenced this pull request
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
Forgot the changelog
@bors r+
💡 This pull request was already approved, no need to approve it again.
- This pull request previously failed. You should add more commits to fix the bug, or use
retry
to trigger a build again. - There's another pull request that is currently being tested, blocking this pull request: Fixed repeated word #4370
📌 Commit d553158 has been approved by flip1995
bors added a commit that referenced this pull request
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 added a commit that referenced this pull request
bors added a commit that referenced this pull request
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.