Skip to content

Commit 5050837

Browse files
committed
Auto merge of rust-lang#130599 - jieyouxu:snake_case_binary_cleanup, r=petrochenkov
Explain why `non_snake_case` is skipped for binary crates and cleanup tests - Explain `non_snake_case` lint is skipped for bin crate names because binaries are not intended to be distributed or consumed like library crates (rust-lang#45127). - Coalesce the bunch of tests into a single one but with revisions, which is easier to compare the differences for `non_snake_case` behavior with respect to crate types. Follow-up to rust-lang#121749 with some more comments and test cleanup. cc `@saethlin` who bumped into one of the tests and was confused why it was `only-x86_64-unknown-linux-gnu`.
2 parents c0838c8 + aebc28e commit 5050837

20 files changed

+66
-100
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+3
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
332332
return;
333333
}
334334

335+
// Issue #45127: don't enforce `snake_case` for binary crates as binaries are not intended
336+
// to be distributed and depended on like libraries. The lint is not suppressed for cdylib
337+
// or staticlib because it's not clear what the desired lint behavior for those are.
335338
if cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::Executable) {
336339
return;
337340
}

src/tools/compiletest/src/command-list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
5656
"ignore-horizon",
5757
"ignore-i686-pc-windows-gnu",
5858
"ignore-i686-pc-windows-msvc",
59+
"ignore-i686-unknown-linux-musl",
5960
"ignore-illumos",
6061
"ignore-ios",
6162
"ignore-linux",

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

-7
This file was deleted.

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

-7
This file was deleted.

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

-8
This file was deleted.

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

-7
This file was deleted.

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

-7
This file was deleted.

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

-7
This file was deleted.

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.rs

-7
This file was deleted.

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-proc-macro.stderr

-14
This file was deleted.

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

-7
This file was deleted.

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

-7
This file was deleted.

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

-14
This file was deleted.

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.stderr renamed to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.cdylib_.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-lib.rs:3:18
2+
--> $DIR/lint-non-snake-case-crate.rs:22: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-lib.rs:5:9
8+
--> $DIR/lint-non-snake-case-crate.rs:24:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.stderr renamed to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.dylib_.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-rlib.rs:3:18
2+
--> $DIR/lint-non-snake-case-crate.rs:22: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-rlib.rs:5:9
8+
--> $DIR/lint-non-snake-case-crate.rs:24:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.stderr renamed to tests/ui/lint/non-snake-case/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-dylib.rs:3:18
2+
--> $DIR/lint-non-snake-case-crate.rs:22: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-dylib.rs:5:9
8+
--> $DIR/lint-non-snake-case-crate.rs:24:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.stderr renamed to tests/ui/lint/non-snake-case/lint-non-snake-case-crate.proc_macro_.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-cdylib.rs:3:18
2+
--> $DIR/lint-non-snake-case-crate.rs:22: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-cdylib.rs:5:9
8+
--> $DIR/lint-non-snake-case-crate.rs:24:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^
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.rs:22: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.rs:24:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Don't lint on binary crate with non-snake-case names.
2+
//!
3+
//! See <https://github.com/rust-lang/rust/issues/45127>.
4+
5+
//@ revisions: bin_ cdylib_ dylib_ lib_ proc_macro_ rlib_ staticlib_
6+
7+
// Should not fire on binary crates.
8+
//@[bin_] compile-flags: --crate-type=bin
9+
//@[bin_] check-pass
10+
11+
// But should fire on non-binary crates.
12+
//@[cdylib_] compile-flags: --crate-type=cdylib
13+
//@[cdylib_] ignore-i686-unknown-linux-musl (cdylib is not supported)
14+
//@[dylib_] compile-flags: --crate-type=dylib
15+
//@[dylib_] ignore-wasm (dylib is not supported)
16+
//@[lib_] compile-flags: --crate-type=lib
17+
//@[proc_macro_] compile-flags: --crate-type=proc-macro
18+
//@[proc_macro_] ignore-wasm (dylib is not supported)
19+
//@[rlib_] compile-flags: --crate-type=rlib
20+
//@[staticlib_] compile-flags: --crate-type=staticlib
21+
22+
#![crate_name = "NonSnakeCase"]
23+
//[cdylib_,dylib_,lib_,proc_macro_,rlib_,staticlib_]~^ ERROR crate `NonSnakeCase` should have a snake case name
24+
#![deny(non_snake_case)]
25+
26+
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.rs:22: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.rs:24:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)