Common causes
1. The same key written twice in a table
Bumping a version or a setting by adding a new line instead of editing the old one is the usual source. Keep one line.
[project]
version = "1.2.0"
name = "invoice-tool"
version = "1.3.0"[project]
version = "1.3.0"
name = "invoice-tool"2. A dotted key that extends a plain value
server = "web-1" makes server a string, so server.port cannot add a key to it. Turn server into a table and give the old value its own key.
server = "web-1"
server.port = 80server.name = "web-1"
server.port = 803. Bare and quoted spellings of the same key
Quotes do not change a key: name and "name" are identical, so the second line redefines the first. Keys are case-sensitive, so Name would be a different key.
name = "invoice-tool"
"name" = "invoice-cli"name = "invoice-cli"4. A key that also appears inside an inline table
Inline tables are complete when they close. Adding a key to owner afterwards, with a dotted key or a section, redefines it. Put every key in the inline table or switch to a [owner] section.
owner = { name = "Ada" }
owner.email = "ada@example.com"owner = { name = "Ada", email = "ada@example.com" }Frequently asked questions
Why does TOML reject duplicates when JSON allows them?
TOML was designed to map unambiguously to a hash table, so the spec explicitly says defining a key multiple times is invalid. That makes config errors visible instead of silently keeping one value.
Where does Cargo report the duplicate?
Cargo prints “TOML parse error at line N, column M” with the offending line, followed by “duplicate key name in table package”. The line shown is the second definition.
Is the same key allowed in different tables?
Yes. version under [project] and version under [tool.poetry] are separate keys because they live in different tables.