Skip to content

Commit 166e715

Browse files
authored
Rollup merge of rust-lang#111130 - GilShoshan94:issue-45127-fix, r=oli-obk
Don't lint snake-case on executable crate name Fix rust-lang#45127 Hi, First PR on Rust, I tried my best to follow "Rust Compiler Development Guide". I tested it with a custom toolchain on a dummy bin crate with one submodule and it seems to work. The lint `non_snake_case` ignore the binary crate name but not the module name. Thank you `@Manishearth` and `@jyn514` for the guidance !
2 parents 8ca6de2 + e4dcf0c commit 166e715

17 files changed

+123
-15
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::intravisit::FnKind;
1111
use rustc_hir::{GenericParamKind, PatKind};
1212
use rustc_middle::ty;
13+
use rustc_session::config::CrateType;
1314
use rustc_span::def_id::LocalDefId;
1415
use rustc_span::symbol::{sym, Ident};
1516
use rustc_span::{BytePos, Span};
@@ -366,7 +367,11 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
366367
})
367368
};
368369

369-
if let Some(ident) = &crate_ident {
370+
if let Some(ident) = &crate_ident
371+
&& cx.tcx.sess.crate_types().iter().all(|&crate_type| {
372+
crate_type != CrateType::Executable
373+
})
374+
{
370375
self.check_snake_case(cx, "crate", ident);
371376
}
372377
}

tests/ui/lint/lint-non-snake-case-crate-2.stderr

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// check-pass
2+
#![crate_name = "NonSnakeCase"]
3+
4+
#![deny(non_snake_case)]
5+
6+
fn main() {}

tests/ui/lint/lint-non-snake-case-crate-2.rs tests/ui/lint/lint-non-snake-case-crate-bin2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
// check-pass
12
// compile-flags: --crate-name NonSnakeCase
2-
// error-pattern: crate `NonSnakeCase` should have a snake case name
33

44
#![deny(non_snake_case)]
55

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-pass
2+
#![crate_type = "bin"]
3+
#![crate_name = "NonSnakeCase"]
4+
5+
#![deny(non_snake_case)]
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "cdylib"]
2+
#![crate_name = "NonSnakeCase"]
3+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
4+
#![deny(non_snake_case)]
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: crate `NonSnakeCase` should have a snake case name
2+
--> $DIR/lint-non-snake-case-crate-cdylib.rs:2:18
3+
|
4+
LL | #![crate_name = "NonSnakeCase"]
5+
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-non-snake-case-crate-cdylib.rs:4:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "dylib"]
2+
#![crate_name = "NonSnakeCase"]
3+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
4+
#![deny(non_snake_case)]
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: crate `NonSnakeCase` should have a snake case name
2+
--> $DIR/lint-non-snake-case-crate-dylib.rs:2:18
3+
|
4+
LL | #![crate_name = "NonSnakeCase"]
5+
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-non-snake-case-crate-dylib.rs:4:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

tests/ui/lint/lint-non-snake-case-crate.rs tests/ui/lint/lint-non-snake-case-crate-lib.rs

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

tests/ui/lint/lint-non-snake-case-crate.stderr tests/ui/lint/lint-non-snake-case-crate-lib.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: crate `NonSnakeCase` should have a snake case name
2-
--> $DIR/lint-non-snake-case-crate.rs:1:18
2+
--> $DIR/lint-non-snake-case-crate-lib.rs:2:18
33
|
44
LL | #![crate_name = "NonSnakeCase"]
55
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
66
|
77
note: the lint level is defined here
8-
--> $DIR/lint-non-snake-case-crate.rs:3:9
8+
--> $DIR/lint-non-snake-case-crate-lib.rs:4:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "proc-macro"]
2+
#![crate_name = "NonSnakeCase"]
3+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
4+
#![deny(non_snake_case)]
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: crate `NonSnakeCase` should have a snake case name
2+
--> $DIR/lint-non-snake-case-crate-proc-macro.rs:2:18
3+
|
4+
LL | #![crate_name = "NonSnakeCase"]
5+
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-non-snake-case-crate-proc-macro.rs:4:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "rlib"]
2+
#![crate_name = "NonSnakeCase"]
3+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
4+
#![deny(non_snake_case)]
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: crate `NonSnakeCase` should have a snake case name
2+
--> $DIR/lint-non-snake-case-crate-rlib.rs:2:18
3+
|
4+
LL | #![crate_name = "NonSnakeCase"]
5+
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-non-snake-case-crate-rlib.rs:4:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "staticlib"]
2+
#![crate_name = "NonSnakeCase"]
3+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
4+
#![deny(non_snake_case)]
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: crate `NonSnakeCase` should have a snake case name
2+
--> $DIR/lint-non-snake-case-crate-staticlib.rs:2:18
3+
|
4+
LL | #![crate_name = "NonSnakeCase"]
5+
| ^^^^^^^^^^^^ help: convert the identifier to snake case: `non_snake_case`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-non-snake-case-crate-staticlib.rs:4:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)