Skip to content

Commit

Permalink
Run clippy on rustdoc tests (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed May 6, 2024
2 parents 117549f + d0439d9 commit d7f84dd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions serde_with/src/de/mod.rs
Expand Up @@ -72,7 +72,7 @@ use crate::prelude::*;
/// This shows a simplified implementation for [`DisplayFromStr`].
///
/// ```rust
/// # #[cfg(all(feature = "macros"))] {
/// # #[cfg(feature = "macros")] {
/// # use serde::Deserialize;
/// # use serde::de::Error;
/// # use serde_with::{serde_as, DeserializeAs};
Expand All @@ -98,7 +98,7 @@ use crate::prelude::*;
/// # #[derive(serde::Deserialize)]
/// # struct S (#[serde_as(as = "DisplayFromStr")] bool);
/// #
/// # assert_eq!(false, serde_json::from_str::<S>(r#""false""#).unwrap().0);
/// # assert!(!serde_json::from_str::<S>(r#""false""#).unwrap().0);
/// # }
/// ```
/// [`Box`]: std::boxed::Box
Expand Down
4 changes: 2 additions & 2 deletions serde_with/src/hex.rs
Expand Up @@ -72,11 +72,11 @@ use crate::prelude::*;
/// [u8; 12]
/// );
///
/// let b = b"Hello World!";
/// let b = *b"Hello World!";
///
/// assert_eq!(
/// json!("48656c6c6f20576f726c6421"),
/// serde_json::to_value(ByteArray(b.clone())).unwrap()
/// serde_json::to_value(ByteArray(b)).unwrap()
/// );
///
/// // Serialization always work from lower- and uppercase characters, even mixed case.
Expand Down
45 changes: 25 additions & 20 deletions serde_with/src/lib.rs
@@ -1,7 +1,12 @@
#![doc(test(attr(
// Problematic handling for foreign From<T> impls in tests
// https://github.com/rust-lang/rust/issues/121621
allow(unknown_lints, non_local_definitions),
allow(
unknown_lints,
// Problematic handling for foreign From<T> impls in tests
// https://github.com/rust-lang/rust/issues/121621
non_local_definitions,
// Some tests use foo as name
clippy::disallowed_names,
),
deny(
missing_debug_implementations,
rust_2018_idioms,
Expand Down Expand Up @@ -97,7 +102,7 @@
//! {"bar": "12"}
//! # "#;
//! # assert_eq!(json.replace(" ", "").replace("\n", ""), serde_json::to_string(&foo).unwrap());
//! # assert_eq!(foo, serde_json::from_str(&json).unwrap());
//! # assert_eq!(foo, serde_json::from_str(json).unwrap());
//! # }
//! ```
//!
Expand Down Expand Up @@ -181,7 +186,7 @@
//! {"d": 4, "g": 7}
//! # "#;
//! # assert_eq!(json.replace(" ", "").replace("\n", ""), serde_json::to_string(&foo).unwrap());
//! # assert_eq!(foo, serde_json::from_str(&json).unwrap());
//! # assert_eq!(foo, serde_json::from_str(json).unwrap());
//! # }
//! ```
//!
Expand Down Expand Up @@ -232,7 +237,7 @@
//! }
//! # "#;
//! # assert_eq!(json.replace(" ", "").replace("\n", ""), serde_json::to_string(&foo).unwrap());
//! # assert_eq!(foo, serde_json::from_str(&json).unwrap());
//! # assert_eq!(foo, serde_json::from_str(json).unwrap());
//!
//! // and serializes
//! # let foo =
Expand All @@ -257,7 +262,7 @@
//! }
//! # "#;
//! # assert_eq!(json.replace(" ", "").replace("\n", ""), serde_json::to_string(&foo).unwrap());
//! # assert_eq!(foo, serde_json::from_str(&json).unwrap());
//! # assert_eq!(foo, serde_json::from_str(json).unwrap());
//! # }
//! ```
//!
Expand Down Expand Up @@ -532,7 +537,7 @@ pub struct Same;
/// mime: mime::STAR_STAR,
/// number: 777,
/// };
/// assert_eq!(json!({ "mime": "*/*", "number": "777" }), serde_json::to_value(&x).unwrap());
/// assert_eq!(json!({ "mime": "*/*", "number": "777" }), serde_json::to_value(x).unwrap());
/// # }
/// ```
///
Expand Down Expand Up @@ -612,12 +617,12 @@ pub struct IfIsHumanReadable<H, F = Same>(PhantomData<H>, PhantomData<F>);
/// let x = A {
/// tags: Some("This is text".to_string()),
/// };
/// assert_eq!(json!({ "tags": "This is text" }), serde_json::to_value(&x).unwrap());
/// assert_eq!(json!({ "tags": "This is text" }), serde_json::to_value(x).unwrap());
///
/// let x = A {
/// tags: None,
/// };
/// assert_eq!(json!({ "tags": "" }), serde_json::to_value(&x).unwrap());
/// assert_eq!(json!({ "tags": "" }), serde_json::to_value(x).unwrap());
/// # }
/// ```
///
Expand Down Expand Up @@ -879,7 +884,7 @@ pub struct BytesOrString;
/// "d_f64": 12346.0,
/// "d_string": "12346",
/// });
/// assert_eq!(expected, serde_json::to_value(&d).unwrap());
/// assert_eq!(expected, serde_json::to_value(d).unwrap());
///
/// // Deserialization works too
/// // Subsecond precision in numbers will be rounded away
Expand Down Expand Up @@ -937,7 +942,7 @@ pub struct BytesOrString;
/// "d_f64": -12345.0,
/// "d_string": "12346",
/// });
/// assert_eq!(expected, serde_json::to_value(&d).unwrap());
/// assert_eq!(expected, serde_json::to_value(d).unwrap());
///
/// // Deserialization works too
/// // Subsecond precision in numbers will be rounded away
Expand Down Expand Up @@ -1021,7 +1026,7 @@ pub struct DurationSeconds<
/// "d_f64": 12345.5,
/// "d_string": "12345.999999",
/// });
/// assert_eq!(expected, serde_json::to_value(&d).unwrap());
/// assert_eq!(expected, serde_json::to_value(d).unwrap());
///
/// // Deserialization works too
/// // Subsecond precision in numbers will be rounded away
Expand Down Expand Up @@ -1072,7 +1077,7 @@ pub struct DurationSeconds<
/// "d_f64": -12344.5,
/// "d_string": "12345.999999",
/// });
/// assert_eq!(expected, serde_json::to_value(&d).unwrap());
/// assert_eq!(expected, serde_json::to_value(d).unwrap());
///
/// // Deserialization works too
///
Expand Down Expand Up @@ -1211,7 +1216,7 @@ pub struct DurationNanoSecondsWithFrac<
/// "st_f64": 12346.0,
/// "st_string": "12346",
/// });
/// assert_eq!(expected, serde_json::to_value(&ts).unwrap());
/// assert_eq!(expected, serde_json::to_value(ts).unwrap());
///
/// // Deserialization works too
/// // Subsecond precision in numbers will be rounded away
Expand Down Expand Up @@ -1269,7 +1274,7 @@ pub struct DurationNanoSecondsWithFrac<
/// "dt_f64": -12345.0,
/// "dt_string": "12346",
/// });
/// assert_eq!(expected, serde_json::to_value(&ts).unwrap());
/// assert_eq!(expected, serde_json::to_value(ts).unwrap());
///
/// // Deserialization works too
/// // Subsecond precision in numbers will be rounded away
Expand Down Expand Up @@ -1361,7 +1366,7 @@ pub struct TimestampSeconds<
/// "st_f64": 12345.5,
/// "st_string": "12345.999999",
/// });
/// assert_eq!(expected, serde_json::to_value(&ts).unwrap());
/// assert_eq!(expected, serde_json::to_value(ts).unwrap());
///
/// // Deserialization works too
/// // Subsecond precision in numbers will be rounded away
Expand Down Expand Up @@ -1412,7 +1417,7 @@ pub struct TimestampSeconds<
/// "dt_f64": -12344.5,
/// "dt_string": "12345.999999",
/// });
/// assert_eq!(expected, serde_json::to_value(&ts).unwrap());
/// assert_eq!(expected, serde_json::to_value(ts).unwrap());
///
/// // Deserialization works too
///
Expand Down Expand Up @@ -1534,7 +1539,7 @@ pub struct TimestampNanoSecondsWithFrac<
/// }
///
/// let value = Test {
/// array: b"0123456789ABCDE".clone(),
/// array: *b"0123456789ABCDE",
/// boxed: b"...".to_vec().into_boxed_slice(),
/// cow: Cow::Borrowed(b"FooBar"),
/// cow_array: Cow::Borrowed(&[42u8; 15]),
Expand All @@ -1551,7 +1556,7 @@ pub struct TimestampNanoSecondsWithFrac<
/// # let pretty_config = ron::ser::PrettyConfig::new()
/// # .new_line("\n".into());
/// assert_eq!(expected, ron::ser::to_string_pretty(&value, pretty_config).unwrap());
/// assert_eq!(value, ron::from_str(&expected).unwrap());
/// assert_eq!(value, ron::from_str(expected).unwrap());
/// # }
/// ```
///
Expand Down
2 changes: 1 addition & 1 deletion serde_with/src/ser/mod.rs
Expand Up @@ -73,7 +73,7 @@ use crate::prelude::*;
/// This shows a simplified implementation for [`DisplayFromStr`].
///
/// ```rust
/// # #[cfg(all(feature = "macros"))] {
/// # #[cfg(feature = "macros")] {
/// # use serde_with::{serde_as, SerializeAs};
/// # use std::fmt::Display;
/// struct DisplayFromStr;
Expand Down
2 changes: 1 addition & 1 deletion serde_with_macros/src/lib.rs
Expand Up @@ -1323,7 +1323,7 @@ pub fn __private_consume_serde_as_attributes(_: TokenStream) -> TokenStream {
/// {
/// "always_serialize_this_field": null
/// }
/// # ), serde_json::to_value(&data).unwrap());
/// # ), serde_json::to_value(data).unwrap());
/// ```
///
/// # Alternative path to `serde_with` crate
Expand Down

0 comments on commit d7f84dd

Please sign in to comment.