Cargo: package.metadata is not recognized when in quotes

Created on 27 Oct 2019  路  2Comments  路  Source: rust-lang/cargo

Problem

My Cargo.toml contains:

[features]
feature1 = []

["package.metadata.docs.rs"]
features = ["feature1"]

When I run cargo build, it outputs:

warning: unused manifest key: package.metadata.docs.rs

Also, when publishing the crate, cargo seems to remove the metadata section completely from the published Cargo.toml.


Steps

  1. Create a new library crate.
  2. Add the text from the block above to Cargo.toml.
  3. Run cargo build.

Possible Solution(s)
The issue seems to be caused by quotes in ["package.metadata.docs.rs"]. If I replace it with [package.metadata.docs.rs], the warning goes away (but metadata is still removed from published Cargo.toml).

It seems that quotes should be supported by cargo. For example, replacing [package] with ["package"] in Cargo.toml doesn't prevent cargo from parsing it.

My Cargo.toml is generated using toml crate, so I don't have an easy way to remove the quotes.


Notes

Output of cargo version: cargo 1.38.0 (23ef9a4ef 2019-08-20)


C-bug

All 2 comments

That is how TOML works. [package.metadata] specifies a table called metadata in the table called package, and ["package.metadata"] specifies a table called "package.metadata".

["package.metadata.docs.rs"] doesn't mean the same thing as [package.metadata.docs.rs]. The latter creates a hierarchical set of keys, package = { metadata = { docs = { rs = ... } } } }. The former creates a single key whose name includes dots, "package.metadata.docs.rs" = .... That isn't a key under package.metadata, so cargo doesn't treat it as metadata.

Was this page helpful?
0 / 5 - 0 ratings