forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#94467 - ibraheemdev:master, r=pnkfelix
Add `special_module_name` lint 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.
- Loading branch information
Showing
6 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[allow(dead_code)] | ||
pub struct Dummy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod lib; | ||
//~^ WARN found module declaration for lib.rs | ||
//~| ERROR file not found for module `lib` | ||
mod main; | ||
//~^ WARN found module declaration for main.rs | ||
//~| ERROR file not found for module `main` | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
error[E0583]: file not found for module `lib` | ||
--> $DIR/special_module_name.rs:1:1 | ||
| | ||
LL | mod lib; | ||
| ^^^^^^^^ | ||
| | ||
= help: to create the module `lib`, create file "$DIR/lib.rs" or "$DIR/lib/mod.rs" | ||
|
||
error[E0583]: file not found for module `main` | ||
--> $DIR/special_module_name.rs:4:1 | ||
| | ||
LL | mod main; | ||
| ^^^^^^^^^ | ||
| | ||
= help: to create the module `main`, create file "$DIR/main.rs" or "$DIR/main/mod.rs" | ||
|
||
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 | ||
|
||
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 | ||
|
||
error: aborting due to 2 previous errors; 2 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0583`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// run-pass | ||
|
||
#[path = "auxiliary/dummy_lib.rs"] | ||
mod lib; | ||
|
||
#[path = "auxiliary/dummy_lib.rs"] | ||
mod main; | ||
|
||
fn main() {} |