-
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
cargo/init: avoid target.name assignments if possible #13606
Conversation
Make `cargo init` skip `target.name` assignments if the default value is suitable. Currently, all paths of `cargo init` will set target-names to the package-name, ensuring that a suitable target-name is set. This is required for all targets but libraries. Unfortunately, library-names have more restrictions than other targets. For example, creating a library with dashes will lead to errors: mkdir foo-bar cd foo-bar touch foo-bar.rs cargo init --lib Fortunately, target-names for libraries are inferred from the package-name. Hence, by omitting the target-name, a valid configuration will be produced. Instead of adjusting `SourceFileInformation::target_name` to use `Option<String>`, this commit strips the field completely, since all callers set it to the package-name. Signed-off-by: David Rheinsberg <david@readahead.eu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense. Thanks!
@bors r+ |
☀️ Test successful - checks-actions |
Update cargo 5 commits in 2fe739fcf16c5bf8c2064ab9d357f4a0e6c8539b..d438c80c45c24be676ef5867edc79d0a14910efe 2024-03-15 21:39:18 +0000 to 2024-03-19 16:11:22 +0000 - refactor(toml): Expose surce/spans for VirtualManifests (rust-lang/cargo#13603) - cargo/init: avoid target.name assignments if possible (rust-lang/cargo#13606) - chore: Fix minor grammar nit in command-line help (rust-lang/cargo#13602) - Bump to 0.80.0; update changelog (rust-lang/cargo#13604) - cargo: prevent dashes in lib.name (rust-lang/cargo#12783) r? ghost
Note for the change: While I understand people may use |
Make
cargo init
skiptarget.name
assignments if the default value is suitable.Currently, all paths of
cargo init
will set target-names to the package-name, ensuring that a suitable target-name is set. This is required for all targets but libraries. Unfortunately, library-names have more restrictions than other targets. For example, creating a library with dashes will lead to errors:Fortunately, target-names for libraries are inferred from the package-name. Hence, by omitting the target-name, a valid configuration will be produced.
Instead of adjusting
SourceFileInformation::target_name
to useOption<String>
, this commit strips the field completely, since all callers set it to the package-name.Fixes: #11259