Skip to content

Commit

Permalink
Ungroup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 26, 2023
1 parent 11677ad commit dd99136
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 68 deletions.
10 changes: 4 additions & 6 deletions precompiled/serde_derive/src/lib_from_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
extern crate quote;
#[macro_use]
extern crate syn;

extern crate proc_macro;
extern crate proc_macro2;

mod internals;

use proc_macro::TokenStream;
use syn::DeriveInput;

#[macro_use]
mod bound;
#[macro_use]
mod fragment;

mod de;
mod dummy;
mod internals;
mod pretend;
mod ser;
mod this;
mod try;

use proc_macro::TokenStream;
use syn::DeriveInput;

#[proc_macro_derive(Serialize, attributes(serde))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as DeriveInput);
Expand Down
7 changes: 2 additions & 5 deletions serde_derive/src/bound.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::collections::HashSet;

use syn::punctuated::{Pair, Punctuated};

use crate::internals::ast::{Container, Data};
use crate::internals::{attr, ungroup};

use proc_macro2::Span;
use std::collections::HashSet;
use syn::punctuated::{Pair, Punctuated};

// Remove the default from every type parameter because in the generated impls
// they look like associated types: "error: associated type bindings are not
Expand Down
14 changes: 6 additions & 8 deletions serde_derive/src/de.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use crate::fragment::{Expr, Fragment, Match, Stmts};
use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::internals::{attr, replace_receiver, ungroup, Ctxt, Derive};
use crate::{bound, dummy, pretend, this};
use proc_macro2::{Literal, Span, TokenStream};
use quote::ToTokens;
use std::collections::BTreeSet;
use std::ptr;
#[cfg(precompiled)]
use std::sync::atomic::Ordering;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};

use crate::fragment::{Expr, Fragment, Match, Stmts};
use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::internals::{attr, replace_receiver, ungroup, Ctxt, Derive};
use crate::{bound, dummy, pretend, this};

use std::collections::BTreeSet;
use std::ptr;

pub fn expand_derive_deserialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
replace_receiver(input);

Expand Down
3 changes: 1 addition & 2 deletions serde_derive/src/dummy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use proc_macro2::TokenStream;

use crate::try;
use proc_macro2::TokenStream;

pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream {
let try_replacement = try::replacement();
Expand Down
3 changes: 1 addition & 2 deletions serde_derive/src/internals/case.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Code to convert the Rust-styled field/variant (e.g. `my_field`, `MyType`) to the
//! case of the source (e.g. `my-field`, `MY_FIELD`).

use std::fmt::{self, Debug, Display};

use self::RenameRule::*;
use std::fmt::{self, Debug, Display};

/// The different possible ways to change case of fields in a struct, or variants in an enum.
#[derive(Copy, Clone, PartialEq)]
Expand Down
11 changes: 5 additions & 6 deletions serde_derive/src/internals/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
pub mod ast;
pub mod attr;

mod ctxt;
pub use self::ctxt::Ctxt;

mod receiver;
pub use self::receiver::replace_receiver;

mod case;
mod check;
mod ctxt;
mod receiver;
mod respan;
mod symbol;

use syn::Type;

pub use self::ctxt::Ctxt;
pub use self::receiver::replace_receiver;

#[derive(Copy, Clone)]
pub enum Derive {
Serialize,
Expand Down
3 changes: 1 addition & 2 deletions serde_derive/src/pretend.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::internals::ast::{Container, Data, Field, Style, Variant};
use proc_macro2::TokenStream;
use quote::format_ident;

use crate::internals::ast::{Container, Data, Field, Style, Variant};

// Suppress dead_code warnings that would otherwise appear when using a remote
// derive. Other than this pretend code, a struct annotated with remote derive
// never has its fields referenced and an enum annotated with remote derive
Expand Down
7 changes: 3 additions & 4 deletions serde_derive/src/ser.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use proc_macro2::{Span, TokenStream};
use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};

use crate::fragment::{Fragment, Match, Stmts};
use crate::internals::ast::{Container, Data, Field, Style, Variant};
use crate::internals::{attr, replace_receiver, Ctxt, Derive};
use crate::{bound, dummy, pretend, this};
use proc_macro2::{Span, TokenStream};
use syn::spanned::Spanned;
use syn::{self, Ident, Index, Member};

pub fn expand_derive_serialize(input: &mut syn::DeriveInput) -> syn::Result<TokenStream> {
replace_receiver(input);
Expand Down
10 changes: 4 additions & 6 deletions test_suite/tests/test_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
use serde::de::{self, Deserialize, Deserializer, IgnoredAny, MapAccess, Unexpected, Visitor};
use serde::ser::{Serialize, Serializer};
use serde_derive::{Deserialize, Serialize};

use std::collections::{BTreeMap, HashMap};
use std::convert::TryFrom;
use std::fmt;
use std::marker::PhantomData;

use serde_test::{
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_ser_tokens_error,
assert_tokens, Token,
};
use std::collections::{BTreeMap, HashMap};
use std::convert::TryFrom;
use std::fmt;
use std::marker::PhantomData;

trait MyDefault: Sized {
fn my_default() -> Self;
Expand Down
1 change: 0 additions & 1 deletion test_suite/tests/test_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use serde::de::value::{BorrowedStrDeserializer, MapDeserializer};
use serde::de::{Deserialize, Deserializer, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, assert_de_tokens_error, Token};

use std::borrow::Cow;

#[test]
Expand Down
14 changes: 6 additions & 8 deletions test_suite/tests/test_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
)]
#![cfg_attr(feature = "unstable", feature(never_type))]

use fnv::FnvHasher;
use serde::de::{Deserialize, DeserializeOwned, Deserializer, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, Configure, Token};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::default::Default;
use std::ffi::{CStr, CString, OsString};
Expand All @@ -27,16 +31,10 @@ use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize, Ordering,
};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};

