Add `special_module_name` lint by ibraheemdev · Pull Request #94467 · rust-lang/...
source link: https://github.com/rust-lang/rust/pull/94467
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Declaring lib
as a module is one of the most common beginner mistakes when trying to setup a binary and library target in the same crate. special_module_name
lints against it, as well as mod main;
warning: found module declaration for main.rs
--> $DIR/special_module_name.rs:4:1
|
LL | mod main;
| ^^^^^^^^^
|
= note: a binary crate cannot be used as library
warning: found module declaration for lib.rs
--> $DIR/special_module_name.rs:1:1
|
LL | mod lib;
| ^^^^^^^^
|
= note: `#[warn(special_module_name)]` on by default
= note: lib.rs is the root of this crate's library target
= help: to refer to it from other targets, use the library's name as the path
Note that the help message is not the best in that it doesn't provide an example of an import path (the_actual_crate_name::
), and doesn't check whether the current file is part of a library/binary target to provide more specific error messages. I'm not sure where this lint would have to be run to access that information.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK