Skip to content

Commit 6f1904e

Browse files
committed
Merge pull request rust-lang#291 from nox/clippy
Add a Clippy build to Travis
2 parents ff2d7a4 + c6adfa4 commit 6f1904e

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ matrix:
3535
- os: osx
3636
env: LLVM_VERSION=3.5
3737
rust: nightly
38+
- env: LLVM_VERSION=3.7
39+
rust: nightly
40+
script: cargo build --features clippy
3841

3942
cache:
4043
directories:

src/clang.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,8 @@ impl SourceLocation {
283283
impl fmt::Display for SourceLocation {
284284
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
285285
let (file, line, col, _) = self.location();
286-
if !file.is_null() {
287-
try!(file.name().fmt(f));
288-
try!(":".fmt(f));
289-
try!(line.fmt(f));
290-
try!(":".fmt(f));
291-
col.fmt(f)
286+
if let Some(name) = file.name() {
287+
write!(f, "{}:{}:{}", name, line, col)
292288
} else {
293289
"builtin definitions".fmt(f)
294290
}
@@ -301,18 +297,14 @@ pub struct File {
301297
}
302298

303299
impl File {
304-
pub fn name(&self) -> String {
305-
if self.is_null() {
306-
return "".to_owned();
300+
pub fn name(&self) -> Option<String> {
301+
if self.x.is_null() {
302+
return None;
307303
}
308304
unsafe {
309-
String_ { x: clang_getFileName(self.x) }.to_string()
305+
Some(String_ { x: clang_getFileName(self.x) }.to_string())
310306
}
311307
}
312-
313-
pub fn is_null(&self) -> bool {
314-
self.x.is_null()
315-
}
316308
}
317309

318310
// String

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
#![cfg_attr(feature = "clippy", feature(plugin))]
55
#![cfg_attr(feature = "clippy", plugin(clippy))]
6-
#![cfg_attr(feature = "clippy", allow(if_not_else))]
7-
#![cfg_attr(feature = "clippy", allow(items_after_statements))]
8-
#![cfg_attr(feature = "clippy", allow(needless_lifetimes))]
96

107
extern crate syntex_syntax as syntax;
118
extern crate libc;
@@ -200,6 +197,8 @@ impl Bindings {
200197
self.write(Box::new(file))
201198
}
202199

200+
// https://github.com/Manishearth/rust-clippy/issues/740
201+
#[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
203202
pub fn write<'a>(&self, mut writer: Box<Write + 'a>) -> io::Result<()> {
204203
try!(writer.write("/* automatically generated by rust-bindgen */\n\n".as_bytes()));
205204
let mut ps = pprust::rust_printer(writer);

src/parser.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ struct ClangParserCtx<'a> {
3838
fn match_pattern(ctx: &mut ClangParserCtx, cursor: &Cursor) -> bool {
3939
let (file, _, _, _) = cursor.location().location();
4040

41-
if file.is_null() {
42-
return ctx.options.builtins;
43-
}
41+
let name = match file.name() {
42+
None => return ctx.options.builtins,
43+
Some(name) => name,
44+
};
4445

4546
if ctx.options.match_pat.is_empty() {
4647
return true;
4748
}
4849

49-
let name = file.name();
5050
let mut found = false;
5151
ctx.options.match_pat.iter().all(|pat| {
5252
if (&name[..]).contains(pat) {
@@ -318,8 +318,6 @@ fn opaque_ty(ctx: &mut ClangParserCtx, ty: &cx::Type) {
318318
fn visit_composite(cursor: &Cursor, parent: &Cursor,
319319
ctx: &mut ClangParserCtx,
320320
compinfo: &mut CompInfo) -> Enum_CXVisitorResult {
321-
let members = &mut compinfo.members;
322-
323321
fn is_bitfield_continuation(field: &il::FieldInfo, ty: &il::Type, width: u32) -> bool {
324322
match (&field.bitfields, ty) {
325323
(&Some(ref bitfields), &il::TInt(_, layout)) if *ty == field.ty => {
@@ -329,6 +327,19 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
329327
}
330328
}
331329

330+
fn inner_composite(mut ty: &il::Type) -> Option<&Rc<RefCell<CompInfo>>> {
331+
loop {
332+
match *ty {
333+
TComp(ref comp_ty) => return Some(comp_ty),
334+
TPtr(ref ptr_ty, _, _) => ty = &**ptr_ty,
335+
TArray(ref array_ty, _, _) => ty = &**array_ty,
336+
_ => return None
337+
}
338+
}
339+
}
340+
341+
let members = &mut compinfo.members;
342+
332343
match cursor.kind() {
333344
CXCursor_FieldDecl => {
334345
let ty = conv_ty(ctx, &cursor.cur_type(), cursor);
@@ -389,17 +400,6 @@ fn visit_composite(cursor: &Cursor, parent: &Cursor,
389400
// };
390401
//
391402

392-
fn inner_composite(mut ty: &il::Type) -> Option<&Rc<RefCell<CompInfo>>> {
393-
loop {
394-
match *ty {
395-
TComp(ref comp_ty) => return Some(comp_ty),
396-
TPtr(ref ptr_ty, _, _) => ty = &**ptr_ty,
397-
TArray(ref array_ty, _, _) => ty = &**array_ty,
398-
_ => return None
399-
}
400-
}
401-
}
402-
403403
let is_composite = match (inner_composite(&ty), members.last()) {
404404
(Some(ty_compinfo), Some(&CompMember::Comp(ref c))) => {
405405
c.borrow().deref() as *const _ == ty_compinfo.borrow().deref() as *const _

0 commit comments

Comments
 (0)