rust-lang / docs.rs

crates.io documentation generator
https://docs.rs
MIT License
995 stars 198 forks source link

Cargo.toml source rendered by docs.rs is inconsistent with Cargo.toml published by Cargo #2655

Open dtolnay opened 1 month ago

dtolnay commented 1 month ago

I noticed that the source code rendered by docs.rs at https://docs.rs/crate/${name}/${version}/source/Cargo.toml is different from the Cargo.toml actually in the published archive, at https://static.crates.io/crates/${name}/${version}/download. (Note: this is not a confusion between Cargo.toml vs Cargo.toml.orig.)

From skimming the code in this repo, I did not come across what is causing the contents to get mangled, so I have opened this issue to verify whether this is intentional. Naively I would expect docs.rs's source pages to be serving exactly the contents that are in the published archives.

Example

https://docs.rs/crate/unicode-ident/1.0.13/source/Cargo.toml currently shows this content:

[[bench]]
harness = false
name = "xid"
path = "benches/xid.rs"

[dev-dependencies.criterion]
default-features = false
version = "0.5"

[dev-dependencies.fst]
version = "0.4"

[dev-dependencies.rand]
features = ["small_rng"]
version = "0.8"

[dev-dependencies.roaring]
version = "0.10"

[dev-dependencies.ucd-trie]
default-features = false
version = "0.1"

[dev-dependencies.unicode-xid]
version = "0.2.4"

[lib]
doc-scrape-examples = false
name = "unicode_ident"
path = "src/lib.rs"

[package]
authors = ["David Tolnay <dtolnay@gmail.com>"]
autobenches = false
autobins = false
autoexamples = false
autotests = false
build = false
categories = ["development-tools::procedural-macro-helpers", "no-std", "no-std::no-alloc"]
description = "Determine whether characters have the XID_Start or XID_Continue properties according to Unicode Standard Annex #31"
documentation = "https://docs.rs/unicode-ident"
edition = "2018"
keywords = ["unicode", "xid"]
license = "(MIT OR Apache-2.0) AND Unicode-DFS-2016"
name = "unicode-ident"
readme = "README.md"
repository = "https://github.com/dtolnay/unicode-ident"
rust-version = "1.31"
version = "1.0.13"

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]
targets = ["x86_64-unknown-linux-gnu"]

[[test]]
name = "compare"
path = "tests/compare.rs"

[[test]]
name = "static_size"
path = "tests/static_size.rs"

However, according to curl --silent https://static.crates.io/crates/unicode-ident/1.0.13/download | tar xzO unicode-ident-1.0.13/Cargo.toml the crate contains the following different content instead. This would also be the same content found in $CARGO_HOME/registry/src/index.crates.io-6f17d22bba15001f/unicode-ident-1.0.13/Cargo.toml.

# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.

[package]
edition = "2018"
rust-version = "1.31"
name = "unicode-ident"
version = "1.0.13"
authors = ["David Tolnay <dtolnay@gmail.com>"]
build = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Determine whether characters have the XID_Start or XID_Continue properties according to Unicode Standard Annex #31"
documentation = "https://docs.rs/unicode-ident"
readme = "README.md"
keywords = [
    "unicode",
    "xid",
]
categories = [
    "development-tools::procedural-macro-helpers",
    "no-std",
    "no-std::no-alloc",
]
license = "(MIT OR Apache-2.0) AND Unicode-DFS-2016"
repository = "https://github.com/dtolnay/unicode-ident"

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]
targets = ["x86_64-unknown-linux-gnu"]

[lib]
name = "unicode_ident"
path = "src/lib.rs"
doc-scrape-examples = false

[[test]]
name = "compare"
path = "tests/compare.rs"

[[test]]
name = "static_size"
path = "tests/static_size.rs"

[[bench]]
name = "xid"
path = "benches/xid.rs"
harness = false

[dev-dependencies.criterion]
version = "0.5"
default-features = false

[dev-dependencies.fst]
version = "0.4"

[dev-dependencies.rand]
version = "0.8"
features = ["small_rng"]

[dev-dependencies.roaring]
version = "0.10"

[dev-dependencies.ucd-trie]
version = "0.1"
default-features = false

[dev-dependencies.unicode-xid]
version = "0.2.4"

The TOML data structure is the same but docs.rs has seemingly alphabetized the content, and also stripped the comment block that had been inserted by Cargo.

syphar commented 4 weeks ago

Hi @dtolnay , thank you for the report!

My hunch is that this is related to the toml-tweaker in the rustwide library we and crater are using.

That being said, I think the source we upload and render in docs.rs should not include the tweaked toml, but the one from the archive.

I can dig deeper this week