Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve non_local_definitions warnings in rustc 1.78-nightly #51

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{attr, bound};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{
parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Ident, Result,
parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Result,
};

pub fn derive(input: DeriveInput) -> Result<TokenStream> {
Expand All @@ -26,10 +26,6 @@ pub fn derive(input: DeriveInput) -> Result<TokenStream> {
pub fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStream> {
let ident = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let dummy = Ident::new(
&format!("_IMPL_MINIDESERIALIZE_FOR_{}", ident),
Span::call_site(),
);

let fieldname = fields.named.iter().map(|f| &f.ident).collect::<Vec<_>>();
let fieldty = fields.named.iter().map(|f| &f.ty);
Expand All @@ -46,7 +42,7 @@ pub fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenS

Ok(quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
const _: () = {
#[repr(C)]
struct __Visitor #impl_generics #where_clause {
__out: miniserde::__private::Option<#ident #ty_generics>,
Expand Down Expand Up @@ -117,10 +113,6 @@ pub fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenS
}

let ident = &input.ident;
let dummy = Ident::new(
&format!("_IMPL_MINIDESERIALIZE_FOR_{}", ident),
Span::call_site(),
);

let var_idents = enumeration
.variants
Expand All @@ -141,7 +133,7 @@ pub fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenS

Ok(quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
const _: () = {
#[repr(C)]
struct __Visitor {
__out: miniserde::__private::Option<#ident>,
Expand Down
14 changes: 3 additions & 11 deletions derive/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{attr, bound};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{
parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Ident, Result,
parse_quote, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, FieldsNamed, Result,
};

pub fn derive(input: DeriveInput) -> Result<TokenStream> {
Expand All @@ -26,10 +26,6 @@ pub fn derive(input: DeriveInput) -> Result<TokenStream> {
fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStream> {
let ident = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let dummy = Ident::new(
&format!("_IMPL_MINISERIALIZE_FOR_{}", ident),
Span::call_site(),
);

let fieldname = &fields.named.iter().map(|f| &f.ident).collect::<Vec<_>>();
let fieldstr = fields
Expand All @@ -46,7 +42,7 @@ fn derive_struct(input: &DeriveInput, fields: &FieldsNamed) -> Result<TokenStrea

Ok(quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
const _: () = {
impl #impl_generics miniserde::Serialize for #ident #ty_generics #bounded_where_clause {
fn begin(&self) -> miniserde::ser::Fragment {
miniserde::ser::Fragment::Map(miniserde::__private::Box::new(__Map {
Expand Down Expand Up @@ -89,10 +85,6 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea
}

let ident = &input.ident;
let dummy = Ident::new(
&format!("_IMPL_MINISERIALIZE_FOR_{}", ident),
Span::call_site(),
);

let var_idents = enumeration
.variants
Expand All @@ -113,7 +105,7 @@ fn derive_enum(input: &DeriveInput, enumeration: &DataEnum) -> Result<TokenStrea

Ok(quote! {
#[allow(non_upper_case_globals)]
const #dummy: () = {
const _: () = {
impl miniserde::Serialize for #ident {
fn begin(&self) -> miniserde::ser::Fragment {
match self {
Expand Down
34 changes: 33 additions & 1 deletion src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::de::{Deserialize, Map, Seq, Visitor};
use crate::error::{Error, Result};
use crate::ignore::Ignore;
use crate::ptr::NonuniqueBox;
use crate::Place;
use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
Expand All @@ -18,36 +17,45 @@ use std::hash::{BuildHasher, Hash};

impl Deserialize for () {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<()> {
fn null(&mut self) -> Result<()> {
self.out = Some(());
Ok(())
}
}

Place::new(out)
}
}

impl Deserialize for bool {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<bool> {
fn boolean(&mut self, b: bool) -> Result<()> {
self.out = Some(b);
Ok(())
}
}

Place::new(out)
}
}

impl Deserialize for String {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<String> {
fn string(&mut self, s: &str) -> Result<()> {
self.out = Some(s.to_owned());
Ok(())
}
}

Place::new(out)
}
}
Expand All @@ -56,6 +64,8 @@ macro_rules! signed {
($ty:ident) => {
impl Deserialize for $ty {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<$ty> {
fn negative(&mut self, n: i64) -> Result<()> {
if n >= $ty::min_value() as i64 {
Expand All @@ -75,6 +85,7 @@ macro_rules! signed {
}
}
}

Place::new(out)
}
}
Expand All @@ -90,6 +101,8 @@ macro_rules! unsigned {
($ty:ident) => {
impl Deserialize for $ty {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<$ty> {
fn nonnegative(&mut self, n: u64) -> Result<()> {
if n <= $ty::max_value() as u64 {
Expand All @@ -100,6 +113,7 @@ macro_rules! unsigned {
}
}
}

Place::new(out)
}
}
Expand All @@ -115,6 +129,8 @@ macro_rules! float {
($ty:ident) => {
impl Deserialize for $ty {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<$ty> {
fn negative(&mut self, n: i64) -> Result<()> {
self.out = Some(n as $ty);
Expand All @@ -131,6 +147,7 @@ macro_rules! float {
Ok(())
}
}

Place::new(out)
}
}
Expand All @@ -141,6 +158,8 @@ float!(f64);

impl<T: Deserialize> Deserialize for Box<T> {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<T: Deserialize> Visitor for Place<Box<T>> {
fn null(&mut self) -> Result<()> {
let mut out = None;
Expand Down Expand Up @@ -266,7 +285,10 @@ impl<T: Deserialize> Deserialize for Option<T> {
fn default() -> Option<Self> {
Some(None)
}

fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<T: Deserialize> Visitor for Place<Option<T>> {
fn null(&mut self) -> Result<()> {
self.out = Some(None);
Expand Down Expand Up @@ -315,6 +337,8 @@ impl<T: Deserialize> Deserialize for Option<T> {

impl<A: Deserialize, B: Deserialize> Deserialize for (A, B) {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<A: Deserialize, B: Deserialize> Visitor for Place<(A, B)> {
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
Ok(Box::new(TupleBuilder {
Expand Down Expand Up @@ -356,6 +380,8 @@ impl<A: Deserialize, B: Deserialize> Deserialize for (A, B) {

impl<T: Deserialize> Deserialize for Vec<T> {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<T: Deserialize> Visitor for Place<Vec<T>> {
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
Ok(Box::new(VecBuilder {
Expand Down Expand Up @@ -399,6 +425,8 @@ impl<T: Deserialize> Deserialize for Vec<T> {

impl<T: Deserialize, const N: usize> Deserialize for [T; N] {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<T: Deserialize, const N: usize> Visitor for Place<[T; N]> {
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
Ok(Box::new(ArrayBuilder {
Expand Down Expand Up @@ -469,6 +497,8 @@ where
H: BuildHasher + Default,
{
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<K, V, H> Visitor for Place<HashMap<K, V, H>>
where
K: FromStr + Hash + Eq,
Expand Down Expand Up @@ -529,6 +559,8 @@ where

impl<K: FromStr + Ord, V: Deserialize> Deserialize for BTreeMap<K, V> {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl<K: FromStr + Ord, V: Deserialize> Visitor for Place<BTreeMap<K, V>> {
fn map(&mut self) -> Result<Box<dyn Map + '_>> {
Ok(Box::new(MapBuilder {
Expand Down
3 changes: 2 additions & 1 deletion src/json/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::error::Result;
use crate::json::{drop, Value};
use crate::private;
use crate::ser::{Fragment, Serialize};
use crate::Place;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::fmt::{self, Debug};
Expand Down Expand Up @@ -113,6 +112,8 @@ impl Serialize for Array {

impl Deserialize for Array {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<Array> {
fn seq(&mut self) -> Result<Box<dyn Seq + '_>> {
Ok(Box::new(ArrayBuilder {
Expand Down
3 changes: 2 additions & 1 deletion src/json/number.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::de::{Deserialize, Visitor};
use crate::error::Result;
use crate::ser::{Fragment, Serialize};
use crate::Place;
use core::fmt::{self, Display};

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

impl Deserialize for Number {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<Number> {
fn negative(&mut self, n: i64) -> Result<()> {
self.out = Some(Number::I64(n));
Expand Down
3 changes: 2 additions & 1 deletion src/json/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::de::{Deserialize, Map, Visitor};
use crate::error::Result;
use crate::json::{drop, Value};
use crate::ser::{self, Fragment, Serialize};
use crate::Place;
use alloc::borrow::{Cow, ToOwned};
use alloc::boxed::Box;
use alloc::collections::{btree_map, BTreeMap};
Expand Down Expand Up @@ -116,6 +115,8 @@ impl Serialize for Object {

impl Deserialize for Object {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<Object> {
fn map(&mut self) -> Result<Box<dyn Map + '_>> {
Ok(Box::new(ObjectBuilder {
Expand Down
3 changes: 2 additions & 1 deletion src/json/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::de::{Deserialize, Map, Seq, Visitor};
use crate::error::Result;
use crate::json::{Array, Number, Object};
use crate::ser::{Fragment, Serialize};
use crate::Place;
use alloc::borrow::{Cow, ToOwned};
use alloc::boxed::Box;
use alloc::string::String;
Expand Down Expand Up @@ -72,6 +71,8 @@ impl Serialize for Value {

impl Deserialize for Value {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
make_place!(Place);

impl Visitor for Place<Value> {
fn null(&mut self) -> Result<()> {
self.out = Some(Value::Null);
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,5 @@ pub use crate::error::{Error, Result};
#[doc(inline)]
pub use crate::ser::Serialize;

make_place!(Place);

#[allow(non_camel_case_types)]
struct private;
Loading