How to Update the Cargo.toml for Rustlings Exercises: A Complete Guide

Run rustlings dev update to automatically regenerate the [[bin]] table in your Cargo.toml whenever you add, remove, or rename exercises.

The rust-lang/rustlings repository uses a dynamic exercise system where each lesson is a separate binary target. To keep the project buildable, you must update the Cargo.toml for Rustlings exercises whenever the exercise list changes. The project provides dedicated tooling to handle this automatically without manual editing of the manifest.

Why the Cargo.toml Needs Updating

Rustlings stores the list of executable exercises in the [[bin]] table of its Cargo.toml manifest. Each entry maps a binary name to its source file path:

[[bin]]
name = "intro1"
path = "exercises/00_intro/intro1.rs"

When you add, remove, or rename an exercise, this table becomes out of sync. If you attempt to run cargo run or the rustlings binary without updating the manifest, Cargo will fail to discover the new binaries or will throw errors about missing source files.

Using the Built-in Update Command

The rustlings dev update Command

The project provides a built-in tool that regenerates the bin list automatically. Execute this command from the root of your Rustlings repository:

rustlings dev update

If you are developing Rustlings itself (working on the rust-lang/rustlings source code), use the debug build instead:

cargo dev update

What Happens Under the Hood

The update command follows a precise pipeline defined in the source code:

  1. Parse info.toml – The command reads the exercise metadata from info.toml (or a community repository's info.toml). Each entry is deserialized into the ExerciseInfo struct defined in src/dev/info_file.rs.

  2. Generate a fresh manifest fragment – The function updated_cargo_toml in src/cargo_toml.rs constructs a new [[bin]] array based on the current set of exercises discovered in the previous step.

  3. Write the updated manifest – The logic in src/dev/update.rs::update_cargo_toml overwrites the appropriate file. For user-installed Rustlings, this is the workspace root Cargo.toml. When developing Rustlings itself, it updates dev/Cargo.toml.

When to Update the Cargo.toml

You must update the Cargo.toml for Rustlings exercises in the following situations:

Situation Command Affected File
Adding a new exercise to your own repository rustlings dev update Cargo.toml at repository root
Developing Rustlings itself (adding official exercises) cargo dev update dev/Cargo.toml
Manually editing info.toml (renaming or removing exercises) Same as above Corresponding manifest

If you attempt to verify your exercises with rustlings dev check while the manifest is outdated, the tool will emit a specific warning:

"The file Cargo.toml is outdated. Run rustlings dev update to update it."

This check is implemented in src/dev/check.rs.

Manual Edits vs. Auto-Generated Sections

Only the [[bin]] list is managed automatically. You may safely edit any other section of Cargo.toml (such as adding dependencies or configuring lints), and the update command will preserve those changes while rewriting only the bin array.

Typical manual additions that persist across updates include:

[dependencies]
serde = "1.0"

[lints.rust]
unsafe_code = "forbid"

The generation logic in src/cargo_toml.rs specifically handles this preservation, ensuring that manual configuration is not clobbered when the exercise list changes.

Verifying Your Cargo.toml is Current

Before committing changes or running exercises, verify that your manifest is synchronized:

rustlings dev check

This command compares the current info.toml against the [[bin]] entries in Cargo.toml. If they differ, it reports which exercises are missing or extraneous and reminds you to run rustlings dev update.

Summary

  • Update the Cargo.toml for Rustlings exercises by running rustlings dev update whenever you modify the exercise list in info.toml.
  • The command regenerates only the [[bin]] section in src/dev/update.rs, parsing exercise metadata via src/dev/info_file.rs and generating the manifest fragment in src/cargo_toml.rs.
  • Manual edits to dependencies and lint configurations are preserved across updates.
  • Use rustlings dev check to verify the manifest is synchronized before building.

Frequently Asked Questions

What happens if I don't update the Cargo.toml after adding an exercise?

Cargo will fail to compile the new exercise because the [[bin]] table in Cargo.toml will not contain an entry mapping the exercise name to its source file path. Running rustlings dev check will detect this mismatch and warn you that the manifest is outdated.

Can I manually edit the bin section of the Cargo.toml?

While technically possible, manual edits to the [[bin]] section are discouraged because they will be overwritten the next time you run rustlings dev update. The tool is designed to be the single source of truth for the exercise list, deriving it from info.toml to prevent synchronization errors.

How do I update the Cargo.toml when developing Rustlings itself?

When contributing to the official rust-lang/rustlings repository, use cargo dev update instead of rustlings dev update. This command updates dev/Cargo.toml rather than the workspace root manifest, ensuring the development environment stays in sync with the official exercise list.

Will manual dependencies be preserved when running rustlings dev update?

Yes. The update logic in src/cargo_toml.rs specifically preserves any sections outside of the [[bin]] array. You can safely add custom dependencies, lint rules, or profile configurations to Cargo.toml, and rustlings dev update will retain them while only regenerating the exercise binary list.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →