Skip to content

Commit

Permalink
Use rustfmt from nightly to match CI
Browse files Browse the repository at this point in the history
  • Loading branch information
eqrion committed May 31, 2018
1 parent 9674524 commit 52a187c
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/bindgen/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ impl Bindings {
}

for item in &self.items {
if item.deref()
if item
.deref()
.annotations()
.bool("no-export")
.unwrap_or(false)
Expand Down
3 changes: 2 additions & 1 deletion src/bindgen/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ impl Cargo {
for meta_package in &self.metadata.packages {
if meta_package.name == package.name && meta_package.version == package.version {
for target in &meta_package.targets {
if target.kind.contains(&kind_lib) || target.kind.contains(&kind_staticlib)
if target.kind.contains(&kind_lib)
|| target.kind.contains(&kind_staticlib)
|| target.kind.contains(&kind_rlib)
|| target.kind.contains(&kind_cdylib)
|| target.kind.contains(&kind_dylib)
Expand Down
3 changes: 2 additions & 1 deletion src/bindgen/cdecl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl CDecl {
}

fn build_func(&mut self, f: &Function, layout_vertical: bool) {
let args = f.args
let args = f
.args
.iter()
.map(|&(ref arg_name, ref arg_ty)| (Some(arg_name.clone()), CDecl::from_type(arg_ty)))
.collect();
Expand Down
15 changes: 10 additions & 5 deletions src/bindgen/ir/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use syn;
use bindgen::config::{Config, Language};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, GenericPath, Item,
ItemContainer, Repr, ReprStyle, ReprType, Struct, Type};
use bindgen::ir::{
AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, GenericPath, Item, ItemContainer,
Repr, ReprStyle, ReprType, Struct, Type,
};
use bindgen::library::Library;
use bindgen::rename::{IdentifierType, RenameRule};
use bindgen::utilities::find_first_some;
Expand Down Expand Up @@ -278,7 +280,8 @@ impl Item for Enum {
];

if let Some(r) = find_first_some(&rules) {
self.variants = self.variants
self.variants = self
.variants
.iter()
.map(|variant| EnumVariant {
name: r.apply_to_pascal_case(&variant.name, IdentifierType::EnumVariant(self)),
Expand Down Expand Up @@ -437,7 +440,8 @@ impl Source for Enum {
out.open_brace();
}

for (i, &(ref field_name, ref body)) in self.variants
for (i, &(ref field_name, ref body)) in self
.variants
.iter()
.filter_map(|variant| variant.body.as_ref())
.enumerate()
Expand Down Expand Up @@ -479,7 +483,8 @@ impl Source for Enum {

if let Some((_, ref body)) = variant.body {
out.write_vertical_source_list(
&body.fields
&body
.fields
.iter()
.skip(skip_fields)
.map(|&(ref name, ref ty, _)| {
Expand Down
3 changes: 2 additions & 1 deletion src/bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ impl Function {
];

if let Some(r) = find_first_some(&rules) {
self.args = self.args
self.args = self
.args
.iter()
.map(|x| {
(
Expand Down
5 changes: 3 additions & 2 deletions src/bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::mem;
use bindgen::config::Config;
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::ir::{AnnotationSet, Cfg, Constant, Enum, OpaqueItem, Static, Struct, Type, Typedef,
Union};
use bindgen::ir::{
AnnotationSet, Cfg, Constant, Enum, OpaqueItem, Static, Struct, Type, Typedef, Union,
};
use bindgen::library::Library;
use bindgen::monomorph::Monomorphs;

Expand Down
5 changes: 3 additions & 2 deletions src/bindgen/ir/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use syn;
use bindgen::config::{Config, Language};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer,
Path, Type};
use bindgen::ir::{
AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer, Path, Type,
};
use bindgen::library::Library;
use bindgen::mangle;
use bindgen::monomorph::Monomorphs;
Expand Down
44 changes: 29 additions & 15 deletions src/bindgen/ir/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use syn;
use bindgen::config::{Config, Language};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer,
Repr, Type};
use bindgen::ir::{
AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer, Repr, Type,
};
use bindgen::library::Library;
use bindgen::mangle;
use bindgen::monomorph::Monomorphs;
Expand Down Expand Up @@ -200,15 +201,17 @@ impl Item for Struct {
generic_values.len(),
);

let mappings = self.generic_params
let mappings = self
.generic_params
.iter()
.zip(generic_values.iter())
.collect::<Vec<_>>();

let monomorph = Struct {
name: mangle::mangle_path(&self.name, generic_values),
generic_params: GenericParams::default(),
fields: self.fields
fields: self
.fields
.iter()
.map(|x| (x.0.clone(), x.1.specialize(&mappings), x.2.clone()))
.collect(),
Expand Down Expand Up @@ -257,7 +260,8 @@ impl Source for Struct {
out.write_vertical_source_list(&self.fields, ListType::Cap(";"));
} else {
out.write_vertical_source_list(
&self.fields
&self
.fields
.iter()
.map(|&(ref name, ref ty, _)| (name.clone(), ty.clone()))
.collect(),
Expand Down Expand Up @@ -286,7 +290,8 @@ impl Source for Struct {
};
write!(out, "{}(", self.name);
out.write_vertical_source_list(
&self.fields
&self
.fields
.iter()
.map(|&(ref name, ref ty, _)| {
// const-ref args to constructor
Expand All @@ -299,7 +304,8 @@ impl Source for Struct {
out.new_line();
write!(out, " : ");
out.write_vertical_source_list(
&self.fields
&self
.fields
.iter()
.map(|x| format!("{}({})", x.0, arg_renamer(&x.0)))
.collect(),
Expand Down Expand Up @@ -332,7 +338,8 @@ impl Source for Struct {
out.open_brace();
out.write("return ");
out.write_vertical_source_list(
&self.fields
&self
.fields
.iter()
.map(|x| format!("{} {} {}.{}", x.0, op, other, x.0))
.collect(),
Expand All @@ -342,32 +349,38 @@ impl Source for Struct {
out.close_brace(false);
};

if config.structure.derive_eq(&self.annotations) && !self.fields.is_empty()
if config.structure.derive_eq(&self.annotations)
&& !self.fields.is_empty()
&& self.fields.iter().all(|x| x.1.can_cmp_eq())
{
emit_op("==", "&&");
}
if config.structure.derive_neq(&self.annotations) && !self.fields.is_empty()
if config.structure.derive_neq(&self.annotations)
&& !self.fields.is_empty()
&& self.fields.iter().all(|x| x.1.can_cmp_eq())
{
emit_op("!=", "||");
}
if config.structure.derive_lt(&self.annotations) && self.fields.len() == 1
if config.structure.derive_lt(&self.annotations)
&& self.fields.len() == 1
&& self.fields[0].1.can_cmp_order()
{
emit_op("<", "&&");
}
if config.structure.derive_lte(&self.annotations) && self.fields.len() == 1
if config.structure.derive_lte(&self.annotations)
&& self.fields.len() == 1
&& self.fields[0].1.can_cmp_order()
{
emit_op("<=", "&&");
}
if config.structure.derive_gt(&self.annotations) && self.fields.len() == 1
if config.structure.derive_gt(&self.annotations)
&& self.fields.len() == 1
&& self.fields[0].1.can_cmp_order()
{
emit_op(">", "&&");
}
if config.structure.derive_gte(&self.annotations) && self.fields.len() == 1
if config.structure.derive_gte(&self.annotations)
&& self.fields.len() == 1
&& self.fields[0].1.can_cmp_order()
{
emit_op(">=", "&&");
Expand All @@ -391,7 +404,8 @@ pub trait SynFieldHelpers {

impl SynFieldHelpers for syn::Field {
fn as_ident_and_type(&self) -> Result<Option<(String, Type, Documentation)>, String> {
let ident = self.ident
let ident = self
.ident
.as_ref()
.ok_or(format!("field is missing identifier"))?
.clone();
Expand Down
8 changes: 5 additions & 3 deletions src/bindgen/ir/typedef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use syn;
use bindgen::config::{Config, Language};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer,
Path, Type};
use bindgen::ir::{
AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer, Path, Type,
};
use bindgen::library::Library;
use bindgen::mangle;
use bindgen::monomorph::Monomorphs;
Expand Down Expand Up @@ -143,7 +144,8 @@ impl Item for Typedef {
generic_values.len(),
);

let mappings = self.generic_params
let mappings = self
.generic_params
.iter()
.zip(generic_values.iter())
.collect::<Vec<_>>();
Expand Down
20 changes: 13 additions & 7 deletions src/bindgen/ir/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use bindgen::config::{Config, Language};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::ir::SynFieldHelpers;
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer,
Repr, Type};
use bindgen::ir::{
AnnotationSet, Cfg, CfgWrite, Documentation, GenericParams, Item, ItemContainer, Repr, Type,
};
use bindgen::library::Library;
use bindgen::mangle;
use bindgen::monomorph::Monomorphs;
Expand All @@ -37,7 +38,8 @@ impl Union {
}

let (fields, tuple_union) = {
let out = item.fields
let out = item
.fields
.named
.iter()
.try_skip_map(|x| x.as_ident_and_type())?;
Expand Down Expand Up @@ -145,7 +147,8 @@ impl Item for Union {

self.fields = overriden_fields;
} else if let Some(r) = find_first_some(&rules) {
self.fields = self.fields
self.fields = self
.fields
.iter()
.map(|x| {
(
Expand Down Expand Up @@ -189,15 +192,17 @@ impl Item for Union {
generic_values.len(),
);

let mappings = self.generic_params
let mappings = self
.generic_params
.iter()
.zip(generic_values.iter())
.collect::<Vec<_>>();

let monomorph = Union {
name: mangle::mangle_path(&self.name, generic_values),
generic_params: GenericParams::default(),
fields: self.fields
fields: self
.fields
.iter()
.map(|x| (x.0.clone(), x.1.specialize(&mappings), x.2.clone()))
.collect(),
Expand Down Expand Up @@ -245,7 +250,8 @@ impl Source for Union {
out.write_vertical_source_list(&self.fields, ListType::Cap(";"));
} else {
out.write_vertical_source_list(
&self.fields
&self
.fields
.iter()
.map(|&(ref name, ref ty, _)| (name.clone(), ty.clone()))
.collect(),
Expand Down
3 changes: 2 additions & 1 deletion src/bindgen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ impl Parser {

let mod_parsed = {
if !self.cache_expanded_crate.contains_key(&pkg.name) {
let s = self.lib
let s = self
.lib
.as_ref()
.unwrap()
.expand_crate(pkg)
Expand Down
12 changes: 8 additions & 4 deletions src/bindgen/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ impl RenameRule {

if let IdentifierType::EnumVariant(e) = context {
if let &RenameRule::QualifiedScreamingSnakeCase = self {
result.push_str(&RenameRule::ScreamingSnakeCase
.apply_to_pascal_case(&e.name, IdentifierType::Enum));
result.push_str(
&RenameRule::ScreamingSnakeCase
.apply_to_pascal_case(&e.name, IdentifierType::Enum),
);
result.push_str("_");
}
}
Expand Down Expand Up @@ -173,8 +175,10 @@ impl RenameRule {

if let IdentifierType::EnumVariant(e) = context {
if let &RenameRule::QualifiedScreamingSnakeCase = self {
result.push_str(&RenameRule::ScreamingSnakeCase
.apply_to_snake_case(&e.name, IdentifierType::Enum));
result.push_str(
&RenameRule::ScreamingSnakeCase
.apply_to_snake_case(&e.name, IdentifierType::Enum),
);
result.push_str("_");
}
}
Expand Down
Loading

0 comments on commit 52a187c

Please sign in to comment.