Skip to content

Commit 4bbdeb3

Browse files
committed
Define a separate local Place type per Deserialize impl
Fixes warning about non_local_definitions. warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:21:9 | 21 | / impl Visitor for Place<()> { 22 | | fn null(&mut self) -> Result<()> { 23 | | self.out = Some(()); 24 | | Ok(()) 25 | | } 26 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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 warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:33:9 | 33 | / impl Visitor for Place<bool> { 34 | | fn boolean(&mut self, b: bool) -> Result<()> { 35 | | self.out = Some(b); 36 | | Ok(()) 37 | | } 38 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:45:9 | 45 | / impl Visitor for Place<String> { 46 | | fn string(&mut self, s: &str) -> Result<()> { 47 | | self.out = Some(s.to_owned()); 48 | | Ok(()) 49 | | } 50 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:59:17 | 59 | / impl Visitor for Place<$ty> { 60 | | fn negative(&mut self, n: i64) -> Result<()> { 61 | | if n >= $ty::min_value() as i64 { 62 | | self.out = Some(n as $ty); ... | 76 | | } 77 | | } | |_________________^ ... 83 | signed!(i8); | ----------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `signed` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:59:17 | 59 | / impl Visitor for Place<$ty> { 60 | | fn negative(&mut self, n: i64) -> Result<()> { 61 | | if n >= $ty::min_value() as i64 { 62 | | self.out = Some(n as $ty); ... | 76 | | } 77 | | } | |_________________^ ... 84 | signed!(i16); | ------------ in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `signed` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:59:17 | 59 | / impl Visitor for Place<$ty> { 60 | | fn negative(&mut self, n: i64) -> Result<()> { 61 | | if n >= $ty::min_value() as i64 { 62 | | self.out = Some(n as $ty); ... | 76 | | } 77 | | } | |_________________^ ... 85 | signed!(i32); | ------------ in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `signed` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:59:17 | 59 | / impl Visitor for Place<$ty> { 60 | | fn negative(&mut self, n: i64) -> Result<()> { 61 | | if n >= $ty::min_value() as i64 { 62 | | self.out = Some(n as $ty); ... | 76 | | } 77 | | } | |_________________^ ... 86 | signed!(i64); | ------------ in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `signed` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:59:17 | 59 | / impl Visitor for Place<$ty> { 60 | | fn negative(&mut self, n: i64) -> Result<()> { 61 | | if n >= $ty::min_value() as i64 { 62 | | self.out = Some(n as $ty); ... | 76 | | } 77 | | } | |_________________^ ... 87 | signed!(isize); | -------------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `signed` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:93:17 | 93 | / impl Visitor for Place<$ty> { 94 | | fn nonnegative(&mut self, n: u64) -> Result<()> { 95 | | if n <= $ty::max_value() as u64 { 96 | | self.out = Some(n as $ty); ... | 101 | | } 102 | | } | |_________________^ ... 108 | unsigned!(u8); | ------------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `unsigned` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:93:17 | 93 | / impl Visitor for Place<$ty> { 94 | | fn nonnegative(&mut self, n: u64) -> Result<()> { 95 | | if n <= $ty::max_value() as u64 { 96 | | self.out = Some(n as $ty); ... | 101 | | } 102 | | } | |_________________^ ... 109 | unsigned!(u16); | -------------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `unsigned` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:93:17 | 93 | / impl Visitor for Place<$ty> { 94 | | fn nonnegative(&mut self, n: u64) -> Result<()> { 95 | | if n <= $ty::max_value() as u64 { 96 | | self.out = Some(n as $ty); ... | 101 | | } 102 | | } | |_________________^ ... 110 | unsigned!(u32); | -------------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `unsigned` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:93:17 | 93 | / impl Visitor for Place<$ty> { 94 | | fn nonnegative(&mut self, n: u64) -> Result<()> { 95 | | if n <= $ty::max_value() as u64 { 96 | | self.out = Some(n as $ty); ... | 101 | | } 102 | | } | |_________________^ ... 111 | unsigned!(u64); | -------------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `unsigned` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:93:17 | 93 | / impl Visitor for Place<$ty> { 94 | | fn nonnegative(&mut self, n: u64) -> Result<()> { 95 | | if n <= $ty::max_value() as u64 { 96 | | self.out = Some(n as $ty); ... | 101 | | } 102 | | } | |_________________^ ... 112 | unsigned!(usize); | ---------------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `unsigned` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:118:17 | 118 | / impl Visitor for Place<$ty> { 119 | | fn negative(&mut self, n: i64) -> Result<()> { 120 | | self.out = Some(n as $ty); 121 | | Ok(()) ... | 132 | | } 133 | | } | |_________________^ ... 139 | float!(f32); | ----------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `float` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:118:17 | 118 | / impl Visitor for Place<$ty> { 119 | | fn negative(&mut self, n: i64) -> Result<()> { 120 | | self.out = Some(n as $ty); 121 | | Ok(()) ... | 132 | | } 133 | | } | |_________________^ ... 140 | float!(f64); | ----------- in this macro invocation | = help: move this `impl` block outside the of the current associated function `begin` = 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: this warning originates in the macro `float` (in Nightly builds, run with -Z macro-backtrace for more info) warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:144:9 | 144 | / impl<T: Deserialize> Visitor for Place<Box<T>> { 145 | | fn null(&mut self) -> Result<()> { 146 | | let mut out = None; 147 | | Deserialize::begin(&mut out).null()?; ... | 205 | | } 206 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:270:9 | 270 | / impl<T: Deserialize> Visitor for Place<Option<T>> { 271 | | fn null(&mut self) -> Result<()> { 272 | | self.out = Some(None); 273 | | Ok(()) ... | 309 | | } 310 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:318:9 | 318 | / impl<A: Deserialize, B: Deserialize> Visitor for Place<(A, B)> { 319 | | fn seq(&mut self) -> Result<Box<dyn Seq + '_>> { 320 | | Ok(Box::new(TupleBuilder { 321 | | out: &mut self.out, ... | 324 | | } 325 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:359:9 | 359 | / impl<T: Deserialize> Visitor for Place<Vec<T>> { 360 | | fn seq(&mut self) -> Result<Box<dyn Seq + '_>> { 361 | | Ok(Box::new(VecBuilder { 362 | | out: &mut self.out, ... | 366 | | } 367 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:402:9 | 402 | / impl<T: Deserialize, const N: usize> Visitor for Place<[T; N]> { 403 | | fn seq(&mut self) -> Result<Box<dyn Seq + '_>> { 404 | | Ok(Box::new(ArrayBuilder { 405 | | out: &mut self.out, ... | 410 | | } 411 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:472:9 | 472 | / impl<K, V, H> Visitor for Place<HashMap<K, V, H>> 473 | | where 474 | | K: FromStr + Hash + Eq, 475 | | V: Deserialize, ... | 485 | | } 486 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/de/impls.rs:532:9 | 532 | / impl<K: FromStr + Ord, V: Deserialize> Visitor for Place<BTreeMap<K, V>> { 533 | | fn map(&mut self) -> Result<Box<dyn Map + '_>> { 534 | | Ok(Box::new(MapBuilder { 535 | | out: &mut self.out, ... | 540 | | } 541 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/json/value.rs:75:9 | 75 | / impl Visitor for Place<Value> { 76 | | fn null(&mut self) -> Result<()> { 77 | | self.out = Some(Value::Null); 78 | | Ok(()) ... | 121 | | } 122 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/json/number.rs:37:9 | 37 | / impl Visitor for Place<Number> { 38 | | fn negative(&mut self, n: i64) -> Result<()> { 39 | | self.out = Some(Number::I64(n)); 40 | | Ok(()) ... | 51 | | } 52 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/json/array.rs:116:9 | 116 | / impl Visitor for Place<Array> { 117 | | fn seq(&mut self) -> Result<Box<dyn Seq + '_>> { 118 | | Ok(Box::new(ArrayBuilder { 119 | | out: &mut self.out, ... | 123 | | } 124 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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> warning: non-local `impl` definition, they should be avoided as they go against expectation --> src/json/object.rs:119:9 | 119 | / impl Visitor for Place<Object> { 120 | | fn map(&mut self) -> Result<Box<dyn Map + '_>> { 121 | | Ok(Box::new(ObjectBuilder { 122 | | out: &mut self.out, ... | 127 | | } 128 | | } | |_________^ | = help: move this `impl` block outside the of the current associated function `begin` = 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>
1 parent d9faf43 commit 4bbdeb3

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

src/de/impls.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::de::{Deserialize, Map, Seq, Visitor};
22
use crate::error::{Error, Result};
33
use crate::ignore::Ignore;
44
use crate::ptr::NonuniqueBox;
5-
use crate::Place;
65
use alloc::borrow::ToOwned;
76
use alloc::boxed::Box;
87
use alloc::collections::BTreeMap;
@@ -18,36 +17,45 @@ use std::hash::{BuildHasher, Hash};
1817

1918
impl Deserialize for () {
2019
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
20+
make_place!(Place);
21+
2122
impl Visitor for Place<()> {
2223
fn null(&mut self) -> Result<()> {
2324
self.out = Some(());
2425
Ok(())
2526
}
2627
}
28+
2729
Place::new(out)
2830
}
2931
}
3032

3133
impl Deserialize for bool {
3234
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35+
make_place!(Place);
36+
3337
impl Visitor for Place<bool> {
3438
fn boolean(&mut self, b: bool) -> Result<()> {
3539
self.out = Some(b);
3640
Ok(())
3741
}
3842
}
43+
3944
Place::new(out)
4045
}
4146
}
4247

4348
impl Deserialize for String {
4449
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50+
make_place!(Place);
51+
4552
impl Visitor for Place<String> {
4653
fn string(&mut self, s: &str) -> Result<()> {
4754
self.out = Some(s.to_owned());
4855
Ok(())
4956
}
5057
}
58+
5159
Place::new(out)
5260
}
5361
}
@@ -56,6 +64,8 @@ macro_rules! signed {
5664
($ty:ident) => {
5765
impl Deserialize for $ty {
5866
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
67+
make_place!(Place);
68+
5969
impl Visitor for Place<$ty> {
6070
fn negative(&mut self, n: i64) -> Result<()> {
6171
if n >= $ty::min_value() as i64 {
@@ -75,6 +85,7 @@ macro_rules! signed {
7585
}
7686
}
7787
}
88+
7889
Place::new(out)
7990
}
8091
}
@@ -90,6 +101,8 @@ macro_rules! unsigned {
90101
($ty:ident) => {
91102
impl Deserialize for $ty {
92103
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
104+
make_place!(Place);
105+
93106
impl Visitor for Place<$ty> {
94107
fn nonnegative(&mut self, n: u64) -> Result<()> {
95108
if n <= $ty::max_value() as u64 {
@@ -100,6 +113,7 @@ macro_rules! unsigned {
100113
}
101114
}
102115
}
116+
103117
Place::new(out)
104118
}
105119
}
@@ -115,6 +129,8 @@ macro_rules! float {
115129
($ty:ident) => {
116130
impl Deserialize for $ty {
117131
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
132+
make_place!(Place);
133+
118134
impl Visitor for Place<$ty> {
119135
fn negative(&mut self, n: i64) -> Result<()> {
120136
self.out = Some(n as $ty);
@@ -131,6 +147,7 @@ macro_rules! float {
131147
Ok(())
132148
}
133149
}
150+
134151
Place::new(out)
135152
}
136153
}
@@ -141,6 +158,8 @@ float!(f64);
141158

142159
impl<T: Deserialize> Deserialize for Box<T> {
143160
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
161+
make_place!(Place);
162+
144163
impl<T: Deserialize> Visitor for Place<Box<T>> {
145164
fn null(&mut self) -> Result<()> {
146165
let mut out = None;
@@ -266,7 +285,10 @@ impl<T: Deserialize> Deserialize for Option<T> {
266285
fn default() -> Option<Self> {
267286
Some(None)
268287
}
288+
269289
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
290+
make_place!(Place);
291+
270292
impl<T: Deserialize> Visitor for Place<Option<T>> {
271293
fn null(&mut self) -> Result<()> {
272294
self.out = Some(None);
@@ -315,6 +337,8 @@ impl<T: Deserialize> Deserialize for Option<T> {
315337

316338
impl<A: Deserialize, B: Deserialize> Deserialize for (A, B) {
317339
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
340+
make_place!(Place);
341+
318342
impl<A: Deserialize, B: Deserialize> Visitor for Place<(A, B)> {
319343
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
320344
Ok(Box::new(TupleBuilder {
@@ -356,6 +380,8 @@ impl<A: Deserialize, B: Deserialize> Deserialize for (A, B) {
356380

357381
impl<T: Deserialize> Deserialize for Vec<T> {
358382
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
383+
make_place!(Place);
384+
359385
impl<T: Deserialize> Visitor for Place<Vec<T>> {
360386
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
361387
Ok(Box::new(VecBuilder {
@@ -399,6 +425,8 @@ impl<T: Deserialize> Deserialize for Vec<T> {
399425

400426
impl<T: Deserialize, const N: usize> Deserialize for [T; N] {
401427
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
428+
make_place!(Place);
429+
402430
impl<T: Deserialize, const N: usize> Visitor for Place<[T; N]> {
403431
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
404432
Ok(Box::new(ArrayBuilder {
@@ -469,6 +497,8 @@ where
469497
H: BuildHasher + Default,
470498
{
471499
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
500+
make_place!(Place);
501+
472502
impl<K, V, H> Visitor for Place<HashMap<K, V, H>>
473503
where
474504
K: FromStr + Hash + Eq,
@@ -529,6 +559,8 @@ where
529559

530560
impl<K: FromStr + Ord, V: Deserialize> Deserialize for BTreeMap<K, V> {
531561
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
562+
make_place!(Place);
563+
532564
impl<K: FromStr + Ord, V: Deserialize> Visitor for Place<BTreeMap<K, V>> {
533565
fn map(&mut self) -> Result<Box<dyn Map + '_>> {
534566
Ok(Box::new(MapBuilder {

src/json/array.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::error::Result;
33
use crate::json::{drop, Value};
44
use crate::private;
55
use crate::ser::{Fragment, Serialize};
6-
use crate::Place;
76
use alloc::boxed::Box;
87
use alloc::vec::Vec;
98
use core::fmt::{self, Debug};
@@ -113,6 +112,8 @@ impl Serialize for Array {
113112

114113
impl Deserialize for Array {
115114
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
115+
make_place!(Place);
116+
116117
impl Visitor for Place<Array> {
117118
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
118119
Ok(Box::new(ArrayBuilder {

src/json/number.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::de::{Deserialize, Visitor};
22
use crate::error::Result;
33
use crate::ser::{Fragment, Serialize};
4-
use crate::Place;
54
use core::fmt::{self, Display};
65

76
/// A JSON number represented by some Rust primitive.
@@ -34,6 +33,8 @@ impl Serialize for Number {
3433

3534
impl Deserialize for Number {
3635
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36+
make_place!(Place);
37+
3738
impl Visitor for Place<Number> {
3839
fn negative(&mut self, n: i64) -> Result<()> {
3940
self.out = Some(Number::I64(n));

src/json/object.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::de::{Deserialize, Map, Visitor};
22
use crate::error::Result;
33
use crate::json::{drop, Value};
44
use crate::ser::{self, Fragment, Serialize};
5-
use crate::Place;
65
use alloc::borrow::{Cow, ToOwned};
76
use alloc::boxed::Box;
87
use alloc::collections::{btree_map, BTreeMap};
@@ -116,6 +115,8 @@ impl Serialize for Object {
116115

117116
impl Deserialize for Object {
118117
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
118+
make_place!(Place);
119+
119120
impl Visitor for Place<Object> {
120121
fn map(&mut self) -> Result<Box<dyn Map + '_>> {
121122
Ok(Box::new(ObjectBuilder {

src/json/value.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::de::{Deserialize, Map, Seq, Visitor};
22
use crate::error::Result;
33
use crate::json::{Array, Number, Object};
44
use crate::ser::{Fragment, Serialize};
5-
use crate::Place;
65
use alloc::borrow::{Cow, ToOwned};
76
use alloc::boxed::Box;
87
use alloc::string::String;
@@ -72,6 +71,8 @@ impl Serialize for Value {
7271

7372
impl Deserialize for Value {
7473
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
74+
make_place!(Place);
75+
7576
impl Visitor for Place<Value> {
7677
fn null(&mut self) -> Result<()> {
7778
self.out = Some(Value::Null);

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,5 @@ pub use crate::error::{Error, Result};
197197
#[doc(inline)]
198198
pub use crate::ser::Serialize;
199199

200-
make_place!(Place);
201-
202200
#[allow(non_camel_case_types)]
203201
struct private;

0 commit comments

Comments
 (0)