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

new_ret_no_self false positives #3338

Merged
merged 5 commits into from
Oct 24, 2018

Conversation

JoshMcguigan
Copy link
Contributor

@JoshMcguigan JoshMcguigan commented Oct 19, 2018

WORK IN PROGRESS

I plan to fix all of the false positives in #3313 in this PR, but I wanted to open it now to start gathering feedback.

In this first commit, I've updated the lint to allow tuple return types as long as Self shows up at least once, in any position of the tuple. I believe this is the broadest possible interpretation of what should be allowed for tuple return types, but I would certainly be okay making the lint more strict.

fixes #3313


impl TupleReturnerOk {
// should not trigger lint
pub fn new() -> (Self, u32) { unimplemented!(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

((Self, u32), u32) Will also trigger the lint. I'm not sure at all how strict we should be. I mean it seems perfectly reasonable to allow (Option<Self>, u32) or at least Option<(Self, u32)>. This might get out of hand quickly.

If you want to cover a lot of cases, you can call walk on the return type (giving you an iterator) and iterate over everything.

That would still cause false positives for struct Foo(pub Bar); impl Bar { fn new() -> Foo { ... } } but we need to restrict ourselves somewhere I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the tip, that sounds like a much more manageable approach. I pushed the commit below just to capture my progress, but I'll go back and try rewriting this to use walk.

@JoshMcguigan
Copy link
Contributor Author

The suggestion to use walk cleaned this up significantly. But I still need to add some test cases to ensure walk covers all of our use cases.

@JoshMcguigan
Copy link
Contributor Author

JoshMcguigan commented Oct 20, 2018

I've added test cases which I believe cover all of the issues from #3313, and removed a clippy allow annotation within the clippy code base which should not be necessary anymore (we were returning Option<Self>.

Assuming we don't want to make the lint more strict I think this is good to go. Let me know if you see anything that can be improved.

@JoshMcguigan
Copy link
Contributor Author

Any thoughts on why the travis build failed? I can't make out the reason looking at the logs.

@flip1995
Copy link
Member

I restarted the job.

@flip1995
Copy link
Member

For completeness (#3338 (comment)) test cases for ((Self, u32), u32) and Option<(Self, u32)> would be nice. After that this should be ready to merge.

@JoshMcguigan
Copy link
Contributor Author

@flip1995 Thanks for the feedback. I've added those test cases. Let me know if you see any additional issues.

@flip1995
Copy link
Member

LGTM now!

bors r+

bors bot added a commit that referenced this pull request Oct 24, 2018
3338: new_ret_no_self false positives r=flip1995 a=JoshMcguigan

~~WORK IN PROGRESS~~

I plan to fix all of the false positives in #3313 in this PR, but I wanted to open it now to start gathering feedback.

In this first commit, I've updated the lint to allow tuple return types as long as `Self` shows up at least once, in any position of the tuple. I believe this is the broadest possible interpretation of what should be allowed for tuple return types, but I would certainly be okay making the lint more strict. 

fixes #3313 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
@flip1995
Copy link
Member

bors r-

@bors
Copy link
Contributor

bors bot commented Oct 24, 2018

Canceled

@flip1995
Copy link
Member

It seems that bors also needs a staging.tmp and a trying.tmp branch.

bors r+

bors bot added a commit that referenced this pull request Oct 24, 2018
3338: new_ret_no_self false positives r=flip1995 a=JoshMcguigan

~~WORK IN PROGRESS~~

I plan to fix all of the false positives in #3313 in this PR, but I wanted to open it now to start gathering feedback.

In this first commit, I've updated the lint to allow tuple return types as long as `Self` shows up at least once, in any position of the tuple. I believe this is the broadest possible interpretation of what should be allowed for tuple return types, but I would certainly be okay making the lint more strict. 

fixes #3313 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
@bors
Copy link
Contributor

bors bot commented Oct 24, 2018

@bors bors bot merged commit 30ffc17 into rust-lang:master Oct 24, 2018
tummychow added a commit to tummychow/git-absorb that referenced this pull request Dec 12, 2018
new_ret_no_self will still fail on the clippy packaged with rust 1.31.0.
there was a fix to recursively walk types so that Result<Self, E>
wouldn't fail, but that didn't make it into the stable release yet.

rust-lang/rust-clippy#3338
Emerentius added a commit to Emerentius/rust-clippy that referenced this pull request Apr 10, 2020
The lint was changed to be more lenient than the documentation implies in PR rust-lang#3338.
Related issue rust-lang#3313
bors added a commit that referenced this pull request Apr 13, 2020
Update documentation for new_ret_no_self

changelog: Update documentation for lint new_ret_no_self to reflect that the return type must only contain `Self`, not be `Self`

The lint was changed to be more lenient than the documentation implies in PR #3338 (Related issue #3313)
bors added a commit that referenced this pull request Apr 13, 2020
Update documentation for new_ret_no_self

changelog: Update documentation for lint new_ret_no_self to reflect that the return type must only contain `Self`, not be `Self`

The lint was changed to be more lenient than the documentation implies in PR #3338 (Related issue #3313)
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

Successfully merging this pull request may close these issues.

odd new_ret_no_self warning: return type that wraps Self
3 participants