Skip to content

cargo init --bin creates a lib crate when crate source file is present #9333

Closed
@BartMassey

Description

@BartMassey

Problem

cargo init has a nice feature, in that if the file foo.rs exists in the directory foo that is being initialized, no src directory will be created and instead name = "foo" and path = "foo.rs" will be placed in Cargo.toml.

Unfortunately, cargo init --bin still produces a lib crate in this case.

Steps

  1. mkdir foo
  2. cd foo
  3. touch foo.rs
  4. cargo init --bin

The resulting Cargo.toml is

[package]
name = "foo"
version = "0.1.0"
authors = ["Me <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[lib]
name = "foo"
path = "foo.rs"

I would strongly prefer getting [[bin]] instead of [lib] here.

Notes

Output of cargo version: cargo 1.51.0 (43b129a20 2021-03-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions