Need to turn off unused imports warning, but on module level only

Hi everyone,

In my lib.rs I have this lines:

pub mod chat {
    pub use crate::primary::client::chat::types::{Language, MessageType, TextEmoteType, EmoteType};
}

and I get a warning on compile:

warning: unused imports: `EmoteType`, `Language`, `MessageType`, `TextEmoteType`
  --> src/primary/client/mod.rs:24:23
   |
24 | pub use chat::types::{Language, MessageType, EmoteType, TextEmoteType};
   |                       ^^^^^^^^  ^^^^^^^^^^^  ^^^^^^^^^  ^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

I want to avoid #![allow(unused_imports)] on crate level. I tried also to apply #[allow(dead_code)] to all module chat or to this line inside: pub use crate::primary::client::chat::types::{Language, MessageType, TextEmoteType, EmoteType};, but this not helped.

All imported items looks like this:

#[non_exhaustive]
pub struct Language;

#[allow(dead_code)]
impl Language {
    pub const UNIVERSAL: u32 = 0;
    // ...
}

Could somebody explain, if it possible to turn off the warnings on the chat module level only ?

Using an inner attribute should allow unused imports only in your chat module:

pub mod chat {
    #![allow(unused_imports)]

    pub use crate::primary::client::chat::types::{Language, MessageType, TextEmoteType, EmoteType};
}

but if you only have one use statement an outer attribute on that should also work:

pub mod chat {
    #[allow(unused_imports)]
    pub use crate::primary::client::chat::types::{Language, MessageType, TextEmoteType, EmoteType};
}
2 Likes

This is weird, but both cases not works for me. I still get the warning. Probably I do smth wrong ?

Oh, I applied that to wrong line. Now works ! Thank you

1 Like