From fa0312ac453372ed5dd67c2e38709bbb0d776b05 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 6 Jul 2023 15:45:53 -0700 Subject: [PATCH] More formatting of doc tests and example code --- README.md | 2 +- crates-io.md | 2 +- serde/src/de/ignored_any.rs | 5 ++--- serde/src/de/mod.rs | 9 +++------ serde/src/macros.rs | 3 +-- serde_derive/src/lib.rs | 2 +- serde_test/src/assert.rs | 19 +++++++++---------- serde_test/src/token.rs | 18 +++++++++--------- test_suite/no_std/src/main.rs | 2 +- test_suite/tests/ui/remote/missing_field.rs | 2 +- test_suite/tests/ui/remote/unknown_field.rs | 2 +- 11 files changed, 30 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index d53e5723..a049250b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ serde_json = "1.0"

```rust -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] struct Point { diff --git a/crates-io.md b/crates-io.md index 6e0ec280..18710035 100644 --- a/crates-io.md +++ b/crates-io.md @@ -16,7 +16,7 @@ You may be looking for: ## Serde in action ```rust -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] struct Point { diff --git a/serde/src/de/ignored_any.rs b/serde/src/de/ignored_any.rs index 88d4e967..9810f057 100644 --- a/serde/src/de/ignored_any.rs +++ b/serde/src/de/ignored_any.rs @@ -11,12 +11,11 @@ use de::{ /// gets deserialized. /// /// ```edition2021 -/// use std::fmt; -/// use std::marker::PhantomData; -/// /// use serde::de::{ /// self, Deserialize, DeserializeSeed, Deserializer, IgnoredAny, SeqAccess, Visitor, /// }; +/// use std::fmt; +/// use std::marker::PhantomData; /// /// /// A seed that can be used to deserialize only the `n`th element of a sequence /// /// while efficiently discarding elements of any type before or after index `n`. diff --git a/serde/src/de/mod.rs b/serde/src/de/mod.rs index 9ee6b768..a04ecf77 100644 --- a/serde/src/de/mod.rs +++ b/serde/src/de/mod.rs @@ -433,9 +433,8 @@ impl<'a> fmt::Display for Unexpected<'a> { /// (`&self`) is an implementation of this trait. /// /// ```edition2021 -/// # use std::fmt; -/// # /// # use serde::de::{self, Unexpected, Visitor}; +/// # use std::fmt; /// # /// # struct Example; /// # @@ -667,11 +666,10 @@ impl DeserializeOwned for T where T: for<'de> Deserialize<'de> {} /// trait. /// /// ```edition2021 +/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor}; /// use std::fmt; /// use std::marker::PhantomData; /// -/// use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor}; -/// /// // A DeserializeSeed implementation that uses stateful deserialization to /// // append array elements onto the end of an existing vector. The preexisting /// // state ("seed") in this case is the Vec. The `deserialize` method of @@ -1253,9 +1251,8 @@ pub trait Deserializer<'de>: Sized { /// # Example /// /// ```edition2021 -/// # use std::fmt; -/// # /// # use serde::de::{self, Unexpected, Visitor}; +/// # use std::fmt; /// # /// /// A visitor that deserializes a long string - a string containing at least /// /// some minimum number of bytes. diff --git a/serde/src/macros.rs b/serde/src/macros.rs index 53827c82..71ddc150 100644 --- a/serde/src/macros.rs +++ b/serde/src/macros.rs @@ -79,10 +79,9 @@ /// specified explicitly if necessary. /// /// ```edition2021 -/// # use std::marker::PhantomData; -/// # /// # use serde::forward_to_deserialize_any; /// # use serde::de::{value, Deserializer, Visitor}; +/// # use std::marker::PhantomData; /// # /// # struct MyDeserializer(PhantomData); /// # diff --git a/serde_derive/src/lib.rs b/serde_derive/src/lib.rs index c32f5bb6..f5ac0734 100644 --- a/serde_derive/src/lib.rs +++ b/serde_derive/src/lib.rs @@ -1,7 +1,7 @@ //! This crate provides Serde's two derive macros. //! //! ```edition2021 -//! # use serde_derive::{Serialize, Deserialize}; +//! # use serde_derive::{Deserialize, Serialize}; //! # //! #[derive(Serialize, Deserialize)] //! # struct S; diff --git a/serde_test/src/assert.rs b/serde_test/src/assert.rs index 047a9a30..ff3914a6 100644 --- a/serde_test/src/assert.rs +++ b/serde_test/src/assert.rs @@ -9,7 +9,7 @@ use std::fmt::Debug; /// Runs both `assert_ser_tokens` and `assert_de_tokens`. /// /// ```edition2021 -/// # use serde_derive::{Serialize, Deserialize}; +/// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// #[derive(Serialize, Deserialize, PartialEq, Debug)] @@ -43,7 +43,7 @@ where /// Asserts that `value` serializes to the given `tokens`. /// /// ```edition2021 -/// # use serde_derive::{Serialize, Deserialize}; +/// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_ser_tokens, Token}; /// # /// #[derive(Serialize, Deserialize, PartialEq, Debug)] @@ -85,11 +85,10 @@ where /// `error`. /// /// ```edition2021 -/// use std::sync::{Arc, Mutex}; -/// use std::thread; -/// /// use serde_derive::Serialize; /// use serde_test::{assert_ser_tokens_error, Token}; +/// use std::sync::{Arc, Mutex}; +/// use std::thread; /// /// #[derive(Serialize)] /// struct Example { @@ -102,7 +101,7 @@ where /// }; /// let lock = example.lock.clone(); /// -/// let _ = thread::spawn(move || { +/// let thread = thread::spawn(move || { /// // This thread will acquire the mutex first, unwrapping the result /// // of `lock` because the lock has not been poisoned. /// let _guard = lock.lock().unwrap(); @@ -110,8 +109,8 @@ where /// // This panic while holding the lock (`_guard` is in scope) will /// // poison the mutex. /// panic!() -/// }) -/// .join(); +/// }); +/// thread.join(); /// /// let expected = &[ /// Token::Struct { @@ -143,7 +142,7 @@ where /// Asserts that the given `tokens` deserialize into `value`. /// /// ```edition2021 -/// # use serde_derive::{Serialize, Deserialize}; +/// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_de_tokens, Token}; /// # /// #[derive(Serialize, Deserialize, PartialEq, Debug)] @@ -200,7 +199,7 @@ where /// Asserts that the given `tokens` yield `error` when deserializing. /// /// ```edition2021 -/// # use serde_derive::{Serialize, Deserialize}; +/// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_de_tokens_error, Token}; /// # /// #[derive(Serialize, Deserialize, PartialEq, Debug)] diff --git a/serde_test/src/token.rs b/serde_test/src/token.rs index b486d73d..e67093b3 100644 --- a/serde_test/src/token.rs +++ b/serde_test/src/token.rs @@ -183,7 +183,7 @@ pub enum Token { /// A serialized unit struct of the given name. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -198,7 +198,7 @@ pub enum Token { /// A unit variant of an enum. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -227,7 +227,7 @@ pub enum Token { /// After this header is the value contained in the newtype struct. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -248,7 +248,7 @@ pub enum Token { /// After this header is the value contained in the newtype variant. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -329,7 +329,7 @@ pub enum Token { /// `TupleStructEnd`. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -359,7 +359,7 @@ pub enum Token { /// `TupleVariantEnd`. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -428,7 +428,7 @@ pub enum Token { /// After this header are the fields of the struct, followed by `StructEnd`. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -463,7 +463,7 @@ pub enum Token { /// `StructVariantEnd`. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { @@ -500,7 +500,7 @@ pub enum Token { /// The header to an enum of the given name. /// /// ```edition2021 - /// # use serde_derive::{Serialize, Deserialize}; + /// # use serde_derive::{Deserialize, Serialize}; /// # use serde_test::{assert_tokens, Token}; /// # /// # fn main() { diff --git a/test_suite/no_std/src/main.rs b/test_suite/no_std/src/main.rs index deb32c5f..40f05a4d 100644 --- a/test_suite/no_std/src/main.rs +++ b/test_suite/no_std/src/main.rs @@ -19,7 +19,7 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { ////////////////////////////////////////////////////////////////////////////// -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] struct Unit; diff --git a/test_suite/tests/ui/remote/missing_field.rs b/test_suite/tests/ui/remote/missing_field.rs index e3f3ec8f..91656934 100644 --- a/test_suite/tests/ui/remote/missing_field.rs +++ b/test_suite/tests/ui/remote/missing_field.rs @@ -1,4 +1,4 @@ -use serde_derive::{Serialize, Deserialize}; +use serde_derive::{Deserialize, Serialize}; mod remote { pub struct S { diff --git a/test_suite/tests/ui/remote/unknown_field.rs b/test_suite/tests/ui/remote/unknown_field.rs index dd59cdcc..d21e7ffe 100644 --- a/test_suite/tests/ui/remote/unknown_field.rs +++ b/test_suite/tests/ui/remote/unknown_field.rs @@ -1,4 +1,4 @@ -use serde_derive::{Serialize, Deserialize}; +use serde_derive::{Deserialize, Serialize}; mod remote { pub struct S {