Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Resolve non_local_definitions warning in test
Browse files Browse the repository at this point in the history
    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 <rust-lang/rust#120363>
        = note: `#[warn(non_local_definitions)]` on by default
  • Loading branch information
dtolnay committed Feb 26, 2024
1 parent ea57d8c commit 8a5542c
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions tests/test_error.rs
Expand Up @@ -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<E>(self) -> Result<X, E> {
Ok(X)
}

fn visit_seq<S>(self, mut seq: S) -> Result<X, S::Error>
where
S: SeqAccess<'de>,
{
while let Some(X) = seq.next_element()? {}
Ok(X)
}
}

impl<'de> Deserialize<'de> for X {
fn deserialize<D>(deserializer: D) -> Result<X, D::Error>
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<E>(self) -> Result<X, E> {
Ok(X)
}

fn visit_seq<S>(self, mut seq: S) -> Result<X, S::Error>
where
S: SeqAccess<'de>,
{
while let Some(X) = seq.next_element()? {}
Ok(X)
}
}

deserializer.deserialize_any(X)
}
}
Expand Down

0 comments on commit 8a5542c

Please sign in to comment.