mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #121749 - jieyouxu:issue-45127-fix, r=petrochenkov
Don't lint on executable crates with `non_snake_case` names Revives #111130, cc `@GilShoshan94.` Closes #45127.
This commit is contained in:
commit
10234fc246
@ -10,6 +10,7 @@ use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{GenericParamKind, PatKind};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::config::CrateType;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::{BytePos, Span};
|
||||
@ -331,6 +332,10 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
||||
return;
|
||||
}
|
||||
|
||||
if cx.tcx.crate_types().iter().all(|&crate_type| crate_type == CrateType::Executable) {
|
||||
return;
|
||||
}
|
||||
|
||||
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
|
||||
Some(Ident::from_str(name))
|
||||
} else {
|
||||
|
@ -1,11 +0,0 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
|
|
||||
= help: convert the identifier to snake case: `non_snake_case`
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-non-snake-case-crate-2.rs:4:9
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
7
tests/ui/lint/lint-non-snake-case-crate-bin.rs
Normal file
7
tests/ui/lint/lint-non-snake-case-crate-bin.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
//@ check-pass
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
@ -1,5 +1,6 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
//@ compile-flags: --crate-name NonSnakeCase
|
||||
//@ error-pattern: crate `NonSnakeCase` should have a snake case name
|
||||
//@ check-pass
|
||||
|
||||
#![deny(non_snake_case)]
|
||||
|
8
tests/ui/lint/lint-non-snake-case-crate-bin3.rs
Normal file
8
tests/ui/lint/lint-non-snake-case-crate-bin3.rs
Normal file
@ -0,0 +1,8 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
//@ check-pass
|
||||
#![crate_type = "bin"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
7
tests/ui/lint/lint-non-snake-case-crate-cdylib.rs
Normal file
7
tests/ui/lint/lint-non-snake-case-crate-cdylib.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
#![crate_type = "cdylib"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
//~^ ERROR crate `NonSnakeCase` should have a snake case name
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
14
tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr
Normal file
14
tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
--> $DIR/lint-non-snake-case-crate-cdylib.rs:3: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
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
7
tests/ui/lint/lint-non-snake-case-crate-dylib.rs
Normal file
7
tests/ui/lint/lint-non-snake-case-crate-dylib.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
#![crate_type = "dylib"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
//~^ ERROR crate `NonSnakeCase` should have a snake case name
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
14
tests/ui/lint/lint-non-snake-case-crate-dylib.stderr
Normal file
14
tests/ui/lint/lint-non-snake-case-crate-dylib.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
--> $DIR/lint-non-snake-case-crate-dylib.rs:3: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
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
@ -1,3 +1,5 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
#![crate_type = "lib"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
//~^ ERROR crate `NonSnakeCase` should have a snake case name
|
||||
#![deny(non_snake_case)]
|
@ -1,11 +1,11 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
--> $DIR/lint-non-snake-case-crate.rs:1:18
|
||||
--> $DIR/lint-non-snake-case-crate-lib.rs:3: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:3:9
|
||||
--> $DIR/lint-non-snake-case-crate-lib.rs:5:9
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
7
tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs
Normal file
7
tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
#![crate_type = "proc-macro"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
//~^ ERROR crate `NonSnakeCase` should have a snake case name
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
14
tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr
Normal file
14
tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
--> $DIR/lint-non-snake-case-crate-proc-macro.rs:3: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-proc-macro.rs:5:9
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
7
tests/ui/lint/lint-non-snake-case-crate-rlib.rs
Normal file
7
tests/ui/lint/lint-non-snake-case-crate-rlib.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
#![crate_type = "rlib"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
//~^ ERROR crate `NonSnakeCase` should have a snake case name
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
14
tests/ui/lint/lint-non-snake-case-crate-rlib.stderr
Normal file
14
tests/ui/lint/lint-non-snake-case-crate-rlib.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
--> $DIR/lint-non-snake-case-crate-rlib.rs:3: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
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
7
tests/ui/lint/lint-non-snake-case-crate-staticlib.rs
Normal file
7
tests/ui/lint/lint-non-snake-case-crate-staticlib.rs
Normal file
@ -0,0 +1,7 @@
|
||||
//@ only-x86_64-unknown-linux-gnu
|
||||
#![crate_type = "staticlib"]
|
||||
#![crate_name = "NonSnakeCase"]
|
||||
//~^ ERROR crate `NonSnakeCase` should have a snake case name
|
||||
#![deny(non_snake_case)]
|
||||
|
||||
fn main() {}
|
14
tests/ui/lint/lint-non-snake-case-crate-staticlib.stderr
Normal file
14
tests/ui/lint/lint-non-snake-case-crate-staticlib.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error: crate `NonSnakeCase` should have a snake case name
|
||||
--> $DIR/lint-non-snake-case-crate-staticlib.rs:3: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-staticlib.rs:5:9
|
||||
|
|
||||
LL | #![deny(non_snake_case)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Reference in New Issue
Block a user