redundant-imports lint does not work in macro-defined modules
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Similar to https://github.com/rust-lang/rust/issues/158371, I found that the redundant_imports lint does not work in modules that are defined in any macros. This is especially relevant since this also affects cfg_if! and cfg_select! which are often used to define modules (e.g., https://github.com/rust-lang/rust/pull/158252).
Interestingly, other lints seem to work just fine, so this seems specific to the work that redundant_imports needs to do to analyze imports.
Reproduction
lib.rs:
#![deny(redundant_imports)]
#[cfg(true)]
pub mod foo; // works
macro_rules! identity {
($($tt:tt)*) => {
$($tt)*
};
}
identity! {
// pub mod foo; // does not work
}
cfg_if::cfg_if! {
if #[cfg(true)] {
// pub mod foo; //does not work
}
}
cfg_select! {
_ => {
// pub mod foo; // does not work
}
}
foo.rs:
use std::option::Option::None;
pub fn foo() -> Option<i32> { None }
Command:
cargo check
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the lib.rs and foo.rs reproduction and run cargo check to confirm the redundant_imports behavior in a normal module versus macro-defined modules. Trace the redundant_imports lint handling for macro-expanded modules; done means the lint reports the redundant import consistently in the identity!, cfg_if!, and cfg_select! cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100