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

Update to 2018 #129

Merged
merged 2 commits into from
Apr 20, 2021
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
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ implementing custom derives.
"""
license = "MIT"
readme = "README.md"
edition = "2018"
exclude = ["/.travis.yml", "/publish.sh", "/.github/**"]

[badges]
Expand All @@ -20,9 +21,9 @@ darling_core = { version = "=0.12.4", path = "core" }
darling_macro = { version = "=0.12.4", path = "macro" }

[dev-dependencies]
proc-macro2 = "1"
quote = "1"
syn = "1"
proc-macro2 = "1.0.26"
quote = "1.0.9"
syn = "1.0.69"

[features]
default = ["suggestions"]
Expand Down
11 changes: 6 additions & 5 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ Helper crate for proc-macro library for reading attributes into structs when
implementing custom derives. Use https://crates.io/crates/darling in your code.
"""
license = "MIT"
edition = "2018"

[features]
diagnostics = []
suggestions = ["strsim"]

[dependencies]
ident_case = "1.0.0"
proc-macro2 = "1"
quote = "1"
syn = { version = "1.0.1", features = ["full", "extra-traits"] }
fnv = "1.0.6"
ident_case = "1.0.1"
proc-macro2 = "1.0.26"
quote = "1.0.9"
syn = { version = "1.0.69", features = ["full", "extra-traits"] }
fnv = "1.0.7"
strsim = { version = "0.10.0", optional = true }
4 changes: 2 additions & 2 deletions core/src/ast/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use syn::spanned::Spanned;

