CodeSampleX

示例

serde 1.0.229: serde deny_unknown_fields stops rejecting unknown keys once the struct is flattened, while the pair the documentation calls unsupported compiles and works in the ordinary case

已验证示例 — cargo serde 1.0.229: serde deny_unknown_fields stops rejecting unknown keys once the struct is flattened, while the pair the documentation calls…

sha256:0c0a0329b6b2d901cce677b9664dd22b748c2a5249af00e202c0d2e12eab06f0

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
2
构建过它的签名密钥
2
声明的环境 rust 1 linux x64 rust 1 rust cargo

验证运行环境

环境 契约 阶段 运行日期
rust 1 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1
2026-08-14
rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1
2026-08-18

案例

FIX
目标
serde deny_unknown_fields stops rejecting unknown keys once the struct is flattened, while the pair the documentation calls unsupported compiles and works in the ordinary case
符号
  • Deserialize
  • deny_unknown_fields
  • flatten
  • rename_all
  • rename_all_fields
  • default
  • skip_serializing_if
  • tag
环境
rust 1
创建时间
2026-08-14T13:02:45Z

契约

  1. assert deny_unknown_fields rejects an extra key as a Category::Data error naming the field and the accepted names
  2. assert rename_all is applied first, so the Rust field name is itself rejected as unknown
  3. assert the accepted-names list is worded three different ways depending on how many fields there are
  4. compile a probe file with rustc to prove deny_unknown_fields together with flatten emits no error and no warning, because serde_derive implements the pair rather than rejecting it
  5. compile a probe file with rustc to prove flatten on a newtype struct is the combination serde_derive does reject
  6. assert deny_unknown_fields with a flattened map rejects every key the map was supposed to collect, so only an empty map is accepted
  7. assert that rejection carries no expected-names list, unlike deny_unknown_fields on its own
  8. assert deny_unknown_fields with a flattened struct accepts the flattened fields and rejects only the leftovers
  9. assert deny_unknown_fields on a struct that is flattened into another one never rejects anything
  10. assert the key that flattened struct ignored is dropped rather than kept, so it is gone from the re-serialized output
  11. assert an Option field is filled in with None when absent, with no attribute on it
  12. assert a field that is neither Option nor defaulted is reported as a missing field
  13. assert #[serde(default)] covers an absent field but not an explicit null
  14. assert Option answers None for both absent and null, so the two cannot be told apart
  15. assert Option serializes as null rather than omitting the key
  16. assert rename_all on a struct renames its fields but not the variant values of an enum field
  17. assert rename_all on an enum renames variants and rename_all_fields is what renames their fields
  18. assert skip_serializing_if omits an Option key entirely instead of writing null
  19. assert skip_serializing_if on a non-Option field breaks the round trip with a missing field error
  20. assert an internally tagged enum reports an unknown tag with the tag values it knows
  21. assert a missing tag is reported as a missing field and an externally tagged enum names its variants
  22. assert an internally tagged enum drops unknown payload keys, and that deny_unknown_fields on the enum does fire and reject them
  23. assert that enum rejection arrives with no line and column suffix, unlike every other error here

文件

  • Cargo.lock
  • Cargo.toml
  • csx.json
  • rustc_probe/deny_unknown_with_flatten.rs
  • rustc_probe/flatten_on_newtype.rs
  • src/main.rs

下载源代码构件 (tar.gz)

原始种子者

anonymous