Skip to content

Commit

Permalink
Use rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
eqrion committed May 31, 2018
1 parent d192544 commit 155b540
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 88 deletions.
4 changes: 2 additions & 2 deletions src/bindgen/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::io::{Read, Write};
use std::fs;
use std::fs::File;
use std::io::{Read, Write};
use std::path;
use std::fs;

use bindgen::config::{Config, Language};
use bindgen::ir::{Constant, Function, ItemContainer, Static};
Expand Down
12 changes: 9 additions & 3 deletions src/bindgen/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use std::path;

use bindgen::bindings::Bindings;
use bindgen::cargo::Cargo;
use bindgen::config::{Braces, Config, Language};
use bindgen::error::Error;
use bindgen::library::Library;
use bindgen::bindings::Bindings;
use bindgen::parser::{self, Parse};

/// A builder for generating a bindings header.
Expand Down Expand Up @@ -266,10 +266,16 @@ impl Builder {
None,
Some(&binding_lib_name),
self.config.parse.parse_deps,
self.config.parse.clean
self.config.parse.clean,
)?
} else {
Cargo::load(&lib_dir, None, None, self.config.parse.parse_deps, self.config.parse.clean)?
Cargo::load(
&lib_dir,
None,
None,
self.config.parse.parse_deps,
self.config.parse.clean,
)?
};

