How to ignore `unused_imports`?

I have a code which should disable the lint warning unused_imports (which I also dont understand because the function is private in

async fn get_all_jobs(s: &State<AppState>) -> json::JsonResponse<Vec<JobBundle>> {
    info!(s.log, "Getting all jobs.");

    let result = vec![JobBundle::new("my-doc", "no-digest")];
    return json::success!(result);

but somehow when I compile it still shows up.

The same happens for some spurious renamed_and_removed_lints which I tried to disable.

What I am doing wrong? Compiling with the latest Rust toolchain, nigthly.

The unused_imports lint refers to imports in a module, it has nothing to do with a function.


It sounds like you're probably misinterpreting what the warnings mean, can you post both of them?

The warnings are:

warning: unused import: `get_all_jobs`
  --> components/api/src/service/
12 | async fn get_all_jobs(s: &State<AppState>) -> json::JsonResponse<Vec<JobBundle>> {
   |          ^^^^^^^^^^^^
   = note: `#[warn(unused_imports)]` on by default module is included in as mod handlers;. Both files are next to each other and get_all_jobs is private....??

I think these are just issues in the rocket::get macro in the release candidate version you're using (0.5.0-rc.3). Try updating to 0.5.0 and see if that fixes the issue. I managed to find this commit that adds some #[allow(unused)]s to related code in rocket: Qualm various emerging unused warnings. · rwf2/Rocket@48d1b82 · GitHub.

Macros sometimes cause strange compiler errors like this, in this case it appears that the macro is generating code that triggers the unused_imports lint, and the problem is then incorrectly mapped to the function definition for get_all_jobs since the code that triggers the issue doesn't actually exist in the source file, all the compiler has to blame is the function.

Unfortunately, I don't know if any work is currently being done to improve the situation...the error is definitely unclear and unhelpful here. Really the lint shouldn't fire at all since it's not your code that's the issue.

1 Like

Exactly that was the problem, the macro creates a public function, which I can unfortunately not stear from the invocation point.

1 Like

there isnt a scoped "ignore these lints" for rust with something like { ... }? only globally ignoring stuff with "#![allow(warn_unused)]", right? I mean locally applying this would not work as above noted.

Sure, it's #[allow(...)] { ... }.

It means the same thing as { #![allow(...)]; ... }.

Read more about inner and outer attributes.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.