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

use_self is triggered inside derived code #6818

Closed
imp opened this issue Mar 1, 2021 · 3 comments · Fixed by #6833
Closed

use_self is triggered inside derived code #6818

imp opened this issue Mar 1, 2021 · 3 comments · Fixed by #6833
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion

Comments

@imp
Copy link
Contributor

imp commented Mar 1, 2021

It looks like use_self is triggered inside derived macro-generated code. While derived macro authors may handle that on their part, it is still not feasible to expect that to happen overnight. Right now everyone wishing to use this lint inside their own code is affected.

Lint name: use_self

I tried this code:

#![deny(clippy::use_self)]

use serde::{Serialize, Deserialize};

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
struct Text {
    text: String,    
}

fn main() {
    let text = Text { text: String::from("bar") };
    println!("{:?}", text);
}

I expected to see this happen: clean cargo clippy run

Instead, this happened:

    Checking playground v0.0.1 (/playground)
error: unnecessary structure name repetition
 --> src/main.rs:6:8
  |
6 | struct Text {
  |        ^^^^ help: use the applicable keyword: `Self`
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(clippy::use_self)]
  |         ^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

Meta

  • cargo clippy -V: clippy 0.1.52 (e37a13c 2021-02-28)
  • rustc -Vv:

rustc 1.52.0-nightly (e37a13c 2021-02-28)
binary: rustc
commit-hash: e37a13c
commit-date: 2021-02-28
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

@imp imp added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 1, 2021
@Count-Count
Copy link

Is it possible that this is a regression? I haven't seen this before while getting proper warnings for this lint, but it popped up today for all my serde derives. Last I checked was some time ago though.

@imp
Copy link
Contributor Author

imp commented Mar 1, 2021

#3909 and #6179 might be related

@extrawurst
Copy link

extrawurst commented Mar 2, 2021

having the same issue in gitui where I am supposed to name my struct itself Self ^^

see https://github.com/extrawurst/gitui/blob/bd54b47d194934b5860ec762bc658349b151db3a/src/keys.rs#L19

error: unnecessary structure name repetition
  --> src/keys.rs:19:12
   |
19 | pub struct KeyConfig {
   |            ^^^^^^^^^ help: use the applicable keyword: `Self`
   |
note: the lint level is defined here
  --> src/main.rs:6:9
   |
6  | #![deny(clippy::nursery)]
   |         ^^^^^^^^^^^^^^^
   = note: `#[deny(clippy::use_self)]` implied by `#[deny(clippy::nursery)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self

and yeah this is definitely a regression. this did not happen before

@camsteffen camsteffen added the good-first-issue These issues are a good way to get started with Clippy label Mar 2, 2021
@phansch phansch added the T-macros Type: Issues with macros and macro expansion label Mar 2, 2021
@phansch phansch self-assigned this Mar 2, 2021
@bors bors closed this as completed in 6680710 Mar 4, 2021
@phansch phansch removed their assignment Mar 6, 2021
anthraxx added a commit to anthraxx/git-smash that referenced this issue Mar 10, 2021
anthraxx added a commit to anthraxx/git-smash that referenced this issue Mar 10, 2021
anthraxx added a commit to anthraxx/git-smash that referenced this issue Mar 10, 2021
anthraxx added a commit to anthraxx/git-smash that referenced this issue Mar 10, 2021
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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants