summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-03-12 16:56:21 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2016-03-12 16:56:21 +0100
commit7683cc8636d07dd68b14df86bde9c803169e13f7 (patch)
treeee100e4f2c7f428b0bba1ae4f4eff6838508ce58
parent214156a64eb13bc055c7edaa648700a3f6395f15 (diff)
Disallow if_not_else
-rw-r--r--src/clang.rs20
-rw-r--r--src/lib.rs1
-rw-r--r--src/parser.rs8
3 files changed, 10 insertions, 19 deletions
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 eeb788ac..c1a5809c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,7 +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(needless_lifetimes))]
extern crate syntex_syntax as syntax;
diff --git a/src/parser.rs b/src/parser.rs
index 22a79d5f..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) {