Merge pull request #84 from frewsxcv/clippy
Address issues found by rust-clippy
This commit is contained in:
commit
5431cade31
|
@ -10,7 +10,7 @@ impl rustc_serialize::Decoder for Decoder {
|
|||
type Error = DecodeError;
|
||||
fn read_nil(&mut self) -> Result<(), DecodeError> {
|
||||
match self.toml {
|
||||
Some(Value::String(ref s)) if s.len() == 0 => {}
|
||||
Some(Value::String(ref s)) if s.is_empty() => {}
|
||||
Some(Value::String(..)) => return Err(self.err(NilTooLong)),
|
||||
ref found => return Err(self.mismatch("string", found)),
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ impl rustc_serialize::Decoder for Decoder {
|
|||
Some(Value::Table(..)) => {
|
||||
let ret = try!(f(self));
|
||||
match self.toml {
|
||||
Some(Value::Table(ref t)) if t.len() == 0 => {}
|
||||
Some(Value::Table(ref t)) if t.is_empty() => {}
|
||||
_ => return Ok(ret)
|
||||
}
|
||||
self.toml.take();
|
||||
|
@ -243,7 +243,7 @@ impl rustc_serialize::Decoder for Decoder {
|
|||
match self.toml {
|
||||
Some(Value::Array(ref mut arr)) => {
|
||||
arr.retain(|slot| slot.as_integer() != Some(0));
|
||||
if arr.len() != 0 { return Ok(ret) }
|
||||
if !arr.is_empty() { return Ok(ret) }
|
||||
}
|
||||
_ => return Ok(ret)
|
||||
}
|
||||
|
@ -262,12 +262,10 @@ impl rustc_serialize::Decoder for Decoder {
|
|||
};
|
||||
let mut d = self.sub_decoder(Some(toml), "");
|
||||
let ret = try!(f(&mut d));
|
||||
match d.toml {
|
||||
Some(toml) => match self.toml {
|
||||
Some(Value::Array(ref mut arr)) => arr[idx] = toml,
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
if let Some(toml) = d.toml {
|
||||
if let Some(Value::Array(ref mut arr)) = self.toml {
|
||||
arr[idx] = toml;
|
||||
}
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
|
@ -290,7 +288,7 @@ impl rustc_serialize::Decoder for Decoder {
|
|||
let ret = try!(f(self, amt));
|
||||
let leftover = mem::replace(&mut self.leftover_map, prev_map);
|
||||
self.cur_map = prev_iter;
|
||||
if leftover.len() > 0 {
|
||||
if !leftover.is_empty() {
|
||||
self.toml = Some(Value::Table(leftover));
|
||||
}
|
||||
Ok(ret)
|
||||
|
@ -317,9 +315,9 @@ impl rustc_serialize::Decoder for Decoder {
|
|||
if let Some(toml) = d.toml.take() {
|
||||
self.leftover_map.insert(key, toml);
|
||||
}
|
||||
return ret
|
||||
ret
|
||||
}
|
||||
None => return Err(self.err(ExpectedMapElement(idx))),
|
||||
None => Err(self.err(ExpectedMapElement(idx))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,9 +61,8 @@ impl<'a, 'b> Printer<'a, 'b> {
|
|||
match *v {
|
||||
Table(..) => continue,
|
||||
Array(ref a) => {
|
||||
match a.first() {
|
||||
Some(&Table(..)) => continue,
|
||||
_ => {}
|
||||
if let Some(&Table(..)) = a.first() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -108,7 +108,7 @@ impl Value {
|
|||
}
|
||||
|
||||
/// Extracts the string of this value if it is a string.
|
||||
pub fn as_str<'a>(&'a self) -> Option<&'a str> {
|
||||
pub fn as_str(&self) -> Option<&str> {
|
||||
match *self { Value::String(ref s) => Some(&**s), _ => None }
|
||||
}
|
||||
|
||||
|
@ -135,17 +135,17 @@ impl Value {
|
|||
/// ```notrust
|
||||
/// 1979-05-27T07:32:00Z
|
||||
/// ```
|
||||
pub fn as_datetime<'a>(&'a self) -> Option<&'a str> {
|
||||
pub fn as_datetime(&self) -> Option<&str> {
|
||||
match *self { Value::Datetime(ref s) => Some(&**s), _ => None }
|
||||
}
|
||||
|
||||
/// Extracts the array value if it is an array.
|
||||
pub fn as_slice<'a>(&'a self) -> Option<&'a [Value]> {
|
||||
pub fn as_slice(&self) -> Option<&[Value]> {
|
||||
match *self { Value::Array(ref s) => Some(&**s), _ => None }
|
||||
}
|
||||
|
||||
/// Extracts the table value if it is a table.
|
||||
pub fn as_table<'a>(&'a self) -> Option<&'a Table> {
|
||||
pub fn as_table(&self) -> Option<&Table> {
|
||||
match *self { Value::Table(ref s) => Some(s), _ => None }
|
||||
}
|
||||
|
||||
|
@ -187,14 +187,14 @@ impl Value {
|
|||
}
|
||||
|
||||
for key in path.split('.') {
|
||||
match cur_value {
|
||||
&Value::Table(ref hm) => {
|
||||
match *cur_value {
|
||||
Value::Table(ref hm) => {
|
||||
match hm.get(key) {
|
||||
Some(v) => cur_value = v,
|
||||
None => return None
|
||||
}
|
||||
},
|
||||
&Value::Array(ref v) => {
|
||||
Value::Array(ref v) => {
|
||||
match key.parse::<usize>().ok() {
|
||||
Some(idx) if idx < v.len() => cur_value = &v[idx],
|
||||
_ => return None
|
||||
|
|
|
@ -153,7 +153,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
cur += line.len() + 1;
|
||||
}
|
||||
return (self.input.lines().count(), 0)
|
||||
(self.input.lines().count(), 0)
|
||||
}
|
||||
|
||||
fn next_pos(&self) -> usize {
|
||||
|
@ -265,7 +265,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
if !self.expect('.') { return None }
|
||||
}
|
||||
if keys.len() == 0 { return None }
|
||||
if keys.is_empty() { return None }
|
||||
|
||||
// Build the section table
|
||||
let mut table = TomlTable {
|
||||
|
@ -283,7 +283,7 @@ impl<'a> Parser<'a> {
|
|||
if !self.values(&mut ret) { return None }
|
||||
}
|
||||
}
|
||||
if self.errors.len() > 0 {
|
||||
if !self.errors.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(ret.convert())
|
||||
|
@ -309,7 +309,7 @@ impl<'a> Parser<'a> {
|
|||
Some(ret)
|
||||
};
|
||||
match key {
|
||||
Some(ref name) if name.len() == 0 => {
|
||||
Some(ref name) if name.is_empty() => {
|
||||
self.errors.push(ParserError {
|
||||
lo: start,
|
||||
hi: start,
|
||||
|
@ -349,7 +349,7 @@ impl<'a> Parser<'a> {
|
|||
self.comment();
|
||||
self.newline();
|
||||
}
|
||||
return true
|
||||
true
|
||||
}
|
||||
|
||||
fn keyval_sep(&mut self) -> bool {
|
||||
|
@ -381,7 +381,7 @@ impl<'a> Parser<'a> {
|
|||
hi: hi,
|
||||
desc: format!("expected a value"),
|
||||
});
|
||||
return None
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -558,7 +558,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
return Some(Value::String(ret));
|
||||
Some(Value::String(ret))
|
||||
}
|
||||
|
||||
fn number_or_datetime(&mut self, start: usize) -> Option<Value> {
|
||||
|
@ -602,7 +602,7 @@ impl<'a> Parser<'a> {
|
|||
desc: format!("invalid numeric literal"),
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
|
||||
fn integer(&mut self, start: usize, allow_leading_zeros: bool,
|
||||
|
@ -662,7 +662,7 @@ impl<'a> Parser<'a> {
|
|||
hi: pos,
|
||||
desc: format!("numeral cannot end with an underscore"),
|
||||
});
|
||||
return None
|
||||
None
|
||||
} else {
|
||||
Some(s)
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
consume(self);
|
||||
if !self.expect(']') { return None }
|
||||
return Some(Value::Array(ret))
|
||||
Some(Value::Array(ret))
|
||||
}
|
||||
|
||||
fn inline_table(&mut self, _start: usize) -> Option<Value> {
|
||||
|
@ -800,7 +800,7 @@ impl<'a> Parser<'a> {
|
|||
if !self.expect(',') { return None }
|
||||
self.ws();
|
||||
}
|
||||
return Some(Value::Table(ret))
|
||||
Some(Value::Table(ret))
|
||||
}
|
||||
|
||||
fn insert(&mut self, into: &mut TomlTable, key: String, value: Value,
|
||||
|
|
Loading…
Reference in a new issue