use usage::{
use crate::usage::{
self, IdentRefSet, IdentSet, LifetimeRefSet, LifetimeSet, UsesLifetimes, UsesTypeParams,
};
use {Error, FromField, FromVariant, Result};
use crate::{Error, FromField, FromVariant, Result};

/// A struct or enum body.
///
Expand Down
8 changes: 2 additions & 6 deletions core/src/ast/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
use std::iter::Iterator;
use std::slice::Iter;

use syn;

use {FromGenericParam, FromGenerics, FromTypeParam, Result};
use crate::{FromGenericParam, FromGenerics, FromTypeParam, Result};

/// Extension trait for `GenericParam` to support getting values by variant.
///
Expand Down Expand Up @@ -179,10 +177,8 @@ impl<'a, P: GenericParamExt> Iterator for TypeParams<'a, P> {

#[cfg(test)]
mod tests {
use syn;

use super::{GenericParam, Generics};
use FromGenerics;
use crate::FromGenerics;

#[test]
fn generics() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/codegen/attr_extractor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use proc_macro2::TokenStream;

use options::ForwardAttrs;
use util::PathList;
use crate::options::ForwardAttrs;
use crate::util::PathList;

/// Infrastructure for generating an attribute extractor.
pub trait ExtractAttribute {
Expand Down
4 changes: 2 additions & 2 deletions core/src/codegen/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
use syn::{Ident, Path, Type};

use codegen::{DefaultExpression, PostfixTransform};
use usage::{self, IdentRefSet, IdentSet, UsesTypeParams};
use crate::codegen::{DefaultExpression, PostfixTransform};
use crate::usage::{self, IdentRefSet, IdentSet, UsesTypeParams};

/// Properties needed to generate code for a field in all the contexts
/// where one may appear.
Expand Down
14 changes: 8 additions & 6 deletions core/src/codegen/from_derive_impl.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{self, Ident};

use ast::Data;
use codegen::{ExtractAttribute, OuterFromImpl, TraitImpl};
use options::{ForwardAttrs, Shape};
use util::PathList;
use syn::Ident;

use crate::{
ast::Data,
codegen::{ExtractAttribute, OuterFromImpl, TraitImpl},
options::{ForwardAttrs, Shape},
util::PathList,
};

pub struct FromDeriveInputImpl<'a> {
pub ident: Option<&'a Ident>,
Expand Down
10 changes: 6 additions & 4 deletions core/src/codegen/from_field.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{self, Ident};
use syn::Ident;

use codegen::{ExtractAttribute, OuterFromImpl, TraitImpl};
use options::ForwardAttrs;
use util::PathList;
use crate::{
codegen::{ExtractAttribute, OuterFromImpl, TraitImpl},
options::ForwardAttrs,
util::PathList,
};

/// `impl FromField` generator. This is used for parsing an individual
/// field and its attributes.
Expand Down
5 changes: 2 additions & 3 deletions core/src/codegen/from_meta_impl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn;

use ast::{Data, Fields, Style};
use codegen::{Field, OuterFromImpl, TraitImpl, Variant};
use crate::ast::{Data, Fields, Style};
use crate::codegen::{Field, OuterFromImpl, TraitImpl, Variant};

pub struct FromMetaImpl<'a> {
pub base: TraitImpl<'a>,
Expand Down
8 changes: 4 additions & 4 deletions core/src/codegen/from_type_param.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{self, Ident};
use syn::Ident;

use codegen::{ExtractAttribute, OuterFromImpl, TraitImpl};
use options::ForwardAttrs;
use util::PathList;
use crate::codegen::{ExtractAttribute, OuterFromImpl, TraitImpl};
use crate::options::ForwardAttrs;
use crate::util::PathList;

pub struct FromTypeParamImpl<'a> {
pub base: TraitImpl<'a>,
Expand Down
8 changes: 4 additions & 4 deletions core/src/codegen/from_variant_impl.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{self, Ident};
use syn::Ident;

use codegen::{ExtractAttribute, OuterFromImpl, TraitImpl};
use options::{DataShape, ForwardAttrs};
use util::PathList;
use crate::codegen::{ExtractAttribute, OuterFromImpl, TraitImpl};
use crate::options::{DataShape, ForwardAttrs};
use crate::util::PathList;

pub struct FromVariantImpl<'a> {
pub base: TraitImpl<'a>,
Expand Down
2 changes: 1 addition & 1 deletion core/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod trait_impl;
mod variant;
mod variant_data;

pub(in codegen) use self::attr_extractor::ExtractAttribute;
pub(in crate::codegen) use self::attr_extractor::ExtractAttribute;
pub use self::default_expr::DefaultExpression;
pub use self::field::Field;
pub use self::from_derive_impl::FromDeriveInputImpl;
Expand Down
4 changes: 2 additions & 2 deletions core/src/codegen/outer_from_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
use syn::{GenericParam, Generics, Path, TraitBound, TraitBoundModifier, TypeParamBound};

use codegen::TraitImpl;
use usage::IdentSet;
use crate::codegen::TraitImpl;
use crate::usage::IdentSet;

/// Wrapper for "outer From" traits, such as `FromDeriveInput`, `FromVariant`, and `FromField`.
pub trait OuterFromImpl<'a> {
Expand Down
23 changes: 12 additions & 11 deletions core/src/codegen/trait_impl.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use proc_macro2::TokenStream;
use syn::{Generics, Ident, WherePredicate};

use ast::{Data, Fields};
use codegen::error::{ErrorCheck, ErrorDeclaration};
use codegen::field;
use codegen::{DefaultExpression, Field, FieldsGen, PostfixTransform, Variant};
use usage::{CollectTypeParams, IdentSet, Purpose};
use crate::ast::{Data, Fields};
use crate::codegen::{
error::{ErrorCheck, ErrorDeclaration},
field, DefaultExpression, Field, FieldsGen, PostfixTransform, Variant,
};
use crate::usage::{CollectTypeParams, IdentSet, Purpose};

#[derive(Debug)]
pub struct TraitImpl<'a> {
Expand Down Expand Up @@ -86,7 +87,7 @@ impl<'a> TraitImpl<'a> {
}

/// Generate local variable declarations for all fields.
pub(in codegen) fn local_declarations(&self) -> TokenStream {
pub(in crate::codegen) fn local_declarations(&self) -> TokenStream {
if let Data::Struct(ref vd) = self.data {
let vdr = vd.as_ref().map(Field::as_declaration);
let decls = vdr.fields.as_slice();
Expand All @@ -97,7 +98,7 @@ impl<'a> TraitImpl<'a> {
}

/// Generate immutable variable declarations for all fields.
pub(in codegen) fn immutable_declarations(&self) -> TokenStream {
pub(in crate::codegen) fn immutable_declarations(&self) -> TokenStream {
if let Data::Struct(ref vd) = self.data {
let vdr = vd.as_ref().map(|f| field::Declaration::new(f, false));
let decls = vdr.fields.as_slice();
Expand All @@ -107,12 +108,12 @@ impl<'a> TraitImpl<'a> {
}
}

pub(in codegen) fn post_transform_call(&self) -> Option<TokenStream> {
pub(in crate::codegen) fn post_transform_call(&self) -> Option<TokenStream> {
self.post_transform.map(|pt| quote!(#pt))
}

/// Generate local variable declaration and initialization for instance from which missing fields will be taken.
pub(in codegen) fn fallback_decl(&self) -> TokenStream {
pub(in crate::codegen) fn fallback_decl(&self) -> TokenStream {
let default = self.default.as_ref().map(DefaultExpression::as_declaration);
quote!(#default)
}
Expand All @@ -127,12 +128,12 @@ impl<'a> TraitImpl<'a> {
}
}

pub(in codegen) fn initializers(&self) -> TokenStream {
pub(in crate::codegen) fn initializers(&self) -> TokenStream {
self.make_field_ctx().initializers()
}

/// Generate the loop which walks meta items looking for property matches.
pub(in codegen) fn core_loop(&self) -> TokenStream {
pub(in crate::codegen) fn core_loop(&self) -> TokenStream {
self.make_field_ctx().core_loop()
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/codegen/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
use syn::Ident;

use ast::Fields;
use codegen::error::{ErrorCheck, ErrorDeclaration};
use codegen::{Field, FieldsGen};
use usage::{self, IdentRefSet, IdentSet, UsesTypeParams};
use crate::ast::Fields;
use crate::codegen::error::{ErrorCheck, ErrorDeclaration};
use crate::codegen::{Field, FieldsGen};
use crate::usage::{self, IdentRefSet, IdentSet, UsesTypeParams};

/// A variant of the enum which is deriving `FromMeta`.
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
11 changes: 5 additions & 6 deletions core/src/codegen/variant_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use proc_macro2::TokenStream;

use ast::Fields;
use ast::Style;
use codegen::Field;
use crate::ast::{Fields, Style};
use crate::codegen::Field;

pub struct FieldsGen<'a> {
fields: &'a Fields<Field<'a>>,
Expand All @@ -18,7 +17,7 @@ impl<'a> FieldsGen<'a> {
}

/// Create declarations for all the fields in the struct.
pub(in codegen) fn declarations(&self) -> TokenStream {
pub(in crate::codegen) fn declarations(&self) -> TokenStream {
match *self.fields {
Fields {
style: Style::Struct,
Expand All @@ -33,7 +32,7 @@ impl<'a> FieldsGen<'a> {
}

/// Generate the loop which walks meta items looking for property matches.
pub(in codegen) fn core_loop(&self) -> TokenStream {
pub(in crate::codegen) fn core_loop(&self) -> TokenStream {
let arms = self.fields.as_ref().map(Field::as_match);

// If we're allowing unknown fields, then handling one is a no-op.
Expand Down Expand Up @@ -84,7 +83,7 @@ impl<'a> FieldsGen<'a> {
}
}

pub(in codegen) fn initializers(&self) -> TokenStream {
pub(in crate::codegen) fn initializers(&self) -> TokenStream {
let inits = self.fields.as_ref().map(Field::as_initializer);
let inits = inits.iter();

Expand Down
2 changes: 1 addition & 1 deletion core/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::DeriveInput;

use options;
use crate::options;

/// Run an expression which returns a `darling::Result`, then either return the tokenized
/// representation of the `Ok` value, or the tokens of the compiler errors in the `Err` case.
Expand Down
6 changes: 3 additions & 3 deletions core/src/error/kind.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;

use error::Error;
use crate::error::Error;

type DeriveInputShape = String;
type FieldName = String;
Expand All @@ -10,7 +10,7 @@ type MetaFormat = String;
// Don't want to publicly commit to ErrorKind supporting equality yet, but
// not having it makes testing very difficult.
#[cfg_attr(test, derive(Clone, PartialEq, Eq))]
pub(in error) enum ErrorKind {
pub(in crate::error) enum ErrorKind {
/// An arbitrary error message.
Custom(String),
DuplicateField(FieldName),
Expand Down Expand Up @@ -108,7 +108,7 @@ impl From<ErrorUnknownField> for ErrorKind {
// Don't want to publicly commit to ErrorKind supporting equality yet, but
// not having it makes testing very difficult.
#[cfg_attr(test, derive(Clone, PartialEq, Eq))]
pub(in error) struct ErrorUnknownField {
pub(in crate::error) struct ErrorUnknownField {
name: String,
did_you_mean: Option<String>,
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn path_to_string(path: &syn::Path) -> String {

/// Error creation functions
impl Error {
pub(in error) fn new(kind: ErrorKind) -> Self {
pub(in crate::error) fn new(kind: ErrorKind) -> Self {
Error {
kind,
locations: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion core/src/from_derive_input.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use syn::DeriveInput;

use Result;
use crate::Result;

/// Creates an instance by parsing an entire proc-macro `derive` input,
/// including the, identity, generics, and visibility of the type.
Expand Down
4 changes: 2 additions & 2 deletions core/src/from_field.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use syn::{self, Field};
use syn::Field;

use Result;
use crate::Result;

/// Creates an instance by parsing an individual field and its attributes.
pub trait FromField: Sized {
Expand Down
4 changes: 1 addition & 3 deletions core/src/from_generic_param.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use syn;

use Result;
use crate::Result;

/// Creates an instance by parsing a specific `syn::GenericParam`.
/// This can be a type param, a lifetime, or a const param.
Expand Down
2 changes: 1 addition & 1 deletion core/src/from_generics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use syn::Generics;

use Result;
use crate::Result;

/// Creates an instance by parsing an entire generics declaration, including the
/// `where` clause.
Expand Down
Loading