Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't lint snake-case on executable crate name #111130

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -366,7 +367,11 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
})
};

if let Some(ident) = &crate_ident {
if let Some(ident) = &crate_ident
&& cx.tcx.sess.crate_types().iter().all(|&crate_type| {
crate_type != CrateType::Executable
})
{
self.check_snake_case(cx, "crate", ident);
}
}
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/lint/lint-non-snake-case-crate-2.stderr

This file was deleted.

6 changes: 6 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// check-pass
#![crate_name = "NonSnakeCase"]

#![deny(non_snake_case)]

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// check-pass
// compile-flags: --crate-name NonSnakeCase
// error-pattern: crate `NonSnakeCase` should have a snake case name

#![deny(non_snake_case)]

Expand Down
7 changes: 7 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-bin3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// check-pass
#![crate_type = "bin"]
#![crate_name = "NonSnakeCase"]

#![deny(non_snake_case)]

fn main() {}
6 changes: 6 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-cdylib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_type = "cdylib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-cdylib.stderr
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-cdylib.rs:2: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:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to previous error

6 changes: 6 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-dylib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_type = "dylib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-dylib.stderr
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-dylib.rs:2: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:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![crate_type = "lib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![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.rs:1:18
--> $DIR/lint-non-snake-case-crate-lib.rs:2: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:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_type = "proc-macro"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-proc-macro.stderr
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-proc-macro.rs:2: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:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to previous error

6 changes: 6 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_type = "rlib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-rlib.stderr
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-rlib.rs:2: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:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to previous error

6 changes: 6 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-staticlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![crate_type = "staticlib"]
#![crate_name = "NonSnakeCase"]
//~^ ERROR crate `NonSnakeCase` should have a snake case name
#![deny(non_snake_case)]

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/lint/lint-non-snake-case-crate-staticlib.stderr
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-staticlib.rs:2: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:4:9
|
LL | #![deny(non_snake_case)]
| ^^^^^^^^^^^^^^

error: aborting due to previous error