#[cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicI64, AtomicU64};

use fnv::FnvHasher;
use serde::de::{Deserialize, DeserializeOwned, Deserializer, IntoDeserializer};
use serde_derive::Deserialize;
use serde_test::{assert_de_tokens, Configure, Token};
use std::sync::{Arc, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};

#[macro_use]
mod macros;
Expand Down
1 change: 0 additions & 1 deletion test_suite/tests/test_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
use serde::ser::{Serialize, Serializer};
use serde_derive::{Deserialize, Serialize};

use std::borrow::Cow;
use std::marker::PhantomData;
use std::option::Option as StdOption;
Expand Down
1 change: 0 additions & 1 deletion test_suite/tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use serde_derive::{Deserialize, Serialize};
use serde_test::{
assert_de_tokens, assert_de_tokens_error, assert_ser_tokens, assert_tokens, Token,
};

use std::collections::BTreeMap;
use std::marker::PhantomData;

Expand Down
1 change: 0 additions & 1 deletion test_suite/tests/test_roundtrip.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde_test::{assert_tokens, Configure, Token};

use std::net;

#[macro_use]
Expand Down
16 changes: 7 additions & 9 deletions test_suite/tests/test_ser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![allow(clippy::derive_partial_eq_without_eq, clippy::unreadable_literal)]
#![cfg_attr(feature = "unstable", feature(never_type))]

use fnv::FnvHasher;
use serde_derive::Serialize;
use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::ffi::CString;
Expand All @@ -9,21 +12,16 @@ use std::num::Wrapping;
use std::ops::Bound;
use std::path::{Path, PathBuf};
use std::rc::{Rc, Weak as RcWeak};
#[cfg(unix)]
use std::str;
use std::sync::atomic::{
AtomicBool, AtomicI16, AtomicI32, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU8,
AtomicUsize,
};
use std::sync::{Arc, Mutex, RwLock, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};

#[cfg(unix)]
use std::str;
#[cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicI64, AtomicU64};

use fnv::FnvHasher;
use serde_derive::Serialize;
use serde_test::{assert_ser_tokens, assert_ser_tokens_error, Configure, Token};
use std::sync::{Arc, Mutex, RwLock, Weak as ArcWeak};
use std::time::{Duration, UNIX_EPOCH};

#[macro_use]
mod macros;
Expand Down
1 change: 0 additions & 1 deletion test_suite/tests/ui/conflict/flatten-newtype-struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde_derive::Serialize;

use std::collections::HashMap;

#[derive(Serialize)]
Expand Down
4 changes: 2 additions & 2 deletions test_suite/tests/ui/conflict/flatten-newtype-struct.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: #[serde(flatten)] cannot be used on newtype structs
--> tests/ui/conflict/flatten-newtype-struct.rs:6:12
--> tests/ui/conflict/flatten-newtype-struct.rs:5:12
|
6 | struct Foo(#[serde(flatten)] HashMap<String, String>);
5 | struct Foo(#[serde(flatten)] HashMap<String, String>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 change: 0 additions & 1 deletion test_suite/tests/ui/conflict/flatten-tuple-struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use serde_derive::Serialize;

use std::collections::HashMap;

#[derive(Serialize)]
Expand Down
4 changes: 2 additions & 2 deletions test_suite/tests/ui/conflict/flatten-tuple-struct.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: #[serde(flatten)] cannot be used on tuple structs
--> tests/ui/conflict/flatten-tuple-struct.rs:6:17
--> tests/ui/conflict/flatten-tuple-struct.rs:5:17
|
6 | struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
5 | struct Foo(u32, #[serde(flatten)] HashMap<String, String>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 comments on commit dd99136

Please sign in to comment.