Don't lint snake-case on executable crate name

Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
This commit is contained in:
Gil Shoshan 2023-05-03 14:53:54 +03:00 committed by 许杰友 Jieyou Xu (Joe)
parent ef324565d0
commit bf8756d2dd
No known key found for this signature in database
GPG Key ID: 95DDEBD74A1DC2C0
17 changed files with 123 additions and 15 deletions

View File

@ -10,6 +10,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::FnKind;
use rustc_hir::{GenericParamKind, PatKind};
use rustc_middle::ty;
use rustc_session::config::CrateType;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::{sym, Ident};
use rustc_span::{BytePos, Span};
@ -366,7 +367,9 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
})
};
if let Some(ident) = &crate_ident {
if let Some(ident) = &crate_ident
&& cx.tcx.crate_types().iter().all(|&crate_type| crate_type != CrateType::Executable)
{
self.check_snake_case(cx, "crate", ident);
}
}

View File

@ -1,11 +0,0 @@
error: crate `NonSnakeCase` should have a snake case name
|
= help: convert the identifier to snake case: `non_snake_case`
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-2.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View File

@ -0,0 +1,6 @@
//@ check-pass
#![crate_name = "NonSnakeCase"]
#![deny(non_snake_case)]
fn main() {}

View File

@ -1,5 +1,5 @@
//@ compile-flags: --crate-name NonSnakeCase
//@ error-pattern: crate `NonSnakeCase` should have a snake case name
//@ check-pass
#![deny(non_snake_case)]

View File

@ -0,0 +1,7 @@
//@ check-pass
#![crate_type = "bin"]
#![crate_name = "NonSnakeCase"]
#![deny(non_snake_case)]
fn main() {}

View File

@ -0,0 +1,6 @@
#![crate_type = "cdylib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]
fn main() {}

View File

@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate-cdylib.rs:2:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-cdylib.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View File

@ -0,0 +1,6 @@
#![crate_type = "dylib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]
fn main() {}

View File

@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate-dylib.rs:2:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-dylib.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View File

@ -1,3 +1,4 @@
#![crate_type = "lib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

View File

@ -1,11 +1,11 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate.rs:1:18
--> $DIR/lint-non-snake-case-crate-lib.rs:2:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate.rs:3:9
--> $DIR/lint-non-snake-case-crate-lib.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

View File

@ -0,0 +1,6 @@
#![crate_type = "proc-macro"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]
fn main() {}

View File

@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate-proc-macro.rs:2:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-proc-macro.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View File

@ -0,0 +1,6 @@
#![crate_type = "rlib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]
fn main() {}

View File

@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate-rlib.rs:2:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-rlib.rs:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error

View File

@ -0,0 +1,8 @@
//@ ignore-wasm
#![crate_type = "staticlib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]
fn main() {}

View File

@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate-staticlib.rs:4:18
|
LL | #![crate_name = "NonSnakeCase"]
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
|
note: the lint level is defined here
--> $DIR/lint-non-snake-case-crate-staticlib.rs:6:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
error: aborting due to 1 previous error