Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cargo:表格與鍵名一致性

摘要

  • Several table and key names in Cargo.toml have been removed where there were previously two ways to specify the same thing.
    • 已移除 [project];請改用 [package]
    • 已移除 default_features;請改用 default-features
    • 已移除 crate_type;請改用 crate-type
    • 已移除 proc_macro;請改用 proc-macro
    • 已移除 dev_dependencies;請改用 dev-dependencies
    • 已移除 build_dependencies;請改用 build-dependencies

詳情

Several table and keys names are no longer allowed in the 2024 Edition. There were two ways to specify these tables or keys, and this helps ensure there is only one way to specify them.

Some were due to a change in decisions over time, and some were inadvertent implementation artifacts. In order to avoid confusion, and to enforce a single style for specifying these tables and keys, only one variant is now allowed.

例如:

[dev_dependencies]
rand = { version = "0.8.5", default_features = false }

應該變更為:

[dev-dependencies]
rand = { version = "0.8.5", default-features = false }

Notice that the underscores were changed to dashes for dev_dependencies and default_features.

遷移

When using cargo fix --edition, Cargo will automatically update your Cargo.toml file to use the preferred table and key names.

If you prefer to update your Cargo.toml manually, be sure to go through the list above and make sure only the new forms are used.