Skip to content

Commit

Permalink
Auto merge of rust-lang#130599 - jieyouxu:snake_case_binary_cleanup, …
Browse files Browse the repository at this point in the history
…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`.

try-job: dist-i586-gnu-i586-i686-musl
  • Loading branch information
bors committed Sep 21, 2024
2 parents 74fd001 + 9ae1fb4 commit f48c99a
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 100 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 0 additions & 7 deletions tests/ui/lint/non-snake-case/lint-non-snake-case-crate-bin.rs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions tests/ui/lint/non-snake-case/lint-non-snake-case-crate-lib.rs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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:25: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:27:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -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:25: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:27:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -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:25: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:27:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -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:25: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:27:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate.rs:25: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:27:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to 1 previous error

29 changes: 29 additions & 0 deletions tests/ui/lint/non-snake-case/lint-non-snake-case-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Don't lint on binary crate with non-snake-case names.
//!
//! See <https://github.com/rust-lang/rust/issues/45127>.

//@ 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_] ignore-musl (dylibs are not supported)
//@[dylib_] ignore-musl (dylibs are not supported)
//@[dylib_] ignore-wasm (dylib is not supported)
//@[proc_macro_] ignore-wasm (dylib is not supported)

//@[cdylib_] compile-flags: --crate-type=cdylib
//@[dylib_] compile-flags: --crate-type=dylib
//@[lib_] compile-flags: --crate-type=lib
//@[proc_macro_] compile-flags: --crate-type=proc-macro
//@[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() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: crate `NonSnakeCase` should have a snake case name
--> $DIR/lint-non-snake-case-crate.rs:25: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:27:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to 1 previous error

0 comments on commit f48c99a

Please sign in to comment.