]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #94467 - ibraheemdev:master, r=pnkfelix
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 1 Sep 2022 19:37:07 +0000 (21:37 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Sep 2022 19:37:07 +0000 (21:37 +0200)
commitda1d7386014bd5dbe045d9f4f80921c3882719bc
tree9aa46333bc7a17a0f6f812fb6c2fbc355f1899e1
parent9af618b62e91b45d61f41548f24ba60b834e362b
parent4fdf43f23fbd4fb69960c9136dc796d8e64be785
Rollup merge of #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.
compiler/rustc_lint/src/builtin.rs
compiler/rustc_lint/src/lib.rs