Skip to content

Commit

Permalink
Restyle using more RFC-compliant style
Browse files Browse the repository at this point in the history
  • Loading branch information
lo48576 committed Jul 14, 2018
1 parent feae86d commit a454844
Show file tree
Hide file tree
Showing 28 changed files with 0 additions and 82 deletions.
6 changes: 0 additions & 6 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
required_version = "0.8.2"
unstable_features = true

blank_lines_upper_bound = 2
error_on_line_overflow = false # Default.
match_block_trailing_comma = true
newline_style = "Unix" # Default.
reorder_imports = true # Default.
reorder_modules = true # Default.
trailing_comma = "Vertical" # Default.
wrap_comments = true
3 changes: 0 additions & 3 deletions opaque_typedef/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! Traits for `opaque_typedef_macros`.
#![warn(missing_docs)]


/// An error type that indicates the error should never happen.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Infallible {}


/// Common functions for opaque typedef-ed sized types.
pub trait OpaqueTypedef: Sized {
/// Inner type.
Expand Down Expand Up @@ -34,7 +32,6 @@ pub trait OpaqueTypedef: Sized {
unsafe fn as_inner_mut(&mut self) -> &mut Self::Inner;
}


/// Common functions for opaque typedef-ed unsized types.
pub trait OpaqueTypedefUnsized {
/// Inner type.
Expand Down
5 changes: 0 additions & 5 deletions opaque_typedef_macros/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use syn;


/// Checks whether the attribute has the given path.
pub fn is_attr_with_path(attr: &syn::Attribute, path: &[&str]) -> bool {
attr.path
Expand All @@ -12,7 +11,6 @@ pub fn is_attr_with_path(attr: &syn::Attribute, path: &[&str]) -> bool {
.eq(path.into_iter().map(|&s| s))
}


/// Checks whether the word meta item with the given path is specified.
pub fn has_word_meta(meta: &syn::Meta, ident_path: &[&str]) -> bool {
match *meta {
Expand All @@ -35,14 +33,12 @@ pub fn has_word_meta(meta: &syn::Meta, ident_path: &[&str]) -> bool {
}
}


pub fn get_meta_content_by_path(meta: syn::Meta, path: &[&str]) -> Vec<syn::NestedMeta> {
let mut res = Vec::new();
append_meta_content_by_path(meta, path, &mut res);
res
}


fn append_meta_content_by_path(meta: syn::Meta, path: &[&str], vec: &mut Vec<syn::NestedMeta>) {
if path.is_empty() {
return;
Expand All @@ -58,7 +54,6 @@ fn append_meta_content_by_path(meta: syn::Meta, path: &[&str], vec: &mut Vec<syn
}
}


fn append_meta_items_by_path<I>(nested_items: I, path: &[&str], vec: &mut Vec<syn::NestedMeta>)
where
I: IntoIterator<Item = syn::NestedMeta>,
Expand Down
1 change: 0 additions & 1 deletion opaque_typedef_macros/src/derives/as_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use type_props::TypeProps;
use super::deref::{gen_deref_expr, gen_deref_mut_expr};
use super::Derive;


/// Generates an impl for the target.
pub fn gen_impl(target: Derive, props: &TypeProps) -> TokenStream {
let ty_outer = props.ty_outer;
Expand Down
4 changes: 0 additions & 4 deletions opaque_typedef_macros/src/derives/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use utils::extend_generics;

use super::Derive;


pub fn gen_impl_ord(props: &TypeProps) -> TokenStream {
let ty_outer = &props.ty_outer;
let type_generics = &props.type_generics;
Expand All @@ -33,7 +32,6 @@ pub fn gen_impl_ord(props: &TypeProps) -> TokenStream {
}.gen_impl()
}


/// Generates an impl for the target.
pub fn gen_impl_partial_cmp(target: Derive, props: &TypeProps) -> TokenStream {
let trait_spec = match target {
Expand Down Expand Up @@ -379,7 +377,6 @@ pub fn gen_impl_partial_cmp(target: Derive, props: &TypeProps) -> TokenStream {
}
}


#[derive(Debug, Clone, Copy)]
enum CmpTraitSpec {
PartialEq,
Expand Down Expand Up @@ -421,7 +418,6 @@ impl CmpTraitSpec {
}
}


#[derive(Clone)]
struct CmpImplSpec<'a, TyI, TyL, TyR> {
type_props: &'a TypeProps<'a>,
Expand Down
3 changes: 0 additions & 3 deletions opaque_typedef_macros/src/derives/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use utils::extend_generics;

use super::Derive;


/// Generates an impl for the target.
pub fn gen_impl_from_inner(props: &TypeProps) -> TokenStream {
let helper_trait = props.helper_trait();
Expand Down Expand Up @@ -53,7 +52,6 @@ pub fn gen_impl_from_inner(props: &TypeProps) -> TokenStream {
}
}


/// Generates an impl for the target.
pub fn gen_impl_into_inner(props: &TypeProps) -> TokenStream {
let helper_trait = props.helper_trait();
Expand Down Expand Up @@ -92,7 +90,6 @@ pub fn gen_impl_into_inner(props: &TypeProps) -> TokenStream {
}
}


/// Generates an impl for the target.
pub fn gen_impl_into_smartptr(target: Derive, props: &TypeProps) -> TokenStream {
assert_eq!(
Expand Down
3 changes: 0 additions & 3 deletions opaque_typedef_macros/src/derives/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use type_props::TypeProps;

use super::Derive;


/// Generates an impl for the target.
pub fn gen_impl(target: Derive, props: &TypeProps) -> TokenStream {
let ty_outer = props.ty_outer;
Expand Down Expand Up @@ -53,7 +52,6 @@ pub fn gen_impl(target: Derive, props: &TypeProps) -> TokenStream {
}
}


pub fn gen_deref_expr(props: &TypeProps) -> TokenStream {
let self_as_inner = props.tokens_outer_expr_as_inner(quote!(self));
let ty_deref_target = props.tokens_ty_deref_target();
Expand All @@ -63,7 +61,6 @@ pub fn gen_deref_expr(props: &TypeProps) -> TokenStream {
}
}


pub fn gen_deref_mut_expr(props: &TypeProps) -> TokenStream {
// The caller is responsible to ensure `allow_mut_ref` is specified.
assert!(
Expand Down
1 change: 0 additions & 1 deletion opaque_typedef_macros/src/derives/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use utils::extend_generics;

use super::Derive;


/// Generates an impl for the target.
pub fn gen_impl(target: Derive, props: &TypeProps) -> TokenStream {
let trait_name = match target {
Expand Down
4 changes: 0 additions & 4 deletions opaque_typedef_macros/src/derives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod deref;
mod fmt;
mod ops;


/// Auto-derive target trait.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, AsRefStr, EnumString, EnumProperty,
Expand Down Expand Up @@ -1609,7 +1608,6 @@ impl Derive {
}
}


/// Returns metadata in `#[opaque_typedef(derive(..))]` (`..` part).
fn get_derive_meta(attrs: &[syn::Attribute]) -> Vec<syn::Meta> {
attrs
Expand All @@ -1624,15 +1622,13 @@ fn get_derive_meta(attrs: &[syn::Attribute]) -> Vec<syn::Meta> {
.collect()
}


fn abort_on_unknown_derive_target(target: ::std::fmt::Arguments) -> ! {
panic!(
"`#[opaque_typedef(derive({target}))]` is specified, but the target `{target}` is unknown",
target = target
);
}


fn abort_on_unsupported_derive_format(inner: ::std::fmt::Arguments) -> ! {
panic!(
"`#[opaque_typedef(derive({}))]` is specified, but this format is not supported",
Expand Down
4 changes: 0 additions & 4 deletions opaque_typedef_macros/src/derives/ops/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use utils::extend_generics;

use super::{OperandSpec, OperandTypeSpec, OperandTypeWrapperSpec};


/// Binary operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString, EnumProperty)]
pub enum BinOpSpec {
Expand Down Expand Up @@ -406,7 +405,6 @@ impl BinOpSpec {
}
}


pub fn gen_impl_sized_raw(
props: &TypeProps,
op_spec: BinOpSpec,
Expand All @@ -422,7 +420,6 @@ pub fn gen_impl_sized_raw(
)
}


pub fn gen_impl_sized_ref(
props: &TypeProps,
op_spec: BinOpSpec,
Expand Down Expand Up @@ -492,7 +489,6 @@ pub fn gen_impl_sized_ref(
}
}


pub fn gen_impl_sized(
props: &TypeProps,
op_spec: BinOpSpec,
Expand Down
5 changes: 0 additions & 5 deletions opaque_typedef_macros/src/derives/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use type_props::TypeProps;
pub mod binary;
pub mod unary;


/// Operand type (inner or outer).
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString)]
pub enum OperandTypeSpec {
Expand All @@ -26,7 +25,6 @@ impl OperandTypeSpec {
}
}


/// Operand type wrapper (raw, ref, `Cow`, etc...).
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum OperandTypeWrapperSpec {
Expand All @@ -36,7 +34,6 @@ pub enum OperandTypeWrapperSpec {
Ref,
}


/// Operand type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct OperandSpec {
Expand Down Expand Up @@ -114,7 +111,6 @@ impl OperandSpec {
}
}


/// Operator impl variation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString)]
pub enum OpImplVariation {
Expand All @@ -124,7 +120,6 @@ pub enum OpImplVariation {
References,
}


/// Operator spec.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum OpSpec {
Expand Down
4 changes: 0 additions & 4 deletions opaque_typedef_macros/src/derives/ops/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use utils::extend_generics;

use super::{OperandSpec, OperandTypeSpec, OperandTypeWrapperSpec};


/// Unary operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, EnumString, EnumProperty)]
pub enum UnaryOpSpec {
Expand Down Expand Up @@ -114,7 +113,6 @@ impl UnaryOpSpec {
}
}


pub fn gen_impl_sized_raw(
props: &TypeProps,
op_spec: UnaryOpSpec,
Expand All @@ -128,7 +126,6 @@ pub fn gen_impl_sized_raw(
)
}


pub fn gen_impl_sized_ref(
props: &TypeProps,
op_spec: UnaryOpSpec,
Expand All @@ -152,7 +149,6 @@ pub fn gen_impl_sized_ref(
}
}


pub fn gen_impl_sized(
props: &TypeProps,
op_spec: UnaryOpSpec,
Expand Down
3 changes: 0 additions & 3 deletions opaque_typedef_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ mod derives;
mod type_props;
mod utils;


/// The entrypoint for a `#[derive(OpaqueTypedef)]`-ed type.
#[proc_macro_derive(OpaqueTypedef, attributes(opaque_typedef))]
pub fn opaque_typedef(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Expand All @@ -31,7 +30,6 @@ pub fn opaque_typedef(input: proc_macro::TokenStream) -> proc_macro::TokenStream
gen.into()
}


/// The entrypoint for a `#[derive(OpaqueTypedefUnsized)]`-ed type.
#[proc_macro_derive(OpaqueTypedefUnsized, attributes(opaque_typedef))]
pub fn opaque_typedef_unsized(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
Expand All @@ -40,7 +38,6 @@ pub fn opaque_typedef_unsized(input: proc_macro::TokenStream) -> proc_macro::Tok
gen.into()
}


/// Generates additional impls for a `#[derive(OpaqueTypedef*)]`-ed type.
fn gen_opaque_typedef_impls(input: &DeriveInput, sizedness: Sizedness) -> TokenStream {
let props = TypeProps::load(&input, sizedness);
Expand Down
8 changes: 0 additions & 8 deletions opaque_typedef_macros/src/type_props/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use derives::Derive;
use type_props::{CmpSpec, DerefSpec, Field, Sizedness, TypeProps, ValidationSpec};
use utils::expect_singleton_iter;


/// Returns `#[repr(..)]` metadata.
fn get_repr_meta(attrs: &[syn::Attribute]) -> Option<syn::Meta> {
let iter = attrs
Expand All @@ -21,7 +20,6 @@ fn get_repr_meta(attrs: &[syn::Attribute]) -> Option<syn::Meta> {
.expect("Multiple `#[repr(..)]` are not supported")
}


/// Returns a field marked (explicitly or implicitly) as "inner".
fn get_inner_field(data: &syn::Data) -> Field {
// Currently, only struct is supported.
Expand Down Expand Up @@ -53,7 +51,6 @@ fn get_inner_field(data: &syn::Data) -> Field {
unreachable!("Currently, outer types with multiple fields are not supported");
}


fn check_repr_outer(
ty_outer: &syn::Ident,
sizedness: Sizedness,
Expand Down Expand Up @@ -82,7 +79,6 @@ fn check_repr_outer(
);
}


fn get_deref_spec(attrs: &[syn::Attribute]) -> DerefSpec {
let namevalues = attrs
.into_iter()
Expand Down Expand Up @@ -163,7 +159,6 @@ fn get_deref_spec(attrs: &[syn::Attribute]) -> DerefSpec {
}
}


fn get_mut_ref_allowed(attrs: &[syn::Attribute]) -> bool {
attrs
.into_iter()
Expand All @@ -172,7 +167,6 @@ fn get_mut_ref_allowed(attrs: &[syn::Attribute]) -> bool {
.any(|meta| has_word_meta(&meta, &["opaque_typedef", "allow_mut_ref"]))
}


fn get_validation_spec(attrs: &[syn::Attribute]) -> ValidationSpec {
let namevalues = attrs
.into_iter()
Expand Down Expand Up @@ -254,7 +248,6 @@ fn get_validation_spec(attrs: &[syn::Attribute]) -> ValidationSpec {
}
}


fn get_cmp_spec(attrs: &[syn::Attribute]) -> CmpSpec {
let namevalues = attrs
.into_iter()
Expand Down Expand Up @@ -335,7 +328,6 @@ fn get_cmp_spec(attrs: &[syn::Attribute]) -> CmpSpec {
}
}


/// A builder of `TypeProps`.
#[derive(Default, Clone)]
pub struct TypePropsBuilder<'a> {
Expand Down
Loading

0 comments on commit a454844

Please sign in to comment.