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

Redundant Import Warning on Diesel Items #5154

Closed
rschristian opened this issue Feb 11, 2020 · 11 comments · Fixed by #5183
Closed

Redundant Import Warning on Diesel Items #5154

rschristian opened this issue Feb 11, 2020 · 11 comments · Fixed by #5183
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 T-macros Type: Issues with macros and macro expansion

Comments

@rschristian
Copy link

I'm currently running Clippy against a project I've made using Rocket and Diesel, and I'm getting redundant import warnings, specifically against items from Diesel.

warning: this import is redundant
  --> src/db/auth_repository.rs:10:10
   |
10 | #[derive(Insertable)]
   |          ^^^^^^^^^^
   |
   = note: `#[warn(clippy::single_component_path_imports)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports

warning: this import is redundant
 --> src/models/user.rs:7:10
  |
7 | #[derive(Queryable, Serialize)]
  |          ^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports

warning: this import is redundant
 --> src/schema.rs:1:1
  |
1 | / table! {
2 | |     users (id) {
3 | |         id -> Int4,
4 | |         first_name -> Text,
... |
8 | |     }
9 | | }
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
  = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

I could somehow be misunderstanding, but I'm not sure how a derived attribute could be a redundant import, nor how the schema could be. I stepped away from working on this project for a few months, so I'm not sure when this started, as I only updated all of my tools today.

As requested, Clippy version: clippy 0.0.212 (ea85b4c 2020-02-01)

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Feb 11, 2020
@flip1995
Copy link
Member

Needs a macro check. cc @xiongmao86

@xiongmao86
Copy link
Contributor

xiongmao86 commented Feb 12, 2020

Why did this happen? I am still working on the pr, I don't think it is merged. See #5141.

@flip1995
Copy link
Member

It's about this PR: #5058

@xiongmao86
Copy link
Contributor

Oh, sorry, I mixed it up. I’ll take a look.

@xiongmao86
Copy link
Contributor

xiongmao86 commented Feb 12, 2020

I think it probably needs a in_external_macro or from_expansion check. I took a look at diesel_derives/src/insertable.rs, but I didn't figure out where the redundant import is, and had no idea how to setup a suitable trait and derive code for test.

@flip1995
Copy link
Member

I'd allow this also in internal macros. So just utils::in_macro(item.span) at the beginning of the check_item function.

@xiongmao86
Copy link
Contributor

Thank you for the tip, @flip1995, do we have to add a test in this case?

@flip1995
Copy link
Member

Yeah, should be a pretty small test case though. just a macro definition and calling this macro:

macro_rules! m {
    () => {
        use ident;
    };
}

m!()

@xiongmao86
Copy link
Contributor

My laptop is broken. It would take me at least a couple of days to setup an new enviroment. So I won't reply immediately. If anyone is interesting in this, please take it.

@JohnTitor
Copy link
Member

@xiongmao86 Sorry for the steal! I'd like to include a fix for this to next clippy up since it's noisy in some environment.

@bors bors closed this as completed in ba246c8 Feb 17, 2020
@xiongmao86
Copy link
Contributor

@JohnTitor It is no problem, you are welcome to take it.

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 T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants