-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 enforce snake_case for binary names #45127
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
Personally, I prefer 2. |
Policy should apply to executables and cdylib's alike. It would also be great if you could turn off |
change rcsvRogue -> rcsv_rogue to fix warning
Agree, is there way to disable this warning for crate name while cargo build? |
This would be super simple to fix yet it is still a problem. For example on Windows it is normal to have application names with capital letters and white spaces. We shouldn't need to manually rename the build artifact, so it would be nice to have an option to set a customized artifact name for exes and dlls. |
Oh man, need this right now. Kustomize plugins look for a TitleCaseFileName. To save having to do an extra rename, I'll just live with the warnings. |
Hi @oli-obk and @Manishearth, You might be the relevant people to ask for guidance (or at least to redirect to other people). Is it possible to avoid the By build artifacts, I mean for (To me, the most important is the binary case) |
The relevant code is
I think it makes sense to avoid for bin. It's not as clear for the other two and I do not want to be the one to make that call. Make a PR, I guess? |
Thank you for the pointer! |
Also FWIW this is just a suggestion, I do not know what the opinion of the relevant teams (the compiler team) is. So they may see the PR and decide that it is not the right route. If you want to ask for a proper decision I suggest asking on the compiler team's channel on Zulip. |
I looked at the code and it's more involved than what I expected... I am taking your advice and will reach out to the compiler team on Zulip (here the thread). |
Over in #111130, @GilShoshan94 made a very good point about bad user experience when they want to create camelCase binary names but keep the lint for Rust identifiers internally.
Basically the only thing you can do right now is to disable the lint at the top module, and then re-enable it at the top of each child module. This is obviously very sub-optimal UX and doesn't cover the identifiers created at the top level. Even if we want to lint on non snake case binary names, it should be possible to disable the lint for the binary name only and not have the lint for normal rust identifiers be affected. This means that even if #111130 PR isn't chosen, one should at least address the precision issue. For example, this could happen by moving the linting into a new In general I'm in favour of #111130 though, as on windows, it makes little sense to lint, and platform specific lints aren't really nice. |
Wanting to add: this probably will be a good idea anyways because #111130 only turns off the lint for executables, and if someone wants to disable the lint for non executable crate names, they would be in the same situation. So yeah, we should split it up in any case. @workingjubilee to reply to your comment, these are the numbers of characters used in identifers in linux binary names on my local machine:
It seems to me there is a fair usage of |
@est31 I agree with you. We should have a way to turn off or on the lint only for the crate name without affecting the top level. Also we should have better default according to the different crate_types. From the available options for crate_type: Only The others: |
@GilShoshan94 agreed. I think splitting up the lint and making a lint that is for the crate name only is the best approach. |
Hi @oli-obk, You are assigned to review my PR #111130. Proposal
Where On On We should probably add a lints group called Question
|
I don't think we should have that many lints for the same thing. While we can't make lints have options (that would require its own RFC just for the ability to do that), we can have custom attributes that the lint knows about. So we could have a |
If we want to go even more general (so a solution that is not specific to the lint), we could have a |
I would be against that many lints. I think the purpose of the lint is to enforce style: first and foremost we should figure out what our style requirements are. It seems quite likely that enforcing this on binaries is not within our style needs, and not unlikely that the same is true for cdylibs and staticlibs. Once we settle on that set, those should simply not have lints: if there are people wishing to opt in to them being checked, they can file a clippy issue for a restriction lint, but let's not preemptively do work for users we are not sure exist. Basically: whatever we figure out as the final I'm not actually sure we need to worry about shallow stuff if we simply disable the lint for the three library types that have been brought up so far: it is quite reasonable for them to want to opt out; their naming is not from the Rust universe, it is from the C and universes. I think it's a valid problem to be solved, but I'm not sure we need to solve it immediately. |
The good thing with separate lints is that, together with RFC 3389, they would allow a workspace-global configuration. |
Yes, but the question remains to be answered if such a configuration is needed in the first place, and I don't want to preemptivel design for users we don't know exist. The concrete needs I see here are:
So far I have yet to see a need to disable this lint for just the artifact name for reasons other than "I am building a binary/C library which has a different naming convention". I am also yet to see if there are other artifact types that need this. |
My point earlier was that even though that the use case that made people open this issue is addressed well by #111130, one should go further than that and reconsider how it even came to that problem. In addition to merging #111130, one should try to address the useful feedback users gave about the inflexibility to configure lints. That was my earlier point. But thinking of it, the same problem also exists if you have a non-snake case module name or function name, for whatever reason. In those cases, too, you can't easily disable the lint on that level only, keeping it enabled for variables declared inside the body. Maybe, considering that this is such a general weakness, I definitely think that splitting up the lint into one for each crate type is too much. At most one would have three lints: one for non-crate names, one for crate names that are for the rust ecosystem only, and a last one that is allow by default, for externally exposed crate names. Then people creating linux-only software can disallow that lint. But IMO it occurs so rarely that people put major characters in crate names exposed to the system, one doesn't really need a lint for that only. Most linux tooling is following the convention without there being lints that enforce it. |
Thank you all for the replies. Personally, I will be happy with #111130 getting merged as it solves my issue for the |
@est31 yep Though I'm somewhat against even three lints until someone comes up with a need that they would actually wish to enable the allow-by-default lint. Two seems fine if we're not doing |
…i-obk Don't lint snake-case on executable crate name Fix rust-lang#45127 Hi, First PR on Rust, I tried my best to follow "Rust Compiler Development Guide". I tested it with a custom toolchain on a dummy bin crate with one submodule and it seems to work. The lint `non_snake_case` ignore the binary crate name but not the module name. Thank you `@Manishearth` and `@jyn514` for the guidance !
…henkov Don't lint on executable crates with `non_snake_case` names Revives rust-lang#111130, cc `@GilShoshan94.` Closes rust-lang#45127.
…nkov Don't lint on executable crates with `non_snake_case` names Revives rust-lang#111130, cc `@GilShoshan94.` Closes rust-lang#45127.
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.
…r=petrochenkov Explain why `non_snake_case` is skipped for binary crates and cleanup tests - Explain `non_snake_case` lint is skipped for bin crate names because binaries are not intended to be distributed or consumed like library crates (rust-lang#45127). - Coalesce the bunch of tests into a single one but with revisions, which is easier to compare the differences for `non_snake_case` behavior with respect to crate types. Follow-up to rust-lang#121749 with some more comments and test cleanup. cc `@saethlin` who bumped into one of the tests and was confused why it was `only-x86_64-unknown-linux-gnu`.
…r=<try> Explain why `non_snake_case` is skipped for binary crates and cleanup tests - Explain `non_snake_case` lint is skipped for bin crate names because binaries are not intended to be distributed or consumed like library crates (rust-lang#45127). - Coalesce the bunch of tests into a single one but with revisions, which is easier to compare the differences for `non_snake_case` behavior with respect to crate types. Follow-up to rust-lang#121749 with some more comments and test cleanup. cc `@saethlin` who bumped into one of the tests and was confused why it was `only-x86_64-unknown-linux-gnu`. try-job: dist-i586-gnu-i586-i686-musl
…r=petrochenkov Explain why `non_snake_case` is skipped for binary crates and cleanup tests - Explain `non_snake_case` lint is skipped for bin crate names because binaries are not intended to be distributed or consumed like library crates (rust-lang#45127). - Coalesce the bunch of tests into a single one but with revisions, which is easier to compare the differences for `non_snake_case` behavior with respect to crate types. Follow-up to rust-lang#121749 with some more comments and test cleanup. cc `@saethlin` who bumped into one of the tests and was confused why it was `only-x86_64-unknown-linux-gnu`. try-job: dist-i586-gnu-i586-i686-musl
Currently, if you have a Cargo.toml like this:
rustc will complain:
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).
The text was updated successfully, but these errors were encountered: