Repository: jonasbb/serde_with
Pull request #88 (2020-02-29 14:24:32)

Upgrade to 2018 edition

codecov[bot]: # [Codecov](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=h1) Report
> Merging [#88](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=desc) into [master](https://codecov.io/gh/jonasbb/serde_with/commit/92b885def2f118783bb02859730f82795eaae7dd?src=pr&el=desc) will **decrease** coverage by `3.4%`.
> The diff coverage is `7.14%`.

[![Impacted file tree graph](https://codecov.io/gh/jonasbb/serde_with/pull/88/graphs/tree.svg?width=650&token=DoaDtevgcY&height=150&src=pr)](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
- Coverage   72.46%   69.06%   -3.41%     
==========================================
  Files          15       14       -1     
  Lines         770      750      -20     
==========================================
- Hits          558      518      -40     
- Misses        212      232      +20
```


| [Impacted Files](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tests/rust.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-dGVzdHMvcnVzdC5ycw==) | `99.19% <ø> (ø)` | :arrow_up: |
| [serde\_with\_macros/src/lib.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c2VyZGVfd2l0aF9tYWNyb3Mvc3JjL2xpYi5ycw==) | `0% <ø> (ø)` | :arrow_up: |
| [tests/version\_numbers.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-dGVzdHMvdmVyc2lvbl9udW1iZXJzLnJz) | `100% <ø> (ø)` | :arrow_up: |
| [src/lib.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c3JjL2xpYi5ycw==) | `25% <ø> (ø)` | :arrow_up: |
| [serde\_with\_macros/tests/compiler-messages.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c2VyZGVfd2l0aF9tYWNyb3MvdGVzdHMvY29tcGlsZXItbWVzc2FnZXMucnM=) | `60% <ø> (ø)` | :arrow_up: |
| [src/chrono.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c3JjL2Nocm9uby5ycw==) | `0% <ø> (-50.88%)` | :arrow_down: |
| [tests/with\_prefix.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-dGVzdHMvd2l0aF9wcmVmaXgucnM=) | `100% <ø> (ø)` | :arrow_up: |
| [serde\_with\_macros/tests/skip\_serializing\_null.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c2VyZGVfd2l0aF9tYWNyb3MvdGVzdHMvc2tpcF9zZXJpYWxpemluZ19udWxsLnJz) | `100% <ø> (ø)` | :arrow_up: |
| [serde\_with\_macros/tests/version\_numbers.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c2VyZGVfd2l0aF9tYWNyb3MvdGVzdHMvdmVyc2lvbl9udW1iZXJzLnJz) | `100% <ø> (ø)` | :arrow_up: |
| [src/with\_prefix.rs](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree#diff-c3JjL3dpdGhfcHJlZml4LnJz) | `55.39% <0%> (ø)` | :arrow_up: |
| ... and [5 more](https://codecov.io/gh/jonasbb/serde_with/pull/88/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=footer). Last update [92b885d...8b05ec9](https://codecov.io/gh/jonasbb/serde_with/pull/88?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48776fc..ba408dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+### Changed
+
+* Convert the code to use 2018 edition.
+
 ## [1.4.0]
 
 ### Added
@@ -18,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 ### Changed
 
 * Bump minimal Rust version to 1.36.0
-    * Support Rust Edition 2018
+    * Supports Rust Edition 2018
     * version-sync depends on smallvec which requires 1.36
 * Improved CI pipeline by running `cargo audit` and `tarpaulin` in all configurations now.
 
diff --git a/Cargo.toml b/Cargo.toml
index a29c4ec..af8618d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,12 +8,14 @@ name = "serde_with"
 version = "1.4.0"
 authors = ["jonasbb"]
 
+categories = ["encoding"]
 description = "Custom de/serialization functions for Rust's serde"
 documentation = "https://docs.rs/serde_with/"
-repository = "https://github.com/jonasbb/serde_with"
-readme = "README.md"
+edition = "2018"
 keywords = ["serde", "utilities", "serialization", "deserialization"]
 license = "MIT OR Apache-2.0"
+readme = "README.md"
+repository = "https://github.com/jonasbb/serde_with"
 
 exclude = [
     ".codecov.yml",
@@ -32,12 +34,13 @@ codecov = { repository = "jonasbb/serde_with", branch = "master", service = "git
 maintenance = { status = "actively-developed" }
 
 [features]
+chrono = [ "chrono_crate" ]
 default = [ "macros" ]
 json = [ "serde_json" ]
 macros = [ "serde_with_macros" ]
 
 [dependencies]
-chrono = { version = "0.4.1", features = [ "serde" ], optional = true }
+chrono_crate = { package = "chrono", version = "0.4.1", features = [ "serde" ], optional = true }
 serde = "1.0.75"
 serde_json = { version = "1.0.1", optional = true }
 serde_with_macros = { path = "./serde_with_macros", version = "1.1.0", optional = true}
diff --git a/serde_with_macros/CHANGELOG.md b/serde_with_macros/CHANGELOG.md
index 19b0947..3ff8209 100644
--- a/serde_with_macros/CHANGELOG.md
+++ b/serde_with_macros/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+### Changed
+
+* Convert the code to use 2018 edition.
+
 ## [1.1.0]
 
 ### Changed
diff --git a/serde_with_macros/Cargo.toml b/serde_with_macros/Cargo.toml
index 0fc3631..771099a 100644
--- a/serde_with_macros/Cargo.toml
+++ b/serde_with_macros/Cargo.toml
@@ -3,12 +3,14 @@ name = "serde_with_macros"
 version = "1.1.0"
 authors = ["jonasbb"]
 
+categories = ["encoding"]
 description = "proc-macro library for serde_with"
 documentation = "https://docs.rs/serde_with_macros/"
-repository = "https://github.com/jonasbb/serde_with/tree/master/serde_with_macros"
-readme = "README.md"
+edition = "2018"
 keywords = ["serde", "utilities", "serialization", "deserialization"]
 license = "MIT OR Apache-2.0"
+readme = "README.md"
+repository = "https://github.com/jonasbb/serde_with/tree/master/serde_with_macros"
 
 [lib]
 proc-macro = true
diff --git a/serde_with_macros/src/lib.rs b/serde_with_macros/src/lib.rs
index 3975aff..6435e5b 100644
--- a/serde_with_macros/src/lib.rs
+++ b/serde_with_macros/src/lib.rs
@@ -1,6 +1,6 @@
 #![deny(
-    missing_debug_implementations,
     missing_copy_implementations,
+    missing_debug_implementations,
     trivial_casts,
     trivial_numeric_casts,
     unused_extern_crates,
@@ -8,7 +8,20 @@
     unused_qualifications,
     variant_size_differences
 )]
-#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
+#![warn(rust_2018_idioms)]
+#![doc(test(attr(deny(
+    missing_copy_implementations,
+    missing_debug_implementations,
+    trivial_casts,
+    trivial_numeric_casts,
+    unused_extern_crates,
+    unused_import_braces,
+    unused_qualifications,
+    variant_size_differences,
+))))]
+#![doc(test(attr(warn(rust_2018_idioms))))]
+// Not needed for 2018 edition and conflicts with `rust_2018_idioms`
+#![doc(test(no_crate_inject))]
 #![doc(html_root_url = "https://docs.rs/serde_with_macros/1.1.0")]
 
 //! proc-macro extensions for [`serde_with`]
@@ -17,10 +30,8 @@
 //!
 //! [`serde_with`]: https://crates.io/crates/serde_with/
 
+#[allow(unused_extern_crates)]
 extern crate proc_macro;
-extern crate proc_macro2;
-extern crate quote;
-extern crate syn;
 
 use proc_macro::TokenStream;
 use proc_macro2::Span;
@@ -43,7 +54,6 @@ use syn::{
 /// Such a data type might look like:
 ///
 /// ```rust
-/// # extern crate serde;
 /// # use serde::Serialize;
 /// #
 /// #[derive(Serialize)]
@@ -63,9 +73,6 @@ use syn::{
 /// Instead the same struct can be written as:
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_with_macros;
-/// #
 /// # use serde::Serialize;
 /// # use serde_with_macros::skip_serializing_none;
 /// #[skip_serializing_none]
@@ -92,9 +99,6 @@ use syn::{
 /// This cannot be supported, as proc-macros run before type checking, thus it is not possible to determine if a type alias refers to an [`Option`].
 ///
 /// ```rust,ignore
-/// # extern crate serde;
-/// # extern crate serde_with_macros;
-/// #
 /// # use serde::Serialize;
 /// # use serde_with_macros::skip_serializing_none;
 /// type MyOption<T> = Option<T>;
@@ -110,9 +114,6 @@ use syn::{
 /// Here the function `Vec::is_none` does not exist and therefore the example fails to compile.
 ///
 /// ```rust,compile_fail
-/// # extern crate serde;
-/// # extern crate serde_with_macros;
-/// #
 /// # use serde::Serialize;
 /// # use serde_with_macros::skip_serializing_none;
 /// use std::vec::Vec as Option;
@@ -173,12 +174,12 @@ fn is_std_option(path: &Path) -> bool {
 ///
 /// On the example of
 /// `#[serde(skip_serializing_if = "Option::is_none")]`
-//
+///
 /// * `serde` is the outermost path, here namespace
 /// * it contains a Meta::List
 /// * which contains in another Meta a Meta::NameValue
 /// * with the name being `skip_serializing_if`
-#[cfg_attr(feature = "cargo-clippy", allow(cmp_owned))]
+#[allow(clippy::cmp_owned)]
 fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool {
     // On the example of
     // #[serde(skip_serializing_if = "Option::is_none")]
diff --git a/src/chrono.rs b/src/chrono.rs
index ea0118d..be1da48 100644
--- a/src/chrono.rs
+++ b/src/chrono.rs
@@ -11,14 +11,8 @@
 /// # Examples
 ///
 /// ```
-/// # extern crate chrono;
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
-/// # use chrono::{DateTime, Utc};
-/// # use serde_derive::{Deserialize, Serialize};
+/// # use chrono_crate::{DateTime, Utc};
+/// # use serde_derive::Deserialize;
 /// #
 /// #[derive(Debug, Deserialize)]
 /// struct S {
@@ -47,7 +41,7 @@ pub mod datetime_utc_ts_seconds_from_any {
         impl<'de> Visitor<'de> for Helper {
             type Value = DateTime<Utc>;
 
-            fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+            fn expecting(&self, formatter: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
                 formatter.write_str("Invalid timestamp. Must be an integer, float, or string with optional subsecond precision.")
             }
 
diff --git a/src/flatten_maybe.rs b/src/flatten_maybe.rs
index 6ea64ed..dadeb5b 100644
--- a/src/flatten_maybe.rs
+++ b/src/flatten_maybe.rs
@@ -12,11 +12,6 @@
 /// # Examples
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_json;
-/// # #[macro_use]
-/// # extern crate serde_with;
-/// #
 /// # use serde::Deserialize;
 /// #
 /// // Setup the types
@@ -33,7 +28,7 @@
 ///
 /// // The macro creates custom deserialization code.
 /// // You need to specify a function name and the field name of the flattened field.
-/// flattened_maybe!(deserialize_t, "t");
+/// serde_with::flattened_maybe!(deserialize_t, "t");
 ///
 ///
 /// # fn main() {
diff --git a/src/json.rs b/src/json.rs
index 9123713..335505a 100644
--- a/src/json.rs
+++ b/src/json.rs
@@ -7,11 +7,6 @@
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// #
 /// #[derive(Deserialize, Serialize)]
@@ -38,7 +33,6 @@ pub mod nested {
         de::{DeserializeOwned, Deserializer, Error, Visitor},
         ser::{self, Serialize, Serializer},
     };
-    use serde_json;
     use std::{fmt, marker::PhantomData};
 
     /// Deserialize value from a string which is valid JSON
@@ -56,7 +50,7 @@ pub mod nested {
         {
             type Value = S;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 write!(formatter, "valid json object")
             }
 
diff --git a/src/lib.rs b/src/lib.rs
index e153418..c63fdc6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,6 @@
 #![deny(
-    missing_debug_implementations,
     missing_copy_implementations,
+    missing_debug_implementations,
     missing_docs,
     trivial_casts,
     trivial_numeric_casts,
@@ -9,7 +9,20 @@
     unused_qualifications,
     variant_size_differences
 )]
-#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
+#![warn(rust_2018_idioms)]
+#![doc(test(attr(deny(
+    missing_copy_implementations,
+    missing_debug_implementations,
+    trivial_casts,
+    trivial_numeric_casts,
+    unused_extern_crates,
+    unused_import_braces,
+    unused_qualifications,
+    variant_size_differences,
+))))]
+#![doc(test(attr(warn(rust_2018_idioms))))]
+// Not needed for 2018 edition and conflicts with `rust_2018_idioms`
+#![doc(test(no_crate_inject))]
 #![doc(html_root_url = "https://docs.rs/serde_with/1.4.0")]
 
 //! [![docs.rs badge](https://docs.rs/serde_with/badge.svg)](https://docs.rs/serde_with/)
@@ -39,9 +52,6 @@
 //! Annotate your struct or enum to enable the custom de/serializer.
 //!
 //! ```rust
-//! # extern crate serde;
-//! # extern crate serde_derive;
-//! # extern crate serde_with;
 //! # use serde_derive::{Deserialize, Serialize};
 //! #[derive(Deserialize, Serialize)]
 //! struct Foo {
@@ -56,9 +66,6 @@
 //! If you want to mix different helpers, you can write your annotations like
 //!
 //! ```rust
-//! # extern crate serde;
-//! # extern crate serde_derive;
-//! # extern crate serde_with;
 //! # use serde_derive::{Deserialize, Serialize};
 //! # #[cfg(feature = "json")]
 //! #[derive(Deserialize, Serialize)]
@@ -82,14 +89,8 @@
 //! [with-annotation]: https://serde.rs/field-attrs.html#with
 //! [serde#553]: https://github.com/serde-rs/serde/issues/553
 
-#[cfg(feature = "chrono")]
-extern crate chrono as chrono_crate;
 #[doc(hidden)]
 pub extern crate serde;
-#[cfg(feature = "json")]
-extern crate serde_json;
-#[cfg(feature = "macros")]
-extern crate serde_with_macros;
 
 #[cfg(feature = "chrono")]
 pub mod chrono;
diff --git a/src/rust.rs b/src/rust.rs
index 3a984ed..15ec862 100644
--- a/src/rust.rs
+++ b/src/rust.rs
@@ -1,5 +1,6 @@
 //! De/Serialization for Rust's builtin and std types
 
+use crate::Separator;
 use serde::{
     de::{Deserialize, DeserializeOwned, Deserializer, Error, MapAccess, SeqAccess, Visitor},
     ser::{Serialize, SerializeMap, SerializeSeq, Serializer},
@@ -13,7 +14,6 @@ use std::{
     marker::PhantomData,
     str::FromStr,
 };
-use Separator;
 
 /// De/Serialize using [`Display`] and [`FromStr`] implementation
 ///
@@ -24,11 +24,6 @@ use Separator;
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// # use std::net::Ipv4Addr;
 /// #
@@ -73,7 +68,7 @@ pub mod display_fromstr {
         {
             type Value = S;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 write!(formatter, "valid json object")
             }
 
@@ -105,11 +100,6 @@ pub mod display_fromstr {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// #
 /// use std::collections::BTreeSet;
@@ -174,7 +164,7 @@ pub mod seq_display_fromstr {
         {
             type Value = Vec<S>;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 write!(formatter, "a sequence")
             }
 
@@ -227,11 +217,6 @@ pub mod seq_display_fromstr {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// #
 /// use serde_with::{CommaSeparator, SpaceSeparator};
@@ -319,11 +304,6 @@ where
 /// # Examples
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// #
 /// # #[derive(Debug, PartialEq, Eq)]
@@ -351,7 +331,7 @@ where
 /// assert_eq!(Doc {a: Some(Some(5))}, serde_json::from_str(s).unwrap());
 /// assert_eq!(s, serde_json::to_string(&Doc {a: Some(Some(5))}).unwrap());
 /// ```
-#[cfg_attr(feature = "cargo-clippy", allow(option_option))]
+#[allow(clippy::option_option)]
 pub mod double_option {
     use super::*;
 
@@ -395,12 +375,6 @@ pub mod double_option {
 /// # Example
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// # extern crate ron;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// #
 /// # #[derive(Debug, Eq, PartialEq)]
@@ -489,13 +463,8 @@ pub mod unwrap_or_skip {
 /// # Example
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use std::{collections::HashSet, iter::FromIterator};
-/// # use serde_derive::{Deserialize, Serialize};
+/// # use serde_derive::Deserialize;
 /// #
 /// # #[derive(Debug, Eq, PartialEq)]
 /// #[derive(Deserialize)]
@@ -518,7 +487,7 @@ pub mod unwrap_or_skip {
 /// ```
 pub mod sets_duplicate_value_is_error {
     use super::*;
-    use duplicate_key_impls::PreventDuplicateInsertsSet;
+    use crate::duplicate_key_impls::PreventDuplicateInsertsSet;
 
     /// Deserialize a set and return an error on duplicate values
     pub fn deserialize<'de, D, T, V>(deserializer: D) -> Result<T, D::Error>
@@ -539,7 +508,7 @@ pub mod sets_duplicate_value_is_error {
         {
             type Value = T;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 formatter.write_str("a sequence")
             }
 
@@ -584,12 +553,7 @@ pub mod sets_duplicate_value_is_error {
 /// # Example
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
-/// # use serde_derive::{Deserialize, Serialize};
+/// # use serde_derive::Deserialize;
 /// # use std::collections::HashMap;
 /// #
 /// # #[derive(Debug, Eq, PartialEq)]
@@ -616,7 +580,7 @@ pub mod sets_duplicate_value_is_error {
 /// ```
 pub mod maps_duplicate_key_is_error {
     use super::*;
-    use duplicate_key_impls::PreventDuplicateInsertsMap;
+    use crate::duplicate_key_impls::PreventDuplicateInsertsMap;
 
     /// Deserialize a map and return an error on duplicate keys
     pub fn deserialize<'de, D, T, K, V>(deserializer: D) -> Result<T, D::Error>
@@ -640,7 +604,7 @@ pub mod maps_duplicate_key_is_error {
         {
             type Value = T;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 formatter.write_str("a map")
             }
 
@@ -681,7 +645,7 @@ pub mod maps_duplicate_key_is_error {
 /// [`BTreeSet`]: std::collections::HashSet
 pub mod sets_first_value_wins {
     use super::*;
-    use duplicate_key_impls::DuplicateInsertsFirstWinsSet;
+    use crate::duplicate_key_impls::DuplicateInsertsFirstWinsSet;
 
     /// Deserialize a set and return an error on duplicate values
     pub fn deserialize<'de, D, T, V>(deserializer: D) -> Result<T, D::Error>
@@ -702,7 +666,7 @@ pub mod sets_first_value_wins {
         {
             type Value = T;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 formatter.write_str("a sequence")
             }
 
@@ -742,12 +706,7 @@ pub mod sets_first_value_wins {
 /// # Example
 ///
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
-/// # use serde_derive::{Deserialize, Serialize};
+/// # use serde_derive::Deserialize;
 /// # use std::collections::HashMap;
 /// #
 /// # #[derive(Debug, Eq, PartialEq)]
@@ -778,7 +737,7 @@ pub mod sets_first_value_wins {
 /// ```
 pub mod maps_first_key_wins {
     use super::*;
-    use duplicate_key_impls::DuplicateInsertsFirstWinsMap;
+    use crate::duplicate_key_impls::DuplicateInsertsFirstWinsMap;
 
     /// Deserialize a map and return an error on duplicate keys
     pub fn deserialize<'de, D, T, K, V>(deserializer: D) -> Result<T, D::Error>
@@ -802,7 +761,7 @@ pub mod maps_first_key_wins {
         {
             type Value = T;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 formatter.write_str("a map")
             }
 
@@ -838,11 +797,6 @@ pub mod maps_first_key_wins {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// #
 /// #[derive(Deserialize, Serialize)]
@@ -889,7 +843,7 @@ pub mod string_empty_as_none {
         {
             type Value = Option<S>;
 
-            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+            fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                 formatter.write_str("any string")
             }
 
@@ -952,11 +906,6 @@ pub mod string_empty_as_none {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// # use serde_json::json;
 /// # use std::collections::HashMap;
@@ -981,12 +930,6 @@ pub mod string_empty_as_none {
 /// The helper is generic over the hasher type of the [`HashMap`] and works with different variants, such as `FnvHashMap`.
 ///
 /// ```
-/// # extern crate fnv;
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// # use serde_json::json;
 /// #
@@ -1037,7 +980,7 @@ pub mod hashmap_as_tuple_list {
         deserializer.deserialize_seq(HashMapVisitor(PhantomData))
     }
 
-    #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
+    #[allow(clippy::type_complexity)]
     struct HashMapVisitor<K, V, BH>(PhantomData<fn() -> HashMap<K, V, BH>>);
 
     impl<'de, K, V, BH> Visitor<'de> for HashMapVisitor<K, V, BH>
@@ -1048,7 +991,7 @@ pub mod hashmap_as_tuple_list {
     {
         type Value = HashMap<K, V, BH>;
 
-        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
             formatter.write_str("a list of key-value pairs")
         }
 
@@ -1079,11 +1022,6 @@ pub mod hashmap_as_tuple_list {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
 /// # use serde_json::json;
 /// # use std::collections::BTreeMap;
@@ -1131,7 +1069,7 @@ pub mod btreemap_as_tuple_list {
         deserializer.deserialize_seq(BTreeMapVisitor(PhantomData))
     }
 
-    #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
+    #[allow(clippy::type_complexity)]
     struct BTreeMapVisitor<K, V>(PhantomData<fn() -> BTreeMap<K, V>>);
 
     impl<'de, K, V> Visitor<'de> for BTreeMapVisitor<K, V>
@@ -1141,7 +1079,7 @@ pub mod btreemap_as_tuple_list {
     {
         type Value = BTreeMap<K, V>;
 
-        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
             formatter.write_str("a list of key-value pairs")
         }
 
@@ -1172,13 +1110,7 @@ pub mod btreemap_as_tuple_list {
 /// `Wrapper` does not implement [`Hash`] nor [`Ord`], thus prohibiting the use [`HashMap`] or [`BTreeMap`].
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
-/// # use serde_json::json;
 /// #
 /// #[derive(Debug, Deserialize, Serialize, Default)]
 /// struct S {
@@ -1213,13 +1145,7 @@ pub mod btreemap_as_tuple_list {
 /// In this example, the serialized format contains duplicate keys, which is not supported with [`HashMap`] or [`BTreeMap`].
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
-/// # use serde_json::json;
 /// #
 /// #[derive(Debug, Deserialize, Serialize, PartialEq, Default)]
 /// struct S {
@@ -1275,7 +1201,7 @@ pub mod tuple_list_as_map {
         deserializer.deserialize_map(MapVisitor(PhantomData))
     }
 
-    #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
+    #[allow(clippy::type_complexity)]
     struct MapVisitor<I, K, V>(PhantomData<fn() -> (I, K, V)>);
 
     impl<'de, I, K, V> Visitor<'de> for MapVisitor<I, K, V>
@@ -1286,7 +1212,7 @@ pub mod tuple_list_as_map {
     {
         type Value = I;
 
-        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
             formatter.write_str("a map")
         }
 
@@ -1327,13 +1253,7 @@ pub mod tuple_list_as_map {
 ///
 /// # Example
 /// ```rust
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::{Deserialize, Serialize};
-/// # use serde_json::json;
 /// #
 /// #[derive(Debug, Deserialize, Serialize, PartialEq, Default)]
 /// struct S {
@@ -1387,7 +1307,7 @@ pub mod bytes_or_string {
     impl<'de> Visitor<'de> for BytesOrStringVisitor {
         type Value = Vec<u8>;
 
-        fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
             formatter.write_str("a list of bytes or a string")
         }
 
@@ -1429,11 +1349,6 @@ pub mod bytes_or_string {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::Deserialize;
 /// #
 /// #[derive(Deserialize)]
@@ -1460,11 +1375,6 @@ pub mod bytes_or_string {
 /// Deserializing missing values can be supported by adding the `default` field attribute:
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::Deserialize;
 /// #
 /// #[derive(Deserialize)]
@@ -1498,11 +1408,6 @@ pub mod default_on_error {
 /// # Examples
 ///
 /// ```
-/// # extern crate serde;
-/// # extern crate serde_derive;
-/// # extern crate serde_json;
-/// # extern crate serde_with;
-/// #
 /// # use serde_derive::Deserialize;
 /// #
 /// #[derive(Deserialize)]
diff --git a/src/with_prefix.rs b/src/with_prefix.rs
index 776927d..a80fbc3 100644
--- a/src/with_prefix.rs
+++ b/src/with_prefix.rs
@@ -35,11 +35,13 @@ use serde::{
 /// structs, rather than repeating the fields of `Player` for each prefix.
 ///
 /// ```rust
+/// # #[allow(dead_code)]
 /// struct Match {
 ///     player1: Player,
 ///     player2: Player,
 /// }
 ///
+/// # #[allow(dead_code)]
 /// struct Player {
 ///     name: String,
 ///     votes: u64,
@@ -51,12 +53,7 @@ use serde::{
 /// An implementation of the Challonge API would use `with_prefix!` like this:
 ///
 /// ```rust
-/// extern crate serde_derive;
-/// extern crate serde_json;
-/// extern crate serde_with;
-///
 /// use serde_derive::{Deserialize, Serialize};
-/// use serde_json::json;
 /// use serde_with::with_prefix;
 ///
 /// #[derive(Serialize, Deserialize)]
@@ -469,7 +466,7 @@ where
 {
     type Value = V::Value;
 
-    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.delegate.expecting(formatter)
     }
 
@@ -525,7 +522,7 @@ where
 {
     type Value = V::Value;
 
-    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+    fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
         self.delegate.expecting(formatter)
     }
 


Test patch:
diff --git a/serde_with_macros/tests/compile-fail/skip-none-always.rs b/serde_with_macros/tests/compile-fail/skip-none-always.rs
index b522724..c279454 100644
--- a/serde_with_macros/tests/compile-fail/skip-none-always.rs
+++ b/serde_with_macros/tests/compile-fail/skip-none-always.rs
@@ -1,6 +1,3 @@
-extern crate serde;
-extern crate serde_with_macros;
-
 use serde::Serialize;
 use serde_with_macros::skip_serializing_none;
 
diff --git a/serde_with_macros/tests/compile-fail/skip-none-always.stderr b/serde_with_macros/tests/compile-fail/skip-none-always.stderr
index 226d7b5..9085228 100644
--- a/serde_with_macros/tests/compile-fail/skip-none-always.stderr
+++ b/serde_with_macros/tests/compile-fail/skip-none-always.stderr
@@ -1,17 +1,23 @@
 error: The attributes `serialize_always` and `serde(skip_serializing_if = "...")` cannot be used on the same field: `a`.
- --> $DIR/skip-none-always.rs:7:1
+ --> $DIR/skip-none-always.rs:4:1
   |
-7 | #[skip_serializing_none]
+4 | #[skip_serializing_none]
   | ^^^^^^^^^^^^^^^^^^^^^^^^
+  |
+  = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: The attributes `serialize_always` and `serde(skip_serializing_if = "...")` cannot be used on the same field.
-  --> $DIR/skip-none-always.rs:15:1
+  --> $DIR/skip-none-always.rs:12:1
    |
-15 | #[skip_serializing_none]
+12 | #[skip_serializing_none]
    | ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: `serialize_always` may only be used on fields of type `Option`.
-  --> $DIR/skip-none-always.rs:23:1
+  --> $DIR/skip-none-always.rs:20:1
    |
-23 | #[skip_serializing_none]
+20 | #[skip_serializing_none]
    | ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/serde_with_macros/tests/compile-fail/skip-none-not-struct.rs b/serde_with_macros/tests/compile-fail/skip-none-not-struct.rs
index f6776db..314fb64 100644
--- a/serde_with_macros/tests/compile-fail/skip-none-not-struct.rs
+++ b/serde_with_macros/tests/compile-fail/skip-none-not-struct.rs
@@ -1,5 +1,3 @@
-extern crate serde_with_macros;
-
 use serde_with_macros::skip_serializing_none;
 
 #[skip_serializing_none]
diff --git a/serde_with_macros/tests/compile-fail/skip-none-not-struct.stderr b/serde_with_macros/tests/compile-fail/skip-none-not-struct.stderr
index 479fa7e..767bab4 100644
--- a/serde_with_macros/tests/compile-fail/skip-none-not-struct.stderr
+++ b/serde_with_macros/tests/compile-fail/skip-none-not-struct.stderr
@@ -1,5 +1,7 @@
 error: The attribute can only be applied to struct or enum definitions.
- --> $DIR/skip-none-not-struct.rs:5:1
+ --> $DIR/skip-none-not-struct.rs:3:1
   |
-5 | #[skip_serializing_none]
+3 | #[skip_serializing_none]
   | ^^^^^^^^^^^^^^^^^^^^^^^^
+  |
+  = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/serde_with_macros/tests/compiler-messages.rs b/serde_with_macros/tests/compiler-messages.rs
index 01373a3..7ee3fa5 100644
--- a/serde_with_macros/tests/compiler-messages.rs
+++ b/serde_with_macros/tests/compiler-messages.rs
@@ -1,6 +1,3 @@
-extern crate rustversion;
-extern crate trybuild;
-
 // This test fails for older compiler versions since the error messages are different.
 #[rustversion::attr(before(1.35), ignore)]
 #[test]
diff --git a/serde_with_macros/tests/skip_serializing_null.rs b/serde_with_macros/tests/skip_serializing_null.rs
index 7fb43bc..9d0488f 100644
--- a/serde_with_macros/tests/skip_serializing_null.rs
+++ b/serde_with_macros/tests/skip_serializing_null.rs
@@ -1,8 +1,3 @@
-extern crate pretty_assertions;
-extern crate serde;
-extern crate serde_json;
-extern crate serde_with_macros;
-
 use pretty_assertions::assert_eq;
 use serde::{Deserialize, Serialize};
 use serde_json::json;
diff --git a/serde_with_macros/tests/version_numbers.rs b/serde_with_macros/tests/version_numbers.rs
index 9cbd3b3..9f1d04a 100644
--- a/serde_with_macros/tests/version_numbers.rs
+++ b/serde_with_macros/tests/version_numbers.rs
@@ -1,5 +1,3 @@
-extern crate version_sync;
-
 #[test]
 fn test_html_root_url() {
     version_sync::assert_html_root_url_updated!("src/lib.rs");
diff --git a/tests/chrono.rs b/tests/chrono.rs
index e20106e..a084b08 100644
--- a/tests/chrono.rs
+++ b/tests/chrono.rs
@@ -1,13 +1,6 @@
 #![cfg(feature = "chrono")]
 
-extern crate chrono;
-extern crate pretty_assertions;
-extern crate serde;
-extern crate serde_derive;
-extern crate serde_json;
-extern crate serde_with;
-
-use chrono::{DateTime, NaiveDateTime, Utc};
+use chrono_crate::{DateTime, NaiveDateTime, Utc};
 use pretty_assertions::assert_eq;
 use serde_derive::Deserialize;
 
diff --git a/tests/rust.rs b/tests/rust.rs
index cd317c6..82c2552 100644
--- a/tests/rust.rs
+++ b/tests/rust.rs
@@ -1,10 +1,3 @@
-extern crate fnv;
-extern crate pretty_assertions;
-extern crate serde;
-extern crate serde_derive;
-extern crate serde_json;
-extern crate serde_with;
-
 use fnv::FnvHashMap;
 use pretty_assertions::assert_eq;
 use serde_derive::{Deserialize, Serialize};
diff --git a/tests/version_numbers.rs b/tests/version_numbers.rs
index fa24ed0..1cf9bee 100644
--- a/tests/version_numbers.rs
+++ b/tests/version_numbers.rs
@@ -1,5 +1,3 @@
-extern crate version_sync;
-
 use version_sync::{
     assert_contains_regex, assert_html_root_url_updated, assert_markdown_deps_updated,
 };
diff --git a/tests/with_prefix.rs b/tests/with_prefix.rs
index b1113b7..4bf1c16 100644
--- a/tests/with_prefix.rs
+++ b/tests/with_prefix.rs
@@ -1,9 +1,3 @@
-extern crate pretty_assertions;
-extern crate serde;
-extern crate serde_derive;
-extern crate serde_json;
-extern crate serde_with;
-
 use pretty_assertions::assert_eq;
 use serde_derive::{Deserialize, Serialize};
 use serde_json::json;