Skip to content

Commit f48c99a

Browse files
committed
Auto merge of #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 (#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 #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`. try-job: dist-i586-gnu-i586-i686-musl
2 parents 74fd001 + 9ae1fb4 commit f48c99a

19 files changed

+68
-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
}

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 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:25: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:27:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-rlib.stderr 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:25: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:27:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-dylib.stderr 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:25: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:27:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^

tests/ui/lint/non-snake-case/lint-non-snake-case-crate-cdylib.stderr 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:25: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:27: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:25: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:27: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,29 @@
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+
13+
//@[cdylib_] ignore-musl (dylibs are not supported)
14+
//@[dylib_] ignore-musl (dylibs are not supported)
15+
//@[dylib_] ignore-wasm (dylib is not supported)
16+
//@[proc_macro_] ignore-wasm (dylib is not supported)
17+
18+
//@[cdylib_] compile-flags: --crate-type=cdylib
19+
//@[dylib_] compile-flags: --crate-type=dylib
20+
//@[lib_] compile-flags: --crate-type=lib
21+
//@[proc_macro_] compile-flags: --crate-type=proc-macro
22+
//@[rlib_] compile-flags: --crate-type=rlib
23+
//@[staticlib_] compile-flags: --crate-type=staticlib
24+
25+
#![crate_name = "NonSnakeCase"]
26+
//[cdylib_,dylib_,lib_,proc_macro_,rlib_,staticlib_]~^ ERROR crate `NonSnakeCase` should have a snake case name
27+
#![deny(non_snake_case)]
28+
29+
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:25: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:27:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)