-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Warn about crate name's format when creating new crate #12766
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
The API naming guidelines are not referenced but I think that is rightly so, since it has a lower status than an RFC. |
Just some drive-by comments: I'm reluctant to issue this warning on a binary crate, since that affects the executable name. I don't see a reason why that should be restricted, and I think it is probably wrong that rustc issues a warning for it. This doesn't seem to handle
I'm reluctant to try to duplicate what rustc is trying to do, since keeping them in sync will be challenging and cause confusion when they are out of sync. I'd like to be very careful of whether or not this is something that cargo really needs to do, since a warning will be evident on the very first build, which I think is a minor delay compared to immediately with |
@ehuss Then an alternative might be to automatically run a If I provide an empty name, this happens: $ cargo new --name '' blah
warning: compiling this new package may not work due to invalid workspace configuration
failed to parse manifest at `/Users/sanmai/blah/Cargo.toml`
Caused by:
package name cannot be an empty string
Created binary (application) `` package I don't understand why Cargo would offer such a convenience subcommand To an end user using a convenience command, degrees of invalidness are not relevant: whether it's a rustc default lint or a compilation fault. In fact, which experienced Rust developer uses |
Thinking about this and my side note, I wonder if a user-controlled warning about package names being snake or kebab case would be the right way to go, independent of rustc. Until we have #12235, we could have this be a |
Friendly ping. Do the latest changes look good? |
Somehow I overlooked this originally. Bin names should be kebab case and lib package names should be kebab or snake case. That just leaves GUI bins. That seems like a small enough of a slice that they can choose to ignore it (and in the future
I think its worthwhile, especially with this simplified form.
|
@shnaramn could you clean up the commits for how you'd like them merged? |
Warns about not using snake_case or kebab-case format when creating new packages with `cargo new` command.
337092c
to
901018c
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Update cargo 2 commits in d2f6a048529eb8e9ebc55d793abd63456c98fac2..df3509237935f9418351b77803df7bc05c009b3d 2023-10-20 18:25:30 +0000 to 2023-10-24 23:09:01 +0000 - Fix unused_imports warning (rust-lang/cargo#12876) - Warn about crate name's format when creating new crate (rust-lang/cargo#12766) r? ghost
Rollup merge of rust-lang#117150 - weihanglo:update-cargo, r=weihanglo Update cargo 2 commits in d2f6a048529eb8e9ebc55d793abd63456c98fac2..df3509237935f9418351b77803df7bc05c009b3d 2023-10-20 18:25:30 +0000 to 2023-10-24 23:09:01 +0000 - Fix unused_imports warning (rust-lang/cargo#12876) - Warn about crate name's format when creating new crate (rust-lang/cargo#12766) r? ghost
What does this PR try to resolve?
Warns about a crate's name during creation (
crate new ...
) if it doesn't follow the preferred snake_case format.Fixes #2708
The warning message uses the language mentioned in RFC 430.
How should we test and review this PR?
Verified existing tests succeeded with updates. Added new tests to verify fix.
Additional information
The link to API naming guidelines was not used since it still stays
unclear
for naming convention for crates.