Repository navigation
cargo/init: avoid target.name assignments if possible - #13606
Merged
Merged
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 <[email protected]>
Collaborator
Member
|
@bors r+ |
Contributor
Contributor
Contributor
|
☀️ Test successful - checks-actions |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 20, 2024
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
Member
|
Note for the change: While I understand people may use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make
cargo initskiptarget.nameassignments if the default value is suitable.Currently, all paths of
cargo initwill 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_nameto useOption<String>, this commit strips the field completely, since all callers set it to the package-name.Fixes: #11259