Skip to content

Commit

Permalink
Merge pull request rust-lang#291 from nox/clippy
Browse files Browse the repository at this point in the history
Add a Clippy build to Travis
  • Loading branch information
nox committed Mar 12, 2016
2 parents ff2d7a4 + c6adfa4 commit 6f1904e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 6 additions & 14 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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);
Expand Down Expand Up @@ -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 _
Expand Down

0 comments on commit 6f1904e

Please sign in to comment.