bors ecb89a1a4e Auto merge of #13606 - dvdhrm:pr/initlib, r=weihanglo
cargo/init: avoid target.name assignments if possible

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.

Fixes: #11259
2024-03-19 15:39:48 +00:00
..