From 43ede7331d6b05f6e3c1b215694db3137c8583c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Fri, 20 Sep 2024 05:31:54 +0000 Subject: [PATCH 1/2] Explain why non_snake_case is skipped for binary crates --- compiler/rustc_lint/src/nonstandard_style.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index d81052b5e24..ce4ee45c485 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -332,6 +332,9 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase { return; } + // Issue #45127: don't enforce `snake_case` for binary crates as binaries are not intended + // to be distributed and depended on like libraries. The lint is not suppressed for cdylib + // or staticlib because it's not clear what the desired lint behavior for those are. if cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::Executable) { return; } From 9ae1fb4329eaed6e75d20da67b30bf86c5700481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Fri, 20 Sep 2024 05:32:44 +0000 Subject: [PATCH 2/2] Coalesce `non_snake_case` crate test set with revisions --- .../lint-non-snake-case-crate-bin.rs | 7 ----- .../lint-non-snake-case-crate-bin2.rs | 7 ----- .../lint-non-snake-case-crate-bin3.rs | 8 ----- .../lint-non-snake-case-crate-cdylib.rs | 7 ----- .../lint-non-snake-case-crate-dylib.rs | 7 ----- .../lint-non-snake-case-crate-lib.rs | 7 ----- .../lint-non-snake-case-crate-proc-macro.rs | 7 ----- ...int-non-snake-case-crate-proc-macro.stderr | 14 --------- .../lint-non-snake-case-crate-rlib.rs | 7 ----- .../lint-non-snake-case-crate-staticlib.rs | 7 ----- ...lint-non-snake-case-crate-staticlib.stderr | 14 --------- ... lint-non-snake-case-crate.cdylib_.stderr} | 4 +-- ...> lint-non-snake-case-crate.dylib_.stderr} | 4 +-- ... => lint-non-snake-case-crate.lib_.stderr} | 4 +-- ...t-non-snake-case-crate.proc_macro_.stderr} | 4 +-- .../lint-non-snake-case-crate.rlib_.stderr | 14 +++++++++ .../lint-non-snake-case-crate.rs | 29 +++++++++++++++++++ ...int-non-snake-case-crate.staticlib_.stderr | 14 +++++++++ 18 files changed, 65 insertions(+), 100 deletions(-) delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin2.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin3.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.stderr delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.rs delete mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.stderr rename tests/ui/lint/non-snake-case/{lint-non-snake-case-crate-lib.stderr => lint-non-snake-case-crate.cdylib_.stderr} (77%) rename tests/ui/lint/non-snake-case/{lint-non-snake-case-crate-rlib.stderr => lint-non-snake-case-crate.dylib_.stderr} (77%) rename tests/ui/lint/non-snake-case/{lint-non-snake-case-crate-dylib.stderr => lint-non-snake-case-crate.lib_.stderr} (77%) rename tests/ui/lint/non-snake-case/{lint-non-snake-case-crate-cdylib.stderr => lint-non-snake-case-crate.proc_macro_.stderr} (76%) create mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr create mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs create mode 100644 tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin.rs deleted file mode 100644 index f8aad88ecee..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -//@ check-pass -#![crate_name = "NonSnakeCase"] - -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin2.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin2.rs deleted file mode 100644 index c077d81e9e5..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin2.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -//@ compile-flags: --crate-name NonSnakeCase -//@ check-pass - -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin3.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin3.rs deleted file mode 100644 index 278f7cfd3ee..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin3.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -//@ check-pass -#![crate_type = "bin"] -#![crate_name = "NonSnakeCase"] - -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.rs deleted file mode 100644 index 781c6794fc2..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -#![crate_type = "cdylib"] -#![crate_name = "NonSnakeCase"] -//~^ ERROR crate `NonSnakeCase` should have a snake case name -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.rs deleted file mode 100644 index 3f65295f068..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -#![crate_type = "dylib"] -#![crate_name = "NonSnakeCase"] -//~^ ERROR crate `NonSnakeCase` should have a snake case name -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.rs deleted file mode 100644 index 20c58e66aa6..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -#![crate_type = "lib"] -#![crate_name = "NonSnakeCase"] -//~^ ERROR crate `NonSnakeCase` should have a snake case name -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.rs deleted file mode 100644 index f0f2fa4393e..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -#![crate_type = "proc-macro"] -#![crate_name = "NonSnakeCase"] -//~^ ERROR crate `NonSnakeCase` should have a snake case name -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.stderr deleted file mode 100644 index e0091057bc9..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate-proc-macro.rs:3: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:5:9 - | -LL | #![deny(non_snake_case)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.rs deleted file mode 100644 index 1a558def3d0..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -#![crate_type = "rlib"] -#![crate_name = "NonSnakeCase"] -//~^ ERROR crate `NonSnakeCase` should have a snake case name -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.rs deleted file mode 100644 index 2ec53c15eb8..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ only-x86_64-unknown-linux-gnu -#![crate_type = "staticlib"] -#![crate_name = "NonSnakeCase"] -//~^ ERROR crate `NonSnakeCase` should have a snake case name -#![deny(non_snake_case)] - -fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.stderr deleted file mode 100644 index 4ee6d5bd4d4..00000000000 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-staticlib.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate-staticlib.rs:3: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:5:9 - | -LL | #![deny(non_snake_case)] - | ^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr similarity index 77% rename from tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.stderr rename to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr index a68c0e832b8..9bccb270627 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate-lib.rs:3:18 + --> $DIR/lint-non-snake-case-crate.rs:25: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-lib.rs:5:9 + --> $DIR/lint-non-snake-case-crate.rs:27:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr similarity index 77% rename from tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.stderr rename to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr index 6e9d54bd5bc..9bccb270627 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate-rlib.rs:3:18 + --> $DIR/lint-non-snake-case-crate.rs:25: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:5:9 + --> $DIR/lint-non-snake-case-crate.rs:27:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr similarity index 77% rename from tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.stderr rename to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr index 4ee1a9cb3dd..9bccb270627 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.lib_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate-dylib.rs:3:18 + --> $DIR/lint-non-snake-case-crate.rs:25: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:5:9 + --> $DIR/lint-non-snake-case-crate.rs:27:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr similarity index 76% rename from tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.stderr rename to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr index f9167aa8df3..9bccb270627 100644 --- a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.stderr +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.stderr @@ -1,11 +1,11 @@ error: crate `NonSnakeCase` should have a snake case name - --> $DIR/lint-non-snake-case-crate-cdylib.rs:3:18 + --> $DIR/lint-non-snake-case-crate.rs:25: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:5:9 + --> $DIR/lint-non-snake-case-crate.rs:27:9 | LL | #![deny(non_snake_case)] | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr new file mode 100644 index 00000000000..9bccb270627 --- /dev/null +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rlib_.stderr @@ -0,0 +1,14 @@ +error: crate `NonSnakeCase` should have a snake case name + --> $DIR/lint-non-snake-case-crate.rs:25: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:27:9 + | +LL | #![deny(non_snake_case)] + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs new file mode 100644 index 00000000000..57604d99a07 --- /dev/null +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs @@ -0,0 +1,29 @@ +//! Don't lint on binary crate with non-snake-case names. +//! +//! See . + +//@ revisions: bin_ cdylib_ dylib_ lib_ proc_macro_ rlib_ staticlib_ + +// Should not fire on binary crates. +//@[bin_] compile-flags: --crate-type=bin +//@[bin_] check-pass + +// But should fire on non-binary crates. + +//@[cdylib_] ignore-musl (dylibs are not supported) +//@[dylib_] ignore-musl (dylibs are not supported) +//@[dylib_] ignore-wasm (dylib is not supported) +//@[proc_macro_] ignore-wasm (dylib is not supported) + +//@[cdylib_] compile-flags: --crate-type=cdylib +//@[dylib_] compile-flags: --crate-type=dylib +//@[lib_] compile-flags: --crate-type=lib +//@[proc_macro_] compile-flags: --crate-type=proc-macro +//@[rlib_] compile-flags: --crate-type=rlib +//@[staticlib_] compile-flags: --crate-type=staticlib + +#![crate_name = "NonSnakeCase"] +//[cdylib_,dylib_,lib_,proc_macro_,rlib_,staticlib_]~^ ERROR crate `NonSnakeCase` should have a snake case name +#![deny(non_snake_case)] + +fn main() {} diff --git a/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr new file mode 100644 index 00000000000..9bccb270627 --- /dev/null +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.staticlib_.stderr @@ -0,0 +1,14 @@ +error: crate `NonSnakeCase` should have a snake case name + --> $DIR/lint-non-snake-case-crate.rs:25: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:27:9 + | +LL | #![deny(non_snake_case)] + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +