Skip to content

cargo init no longer handles pre-existing source files nicely #3722

Closed
@vi

Description

#3004 broken it a bit.

Previously Cargo looked for files like main.rs, src/main.rs, lib.rs, src/lib.rs, projectname.rs and src/projectname.rs and created [[bin]] and/or [lib] sections in Cargo.toml automatically if source files located unusually.

Now it does look for those files, but fails to use this information meaningfully and just creates src/main.rs or src/lib.rs instead of using sections in Cargo.toml even if a usable source file outside src already exists, making the "hello world" lib or app while previously it used pre-existing source code.

What shall be done? Options:

  • Remove any auto-detection code. Rely only on explicit --lib/--bin. Don't look at any files except of src/{main,lib}.rs
  • Implement insertion of [[bin]] and [lib] again (when --template is not in use)
  • Make Cargo move pre-existing source file to the appropriate location in cargo init, e.g myapp/myapp.rs becomes myapp/src/main.rs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions