Skip to content

Restrict use_self on nested items #3640

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

Merged
merged 4 commits into from
Jan 7, 2019
Merged

Conversation

detrumi
Copy link
Member

@detrumi detrumi commented Jan 6, 2019

Fixes #3637
Fixes #3463

These changes make it so that nested items aren't visited any more by the use_self lint.

I think visiting nested items should be possible (so that it uses a different item_path for the nested item), but I'm not sure whether it's viable and what the best approach would be.

  • Can item_path be changed to a new Self path before visiting the item, and then changing it back afterwards?
  • Alternatively, could a new visitor be created, re-using check_trait_method_impl_decl?

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

LGTM. Just another test would be nice, to make sure, to keep the (correct) old behavior with nested items.

@flip1995
Copy link
Member

flip1995 commented Jan 7, 2019

@bors r+ Thanks!

@phansch
Copy link
Member

phansch commented Jan 7, 2019

@bors r=flip1995

@bors
Copy link
Contributor

bors commented Jan 7, 2019

📌 Commit 466cd07 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jan 7, 2019

⌛ Testing commit 466cd07 with merge 5b84966...

bors added a commit that referenced this pull request Jan 7, 2019
Restrict `use_self` on nested items

Fixes #3637
Fixes #3463

These changes make it so that nested items aren't visited any more by the `use_self` lint.

I think visiting nested items should be possible (so that it uses a different `item_path` for the nested item), but I'm not sure whether it's viable and what the best approach would be.
- Can `item_path` be changed to a new `Self` path before visiting the item, and then changing it back afterwards?
- Alternatively, could a new visitor be created, re-using `check_trait_method_impl_decl`?
@bors
Copy link
Contributor

bors commented Jan 7, 2019

☀️ Test successful - status-appveyor, status-travis
Approved by: flip1995
Pushing 5b84966 to master...

@bors bors merged commit 466cd07 into rust-lang:master Jan 7, 2019
@detrumi detrumi deleted the nested_use_self branch January 8, 2019 16:45
bors added a commit that referenced this pull request Mar 12, 2019
Fix `use_self` false positive on nested functions

Related to #3640

The current `use_self` warns the following code.

```rust
#![warn(clippy::use_self)]
struct Foo {}
impl Foo {
    fn bar() {
        fn baz() -> Foo { //^ warning: unnecessary structure name repetition
            Foo {} //^ warning: unnecessary structure name repetition
         }
    }
}
```
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.

4 participants