result.extend_with(&parser::parse_lib(
Expand Down
15 changes: 10 additions & 5 deletions src/bindgen/cargo/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) struct Cargo {

lock: Option<Lock>,
metadata: Metadata,
clean: bool
clean: bool,
}

impl Cargo {
Expand All @@ -43,12 +43,12 @@ impl Cargo {
lock_file: Option<&str>,
binding_crate_name: Option<&str>,
use_cargo_lock: bool,
clean: bool
clean: bool,
) -> Result<Cargo, Error> {
let toml_path = crate_dir.join("Cargo.toml");
let lock_path = match lock_file {
Some(v) => PathBuf::from(v),
None => crate_dir.join("Cargo.lock")
None => crate_dir.join("Cargo.lock"),
};

let lock = if use_cargo_lock {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Cargo {
binding_crate_name: binding_crate_name,
lock: lock,
metadata: metadata,
clean: clean
clean: clean,
})
}

Expand Down Expand Up @@ -198,6 +198,11 @@ impl Cargo {
}

pub(crate) fn expand_crate(&self, package: &PackageRef) -> Result<String, cargo_expand::Error> {
cargo_expand::expand(&self.manifest_path, &package.name, &package.version, self.clean)
cargo_expand::expand(
&self.manifest_path,
&package.name,
&package.version,
self.clean,
)
}
}
9 changes: 7 additions & 2 deletions src/bindgen/cargo/cargo_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::env;
use std::io;
use std::path::Path;
use std::process::Command;
use std::str::{Utf8Error, from_utf8};
use std::str::{from_utf8, Utf8Error};

extern crate tempdir;
use self::tempdir::TempDir;
Expand Down Expand Up @@ -35,7 +35,12 @@ impl From<Utf8Error> for Error {

/// Use rustc to expand and pretty print the crate into a single file,
/// removing any macros in the process.
pub fn expand(manifest_path: &Path, crate_name: &str, version: &str, use_tempdir: bool) -> Result<String, Error> {
pub fn expand(
manifest_path: &Path,
crate_name: &str,
version: &str,
use_tempdir: bool,
) -> Result<String, Error> {
let cargo = env::var("CARGO").unwrap_or_else(|_| String::from("cargo"));
let mut cmd = Command::new(cargo);

Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/cargo/cargo_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::fs::File;
use std::io;
use std::io::Read;
use std::fs::File;
use std::path::Path;

use toml;
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/cargo/cargo_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

use std::collections::HashMap;
use std::env;
use std::process::Command;
use std::str::{Utf8Error, from_utf8};
use std::io;
use std::path::Path;
use std::process::Command;
use std::str::{from_utf8, Utf8Error};

use serde_json;

Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/cargo/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::fs::File;
use std::io;
use std::io::Read;
use std::fs::File;
use std::path::Path;

use toml;
Expand Down
30 changes: 25 additions & 5 deletions src/bindgen/cdecl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,43 @@ impl CDecl {
match t {
&Type::Path(ref path) => {
if is_const {
assert!(self.type_qualifers.len() == 0, "error generating cdecl for {:?}", t);
assert!(
self.type_qualifers.len() == 0,
"error generating cdecl for {:?}",
t
);
self.type_qualifers = "const".to_owned();
}

assert!(self.type_name.len() == 0, "error generating cdecl for {:?}", t);
assert!(
self.type_name.len() == 0,
"error generating cdecl for {:?}",
t
);
self.type_name = path.name.clone();
assert!(self.type_generic_args.len() == 0, "error generating cdecl for {:?}", t);
assert!(
self.type_generic_args.len() == 0,
"error generating cdecl for {:?}",
t
);
self.type_generic_args = path.generics.clone();
self.type_ctype = path.ctype;
}
&Type::Primitive(ref p) => {
if is_const {
assert!(self.type_qualifers.len() == 0, "error generating cdecl for {:?}", t);
assert!(
self.type_qualifers.len() == 0,
"error generating cdecl for {:?}",
t
);
self.type_qualifers = "const".to_owned();
}

assert!(self.type_name.len() == 0, "error generating cdecl for {:?}", t);
assert!(
self.type_name.len() == 0,
"error generating cdecl for {:?}",
t
);
self.type_name = p.to_string();
}

Expand Down
8 changes: 4 additions & 4 deletions src/bindgen/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::default::Default;
use std::collections::HashMap;
use std::default::Default;
use std::fs::File;
use std::io::prelude::*;
use std::io::{self, BufReader};
Expand Down Expand Up @@ -128,8 +128,8 @@ impl FromStr for Style {
match s {
"Both" => Ok(Style::Both),
"both" => Ok(Style::Both),
"Tag" => Ok(Style::Tag),
"tag" => Ok(Style::Tag),
"Tag" => Ok(Style::Tag),
"tag" => Ok(Style::Tag),
"Type" => Ok(Style::Type),
"type" => Ok(Style::Type),
_ => Err(format!("Unrecognized Style: '{}'.", s)),
Expand Down Expand Up @@ -391,7 +391,7 @@ pub struct ParseConfig {
pub expand: Vec<String>,
/// Whether to use a new temporary target directory when running `rustc --pretty=expanded`.
/// This may be required for some build processes.
pub clean: bool
pub clean: bool,
}

impl Default for ParseConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::collections::HashSet;
use std::cmp::Ordering;
use std::collections::HashSet;

use bindgen::ir::{ItemContainer, Path};

Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use std::fmt;

pub use syn::synom::ParseError;
pub use bindgen::cargo::cargo_expand::Error as CargoExpandError;
pub use bindgen::cargo::cargo_metadata::Error as CargoMetadataError;
pub use bindgen::cargo::cargo_toml::Error as CargoTomlError;
pub use bindgen::cargo::cargo_expand::Error as CargoExpandError;
pub use syn::synom::ParseError;

#[derive(Debug)]
pub enum Error {
Expand Down
6 changes: 2 additions & 4 deletions src/bindgen/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ impl Cfg {
ref lit,
..
})) => match lit {
&syn::Lit::Str(ref value) => {
Some(Cfg::Named(format!("{}", ident), value.value()))
}
&syn::Lit::Str(ref value) => Some(Cfg::Named(format!("{}", ident), value.value())),
_ => None,
},
&syn::NestedMeta::Meta(syn::Meta::List(syn::MetaList {
Expand Down Expand Up @@ -146,7 +144,7 @@ impl Cfg {
} else {
None
}
},
}
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/ir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::mem;
use syn;

use bindgen::config::{Config, Language};
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, Item, ItemContainer, Type};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::ir::{AnnotationSet, Cfg, CfgWrite, Documentation, Item, ItemContainer, Type};
use bindgen::writer::{Source, SourceWriter};

#[derive(Debug, Clone)]
Expand Down
33 changes: 18 additions & 15 deletions src/bindgen/ir/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use syn;
use bindgen::config::{Config, Language};
use bindgen::declarationtyperesolver::DeclarationTypeResolver;
use bindgen::dependencies::Dependencies;
use bindgen::library::Library;
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;
use bindgen::writer::{ListType, Source, SourceWriter};
Expand Down Expand Up @@ -107,8 +107,10 @@ impl EnumVariant {
discriminant,
body: body.map(|body| {
(
RenameRule::SnakeCase
.apply_to_pascal_case(&format!("{}", variant.ident), IdentifierType::StructMember),
RenameRule::SnakeCase.apply_to_pascal_case(
&format!("{}", variant.ident),
IdentifierType::StructMember,
),
body,
)
}),
Expand Down Expand Up @@ -320,7 +322,6 @@ impl Source for Enum {
let is_tagged = self.tag.is_some();
let separate_tag = self.repr.style == ReprStyle::C;


// If tagged, we need to emit a proper struct/union wrapper around our enum
if is_tagged && config.language == Language::Cxx {
out.write(if separate_tag { "struct " } else { "union " });
Expand All @@ -334,7 +335,6 @@ impl Source for Enum {
&self.name
};


// Emit the actual enum
if config.language == Language::C {
if size.is_none() && config.style.generate_typedef() {
Expand Down Expand Up @@ -381,7 +381,6 @@ impl Source for Enum {
}
// Done emitting the enum


// If tagged, we need to emit structs for the cases and union them together
if is_tagged {
// Emit the cases for the structs
Expand All @@ -397,7 +396,6 @@ impl Source for Enum {
out.new_line();
out.new_line();


// Emit the actual union
if config.language == Language::C {
if config.style.generate_typedef() {
Expand Down Expand Up @@ -458,11 +456,10 @@ impl Source for Enum {
out.close_brace(true);
}


// Emit convenience methods
if config.language == Language::Cxx &&
config.enumeration.derive_helper_methods(&self.annotations) {

if config.language == Language::Cxx
&& config.enumeration.derive_helper_methods(&self.annotations)
{
for variant in &self.variants {
out.new_line();
out.new_line();
Expand All @@ -482,8 +479,9 @@ impl Source for Enum {

if let Some((_, ref body)) = variant.body {
out.write_vertical_source_list(
&body
.fields.iter().skip(skip_fields)
&body.fields
.iter()
.skip(skip_fields)
.map(|&(ref name, ref ty, _)| {
// const-ref args to constructor
(format!("const& {}", arg_renamer(name)), ty.clone())
Expand All @@ -501,8 +499,13 @@ impl Source for Enum {
if let Some((ref variant_name, ref body)) = variant.body {
for &(ref field_name, ..) in body.fields.iter().skip(skip_fields) {
out.new_line();
write!(out, "result.{}.{} = {};",
variant_name, field_name, arg_renamer(field_name));
write!(
out,
"result.{}.{} = {};",
variant_name,
field_name,
arg_renamer(field_name)
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bindgen/ir/generics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ops::Deref;
use std::io::Write;
use std::ops::Deref;

use syn;

Expand Down
Loading

0 comments on commit 155b540

Please sign in to comment.