Rust: Don't enforce snake_case for binary names

Created on 9 Oct 2017  ·  3Comments  ·  Source: rust-lang/rust

Currently, if you have a Cargo.toml like this:

[package]
name = "some_package"
version = "0.0.0"

[[bin]]
name = "somePackage"
path = "src/main.rs"

rustc will complain:

warning: crate `somePackage` should have a snake case name such as `some_package`
  |
  = note: #[warn(non_snake_case)] on by default

I understand why this is reasonable for library crates, to enforce a common naming convention for rust libraries and source code. But it doesn't make much sense to enforce this for binaries as well, as there is no real advantage to doing so (note that the crate name isn't camelCase, only the binary name is).


$ rustc --version
rustc 1.22.0-nightly (05f8ddc46 2017-10-07)
A-lint C-feature-request

Most helpful comment

Policy should apply to executables and cdylib's alike.

It would also be great if you could turn off #[warn(non_snake_case)] for the crate name only. If I use #![allow(non_snake_case)] at the top-level, that disables the lint for my entire crate.

All 3 comments

I've actually been digging in to this one and would be happy to take it on, if the Rust team agrees it should happen.

Right now, building a binary passes [[bin]]::name as the --crate-name argument. I've thought of two ways of tackling this.

  1. Don't enforce the snake_case rule when building a binary
  2. Add an optional --bin-name flag which can be used for naming the resulting binary. Defaults back to --crate-name. This would require coordination with cargo.

Personally, I prefer 2.

Policy should apply to executables and cdylib's alike.

It would also be great if you could turn off #[warn(non_snake_case)] for the crate name only. If I use #![allow(non_snake_case)] at the top-level, that disables the lint for my entire crate.

Policy should apply to executables and cdylib's alike.

It would also be great if you could turn off #[warn(non_snake_case)] for the crate name only. If I use #![allow(non_snake_case)] at the top-level, that disables the lint for my entire crate.

Agree, is there way to disable this warning for crate name while cargo build?

Was this page helpful?
0 / 5 - 0 ratings