about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGil Shoshan <shoshan.gil@gmail.com>2023-05-03 14:53:54 +0300
committer许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com>2024-02-28 16:55:00 +0000
commitbf8756d2dd820c560cf8172b43dedfcba00d7d88 (patch)
tree8f04e045225425bf12a71c27ad2fde6aaead0401
parentef324565d071c6d7e2477a195648549e33d6a465 (diff)
downloadrust-bf8756d2dd820c560cf8172b43dedfcba00d7d88.tar.gz
rust-bf8756d2dd820c560cf8172b43dedfcba00d7d88.zip
Don't lint snake-case on executable crate name
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
-rw-r--r--compiler/rustc_lint/src/nonstandard_style.rs5
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-2.stderr11
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-bin.rs6
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-bin2.rs (renamed from tests/ui/lint/lint-non-snake-case-crate-2.rs)2
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-bin3.rs7
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-cdylib.rs6
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr14
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-dylib.rs6
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-dylib.stderr14
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-lib.rs (renamed from tests/ui/lint/lint-non-snake-case-crate.rs)1
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-lib.stderr (renamed from tests/ui/lint/lint-non-snake-case-crate.stderr)4
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs6
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr14
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-rlib.rs6
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-rlib.stderr14
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-staticlib.rs8
-rw-r--r--tests/ui/lint/lint-non-snake-case-crate-staticlib.stderr14
17 files changed, 123 insertions, 15 deletions
diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs
index 4ecd87e37d3..d77bc743ca9 100644
--- a/compiler/rustc_lint/src/nonstandard_style.rs
+++ b/compiler/rustc_lint/src/nonstandard_style.rs
@@ -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);
         }
     }
diff --git a/tests/ui/lint/lint-non-snake-case-crate-2.stderr b/tests/ui/lint/lint-non-snake-case-crate-2.stderr
deleted file mode 100644
index f3207226cd9..00000000000
--- a/tests/ui/lint/lint-non-snake-case-crate-2.stderr
+++ /dev/null
@@ -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
-
diff --git a/tests/ui/lint/lint-non-snake-case-crate-bin.rs b/tests/ui/lint/lint-non-snake-case-crate-bin.rs
new file mode 100644
index 00000000000..ac1a03369ef
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-bin.rs
@@ -0,0 +1,6 @@
+//@ check-pass
+#![crate_name = "NonSnakeCase"]
+
+#![deny(non_snake_case)]
+
+fn main() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-2.rs b/tests/ui/lint/lint-non-snake-case-crate-bin2.rs
index b4b816a5a57..78eb5d1b6cd 100644
--- a/tests/ui/lint/lint-non-snake-case-crate-2.rs
+++ b/tests/ui/lint/lint-non-snake-case-crate-bin2.rs
@@ -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)]
 
diff --git a/tests/ui/lint/lint-non-snake-case-crate-bin3.rs b/tests/ui/lint/lint-non-snake-case-crate-bin3.rs
new file mode 100644
index 00000000000..1e801802b43
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-bin3.rs
@@ -0,0 +1,7 @@
+//@ check-pass
+#![crate_type = "bin"]
+#![crate_name = "NonSnakeCase"]
+
+#![deny(non_snake_case)]
+
+fn main() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-cdylib.rs b/tests/ui/lint/lint-non-snake-case-crate-cdylib.rs
new file mode 100644
index 00000000000..d2cd62fd68a
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-cdylib.rs
@@ -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() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr b/tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr
new file mode 100644
index 00000000000..4bb129f31b7
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr
@@ -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
+
diff --git a/tests/ui/lint/lint-non-snake-case-crate-dylib.rs b/tests/ui/lint/lint-non-snake-case-crate-dylib.rs
new file mode 100644
index 00000000000..1ab974c54f6
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-dylib.rs
@@ -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() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-dylib.stderr b/tests/ui/lint/lint-non-snake-case-crate-dylib.stderr
new file mode 100644
index 00000000000..23d40c2394d
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-dylib.stderr
@@ -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
+
diff --git a/tests/ui/lint/lint-non-snake-case-crate.rs b/tests/ui/lint/lint-non-snake-case-crate-lib.rs
index e4e84261a4e..79e020f07ba 100644
--- a/tests/ui/lint/lint-non-snake-case-crate.rs
+++ b/tests/ui/lint/lint-non-snake-case-crate-lib.rs
@@ -1,3 +1,4 @@
+#![crate_type = "lib"]
 #![crate_name = "NonSnakeCase"]
 //~^ ERROR crate `NonSnakeCase` should have a snake case name
 #![deny(non_snake_case)]
diff --git a/tests/ui/lint/lint-non-snake-case-crate.stderr b/tests/ui/lint/lint-non-snake-case-crate-lib.stderr
index 1136b707d59..6d40a6bdb6c 100644
--- a/tests/ui/lint/lint-non-snake-case-crate.stderr
+++ b/tests/ui/lint/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.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)]
    |         ^^^^^^^^^^^^^^
diff --git a/tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs b/tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs
new file mode 100644
index 00000000000..949abe5573c
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs
@@ -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() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr b/tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr
new file mode 100644
index 00000000000..4963eef88e4
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr
@@ -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
+
diff --git a/tests/ui/lint/lint-non-snake-case-crate-rlib.rs b/tests/ui/lint/lint-non-snake-case-crate-rlib.rs
new file mode 100644
index 00000000000..1d5334d81f3
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-rlib.rs
@@ -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() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-rlib.stderr b/tests/ui/lint/lint-non-snake-case-crate-rlib.stderr
new file mode 100644
index 00000000000..ba0b85f6f00
--- /dev/null
+++ b/tests/ui/lint/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-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
+
diff --git a/tests/ui/lint/lint-non-snake-case-crate-staticlib.rs b/tests/ui/lint/lint-non-snake-case-crate-staticlib.rs
new file mode 100644
index 00000000000..fbb4ea7d0b5
--- /dev/null
+++ b/tests/ui/lint/lint-non-snake-case-crate-staticlib.rs
@@ -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() {}
diff --git a/tests/ui/lint/lint-non-snake-case-crate-staticlib.stderr b/tests/ui/lint/lint-non-snake-case-crate-staticlib.stderr
new file mode 100644
index 00000000000..49438414c27
--- /dev/null
+++ b/tests/ui/lint/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-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
+