From 8a5542ced61ae21d0772e504fac01bd1dbfaaa6b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 25 Feb 2024 22:11:13 -0800 Subject: [PATCH] Resolve non_local_definitions warning in test warning: non-local `impl` definition, they should be avoided as they go against expectation --> tests/test_error.rs:412:13 | 412 | / impl<'de> Visitor<'de> for X { 413 | | type Value = X; 414 | | 415 | | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { ... | 429 | | } 430 | | } | |_____________^ | = help: move this `impl` block outside the of the current associated function `deserialize` and up 2 bodies = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue = note: `#[warn(non_local_definitions)]` on by default --- tests/test_error.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/test_error.rs b/tests/test_error.rs index 6439bd42..f0fc45cf 100644 --- a/tests/test_error.rs +++ b/tests/test_error.rs @@ -404,31 +404,31 @@ fn test_billion_laughs() { #[derive(Debug)] struct X; + impl<'de> Visitor<'de> for X { + type Value = X; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("exponential blowup") + } + + fn visit_unit(self) -> Result { + Ok(X) + } + + fn visit_seq(self, mut seq: S) -> Result + where + S: SeqAccess<'de>, + { + while let Some(X) = seq.next_element()? {} + Ok(X) + } + } + impl<'de> Deserialize<'de> for X { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { - impl<'de> Visitor<'de> for X { - type Value = X; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - formatter.write_str("exponential blowup") - } - - fn visit_unit(self) -> Result { - Ok(X) - } - - fn visit_seq(self, mut seq: S) -> Result - where - S: SeqAccess<'de>, - { - while let Some(X) = seq.next_element()? {} - Ok(X) - } - } - deserializer.deserialize_any(X) } }