We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 21fdbab + 25294b7 commit 8462fdaCopy full SHA for 8462fda
crates/toml/tests/testsuite/spanned.rs
@@ -232,3 +232,30 @@ fn test_spanned_array() {
232
}
233
234
235
+
236
+#[test]
237
+fn deny_unknown_fields() {
238
+ #[derive(Debug, serde::Deserialize)]
239
+ #[serde(deny_unknown_fields)]
240
+ struct Example {
241
+ #[allow(dead_code)]
242
+ real: u32,
243
+ }
244
245
+ let error = toml::from_str::<Example>(
246
+ r#"# my comment
247
+# bla bla bla
248
+fake = 1"#,
249
+ )
250
+ .unwrap_err();
251
+ snapbox::assert_eq(
252
+ "\
253
+TOML parse error at line 3, column 1
254
+ |
255
+3 | fake = 1
256
+ | ^^^^
257
+unknown field `fake`, expected `real`
258
+",
259
+ error.to_string(),
260
+ );
261
+}
0 commit comments