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