summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml3
-rw-r--r--src/clang.rs20
-rw-r--r--src/lib.rs5
-rw-r--r--src/parser.rs34
4 files changed, 28 insertions, 34 deletions
diff --git a/.travis.yml b/.travis.yml
index e5a32b77..cf2370a4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -35,6 +35,9 @@ matrix:
- os: osx
env: LLVM_VERSION=3.5
rust: nightly
+ - env: LLVM_VERSION=3.7
+ rust: nightly
+ script: cargo build --features clippy
cache:
directories:
diff --git a/src/clang.rs b/src/clang.rs
index 320e0097..a8c4aace 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -283,12 +283,8 @@ impl SourceLocation {
impl fmt::Display for SourceLocation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (file, line, col, _) = self.location();
- if !file.is_null() {
- try!(file.name().fmt(f));
- try!(":".fmt(f));
- try!(line.fmt(f));
- try!(":".fmt(f));
- col.fmt(f)
+ if let Some(name) = file.name() {
+ write!(f, "{}:{}:{}", name, line, col)
} else {
"builtin definitions".fmt(f)
}
@@ -301,18 +297,14 @@ pub struct File {
}
impl File {
- pub fn name(&self) -> String {
- if self.is_null() {
- return "".to_owned();
+ pub fn name(&self) -> Option<String> {
+ if self.x.is_null() {
+ return None;
}
unsafe {
- String_ { x: clang_getFileName(self.x) }.to_string()
+ Some(String_ { x: clang_getFileName(self.x) }.to_string())
}
}
-
- pub fn is_null(&self) -> bool {
- self.x.is_null()
- }
}
// String
diff --git a/src/lib.rs b/src/lib.rs
index 1fcc61a3..b10546da 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,9 +3,6 @@
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
-#![cfg_attr(feature = "clippy", allow(if_not_else))]
-#![cfg_attr(feature = "clippy", allow(items_after_statements))]
-#![cfg_attr(feature = "clippy", allow(needless_lifetimes))]
extern crate syntex_syntax as syntax;
extern crate libc;
@@ -200,6 +197,8 @@ impl Bindings {
self.write(Box::new(file))
}
+ // https://github.com/Manishearth/rust-clippy/issues/740
+ #[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
pub fn write<'a>(&self, mut writer: Box<Write + 'a>) -> io::Result<()> {
try!(writer.write("/* automatically generated by rust-bindgen */\n\n".as_bytes()));
let mut ps = pprust::rust_printer(writer);
diff --git a/src/parser.rs b/src/parser.rs
index 3271986e..7895aa68 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -38,15 +38,15 @@ struct ClangParserCtx<'a> {
fn match_pattern(ctx: &mut ClangParserCtx, cursor: &Cursor) -> bool {
let (file, _, _, _) = cursor.location().location();
- if file.is_null() {
- return ctx.options.builtins;
- }
+ let name = match file.name() {
+ None => return ctx.options.builtins,
+ Some(name) => name,
+ };
if ctx.options.match_pat.is_empty() {
return true;
}
- let name = file.name();
let mut found = false;
ctx.options.match_pat.iter().all(|pat| {
if (&name[..]).contains(pat) {
@@ -318,8 +318,6 @@ fn opaque_ty(ctx: &mut ClangParserCtx, ty: &cx::Type) {
fn visit_composite(cursor: &Cursor, parent: &Cursor,
ctx: &mut ClangParserCtx,
compinfo: &mut CompInfo) -> Enum_CXVisitorResult {
- let members = &mut compinfo.members;
-
fn is_bitfield_continuation(field: &il::FieldInfo, ty: &il::Type, width: u32) -> bool {
match (&field.bitfields, ty) {
(&Some(ref bitfields), &il::TInt(_, layout)) if *ty == field.ty => {
@@ -329,6 +327,19 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
}
}
+ fn inner_composite(mut ty: &il::Type) -> Option<&Rc<RefCell<CompInfo>>> {
+ loop {
+ match *ty {
+ TComp(ref comp_ty) => return Some(comp_ty),
+ TPtr(ref ptr_ty, _, _) => ty = &**ptr_ty,
+ TArray(ref array_ty, _, _) => ty = &**array_ty,
+ _ => return None
+ }
+ }
+ }
+
+ let members = &mut compinfo.members;
+
match cursor.kind() {
CXCursor_FieldDecl => {
let ty = conv_ty(ctx, &cursor.cur_type(), cursor);
@@ -389,17 +400,6 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
// };
//
- fn inner_composite(mut ty: &il::Type) -> Option<&Rc<RefCell<CompInfo>>> {
- loop {
- match *ty {
- TComp(ref comp_ty) => return Some(comp_ty),
- TPtr(ref ptr_ty, _, _) => ty = &**ptr_ty,
- TArray(ref array_ty, _, _) => ty = &**array_ty,
- _ => return None
- }
- }
- }
-
let is_composite = match (inner_composite(&ty), members.last()) {
(Some(ty_compinfo), Some(&CompMember::Comp(ref c))) => {
c.borrow().deref() as *const _ == ty_compinfo.borrow().deref() as *const _