From 161687a07748eb2888132c67c46d143b0f79ca6c 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/3] 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 d81052b5e2466..ce4ee45c485ed 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 bddbac713b88a78a3d65745547e351be49b1bc6b 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:19 +0000 Subject: [PATCH 2/3] Add `ignore-i686-unknown-linux-musl` to known directives --- src/tools/compiletest/src/command-list.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/compiletest/src/command-list.rs b/src/tools/compiletest/src/command-list.rs index 865aa76ddb0c7..f4f2a7285c5ce 100644 --- a/src/tools/compiletest/src/command-list.rs +++ b/src/tools/compiletest/src/command-list.rs @@ -56,6 +56,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "ignore-horizon", "ignore-i686-pc-windows-gnu", "ignore-i686-pc-windows-msvc", + "ignore-i686-unknown-linux-musl", "ignore-illumos", "ignore-ios", "ignore-linux", From aebc28eaca07030147d826c4260bb66b9506af31 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 3/3] 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 | 26 +++++++++++++++++++ ...int-non-snake-case-crate.staticlib_.stderr | 14 ++++++++++ 18 files changed, 62 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 f8aad88eceecf..0000000000000 --- 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 c077d81e9e542..0000000000000 --- 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 278f7cfd3ee48..0000000000000 --- 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 781c6794fc2aa..0000000000000 --- 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 3f65295f06839..0000000000000 --- 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 20c58e66aa626..0000000000000 --- 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 f0f2fa4393ee8..0000000000000 --- 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 e0091057bc971..0000000000000 --- 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 1a558def3d02e..0000000000000 --- 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 2ec53c15eb804..0000000000000 --- 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 4ee6d5bd4d46f..0000000000000 --- 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 a68c0e832b88c..a7b3140f27ff5 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:22: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:24: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 6e9d54bd5bcde..a7b3140f27ff5 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:22: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:24: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 4ee1a9cb3ddd5..a7b3140f27ff5 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:22: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:24: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 f9167aa8df349..a7b3140f27ff5 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:22: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:24: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 0000000000000..a7b3140f27ff5 --- /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:22: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:24: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 0000000000000..5cd9f3294d376 --- /dev/null +++ b/tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs @@ -0,0 +1,26 @@ +//! 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_] compile-flags: --crate-type=cdylib +//@[cdylib_] ignore-i686-unknown-linux-musl (cdylib is not supported) +//@[dylib_] compile-flags: --crate-type=dylib +//@[dylib_] ignore-wasm (dylib is not supported) +//@[lib_] compile-flags: --crate-type=lib +//@[proc_macro_] compile-flags: --crate-type=proc-macro +//@[proc_macro_] ignore-wasm (dylib is not supported) +//@[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 0000000000000..a7b3140f27ff5 --- /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:22: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:24:9 + | +LL | #![deny(non_snake_case)] + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +