Skip to content

Commit 057ac2a

Browse files
authored
Rollup merge of rust-lang#121749 - jieyouxu:issue-45127-fix, r=petrochenkov
Don't lint on executable crates with `non_snake_case` names Revives rust-lang#111130, cc `@GilShoshan94.` Closes rust-lang#45127.
2 parents 363e05d + d363db7 commit 057ac2a

17 files changed

+124
-14
lines changed

Diff for: compiler/rustc_lint/src/nonstandard_style.rs

+5
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};
@@ -331,6 +332,10 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
331332
return;
332333
}
333334

335+
if cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::Executable) {
336+
return;
337+
}
338+
334339
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
335340
Some(Ident::from_str(name))
336341
} else {

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

-11
This file was deleted.

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

+6
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() {}

Diff for: tests/ui/lint/lint-non-snake-case-crate-2.rs renamed to tests/ui/lint/lint-non-snake-case-crate-bin2.rs

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

44
#![deny(non_snake_case)]
55

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

+7
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() {}

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

+6
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() {}
+14
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 1 previous error
14+

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

+6
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() {}

Diff for: tests/ui/lint/lint-non-snake-case-crate-dylib.stderr

+14
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 1 previous error
14+

Diff for: tests/ui/lint/lint-non-snake-case-crate.rs renamed to 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)]

Diff for: tests/ui/lint/lint-non-snake-case-crate.stderr renamed to 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
| ^^^^^^^^^^^^^^
+6
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() {}
+14
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 1 previous error
14+

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

+6
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() {}

Diff for: tests/ui/lint/lint-non-snake-case-crate-rlib.stderr

+14
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 1 previous error
14+

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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ ignore-wasm
2+
3+
#![crate_type = "staticlib"]
4+
#![crate_name = "NonSnakeCase"]
5+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
6+
#![deny(non_snake_case)]
7+
8+
fn main() {}
+14
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:4: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:6:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)