Skip to content

Commit cdb0b9a

Browse files
authored
Unrolled build for rust-lang#121749
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 70aa0b8 + d0111cb commit cdb0b9a

17 files changed

+131
-14
lines changed

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 {

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,7 @@
1+
//@ only-x86_64-unknown-linux-gnu
2+
//@ check-pass
3+
#![crate_name = "NonSnakeCase"]
4+
5+
#![deny(non_snake_case)]
6+
7+
fn main() {}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
//@ only-x86_64-unknown-linux-gnu
12
//@ compile-flags: --crate-name NonSnakeCase
2-
//@ error-pattern: crate `NonSnakeCase` should have a snake case name
3+
//@ check-pass
34

45
#![deny(non_snake_case)]
56

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

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ only-x86_64-unknown-linux-gnu
2+
#![crate_type = "lib"]
13
#![crate_name = "NonSnakeCase"]
24
//~^ ERROR crate `NonSnakeCase` should have a snake case name
35
#![deny(non_snake_case)]

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:3: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:5:9
99
|
1010
LL | #![deny(non_snake_case)]
1111
| ^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ only-x86_64-unknown-linux-gnu
2+
#![crate_type = "proc-macro"]
3+
#![crate_name = "NonSnakeCase"]
4+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
5+
#![deny(non_snake_case)]
6+
7+
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:3: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:5: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,7 @@
1+
//@ only-x86_64-unknown-linux-gnu
2+
#![crate_type = "rlib"]
3+
#![crate_name = "NonSnakeCase"]
4+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
5+
#![deny(non_snake_case)]
6+
7+
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:3: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:5: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,7 @@
1+
//@ only-x86_64-unknown-linux-gnu
2+
#![crate_type = "staticlib"]
3+
#![crate_name = "NonSnakeCase"]
4+
//~^ ERROR crate `NonSnakeCase` should have a snake case name
5+
#![deny(non_snake_case)]
6+
7+
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:3: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:5:9
9+
|
10+
LL | #![deny(non_snake_case)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)