Clippy lints / Suspicious
Clippy lint · Suspicious · checked with Clippy 0.1.99
clippy::duplicate_mod: file is loaded as a module multiple times: `main.rs`
What it meansChecks for files that are included as modules multiple times. It is in the suspicious group and warns by default.
What you see
warning: file is loaded as a module multiple times: `main.rs` --> main.rs:4:1 | 4 | mod a; | ^^^^^^ first loaded here 5 | mod b; | ^^^^^^ loaded again here | = help: replace all but one `mod` item with `use` items = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#duplicate_mod = note: `#[warn(clippy::duplicate_mod)]` on by default
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Loading a file as a module more than once causes it to be compiled multiple times, taking longer and putting duplicate content into the module tree.
Code that is most likely wrong or useless. Warns by default.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
// lib.rs
mod a;
mod b;
Write this instead
// a.rs
#[path = "./b.rs"]
mod b;
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::duplicate_mod)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
duplicate_mod = "allow"One run
cargo clippy -- -A clippy::duplicate-modThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for files that are included as modules multiple times.
Why is this bad?
Loading a file as a module more than once causes it to be compiled multiple times, taking longer and putting duplicate content into the module tree.
Example
// lib.rs
mod a;
mod b;
// a.rs
#[path = "./b.rs"]
mod b;
Use instead:
// lib.rs
mod a;
mod b;
// a.rs
use crate::b;
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- doc_nested_refdefslink reference defined in list item
- doc_suspicious_footnoteslooks like a footnote ref, but has no matching footnote
- drop_non_dropcall to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes
- duplicated_attributesduplicated attribute
- empty_docsempty doc comment
- empty_line_after_doc_commentsempty line after doc comment
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::doc_nested_refdefslink reference defined in list itemRead it next →Did this answer your question?