style(lib): address clippy code style warnings

* Remove unnecessary return statements.

* Combine identical `match` arms.

* Collapse nested conditional.

* Use `assert_ne` where applicable.

* Lifetime elision.
This commit is contained in:
Corey Farwell
2017-06-12 23:16:20 -04:00
committed by Sean McArthur
parent 5d19ef88b4
commit 1059eb349a
14 changed files with 38 additions and 49 deletions

View File

@@ -222,16 +222,16 @@ mod tests {
// left has more params
cookie.append("foo", "bar");
assert!(cookie != cookie2);
assert_ne!(cookie, cookie2);
// same len, different params
cookie2.append("bar", "foo");
assert!(cookie != cookie2);
assert_ne!(cookie, cookie2);
// right has more params, and matching KV
cookie2.append("foo", "bar");
assert!(cookie != cookie2);
assert_ne!(cookie, cookie2);
// same params, different order
cookie.append("bar", "foo");

View File

@@ -505,14 +505,13 @@ impl FromStr for Link {
// https://tools.ietf.org/html/rfc5988#section-5.3
if link_header.rel.is_none() {
link_header.rel = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => {
s.trim_matches(|c: char| c == '"' || c.is_whitespace())
.split(' ')
.map(|t| t.trim().parse())
.collect::<Result<Vec<RelationType>, _>>()
.or_else(|_| return Err(::Error::Header))
.or_else(|_| Err(::Error::Header))
.ok()
},
};
@@ -521,8 +520,7 @@ impl FromStr for Link {
// Parse the `Context IRI`.
// https://tools.ietf.org/html/rfc5988#section-5.2
link_header.anchor = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) {
Err(_) => return Err(::Error::Header),
Ok(a) => Some(String::from(a)),
@@ -533,14 +531,13 @@ impl FromStr for Link {
// https://tools.ietf.org/html/rfc5988#section-5.3
if link_header.rev.is_none() {
link_header.rev = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => {
s.trim_matches(|c: char| c == '"' || c.is_whitespace())
.split(' ')
.map(|t| t.trim().parse())
.collect::<Result<Vec<RelationType>, _>>()
.or_else(|_| return Err(::Error::Header))
.or_else(|_| Err(::Error::Header))
.ok()
},
}
@@ -552,8 +549,7 @@ impl FromStr for Link {
v.push(
match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => match s.trim().parse() {
Err(_) => return Err(::Error::Header),
Ok(t) => t,
@@ -567,14 +563,13 @@ impl FromStr for Link {
// https://tools.ietf.org/html/rfc5988#section-5.4
if link_header.media_desc.is_none() {
link_header.media_desc = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => {
s.trim_matches(|c: char| c == '"' || c.is_whitespace())
.split(',')
.map(|t| t.trim().parse())
.collect::<Result<Vec<MediaDesc>, _>>()
.or_else(|_| return Err(::Error::Header))
.or_else(|_| Err(::Error::Header))
.ok()
},
};
@@ -584,8 +579,7 @@ impl FromStr for Link {
// https://tools.ietf.org/html/rfc5988#section-5.4
if link_header.title.is_none() {
link_header.title = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) {
Err(_) => return Err(::Error::Header),
Ok(t) => Some(String::from(t)),
@@ -600,8 +594,7 @@ impl FromStr for Link {
// https://tools.ietf.org/html/rfc5987#section-3.2.1
if link_header.title_star.is_none() {
link_header.title_star = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => Some(String::from(s.trim())),
};
}
@@ -610,8 +603,7 @@ impl FromStr for Link {
// https://tools.ietf.org/html/rfc5988#section-5.4
if link_header.media_type.is_none() {
link_header.media_type = match link_param_split.next() {
None => return Err(::Error::Header),
Some("") => return Err(::Error::Header),
None | Some("") => return Err(::Error::Header),
Some(s) => match verify_and_trim(s.trim(), (b'"', b'"')) {
Err(_) => return Err(::Error::Header),
Ok(t) => match t.parse() {

View File

@@ -104,8 +104,8 @@ impl FromStr for StrictTransportSecurity {
.fold(Ok((None, None)), |res, dir| match (res, dir) {
(Ok((None, sub)), Ok(Directive::MaxAge(age))) => Ok((Some(age), sub)),
(Ok((age, None)), Ok(Directive::IncludeSubdomains)) => Ok((age, Some(()))),
(Ok((Some(_), _)), Ok(Directive::MaxAge(_))) => Err(::Error::Header),
(Ok((_, Some(_))), Ok(Directive::IncludeSubdomains)) => Err(::Error::Header),
(Ok((Some(_), _)), Ok(Directive::MaxAge(_))) |
(Ok((_, Some(_))), Ok(Directive::IncludeSubdomains)) |
(_, Err(_)) => Err(::Error::Header),
(res, _) => res
})

View File

@@ -109,7 +109,7 @@ impl<V: ?Sized + Any + 'static> PtrMapCell<V> {
let one = mem::replace(map, PtrMap::Empty);
match one {
PtrMap::One(id, one) => {
debug_assert!(id != key);
debug_assert_ne!(id, key);
let mut hm = HashMap::with_capacity(2);
hm.insert(id, one);
hm.insert(key, val);

View File

@@ -918,7 +918,7 @@ mod tests {
headers1.set(ContentLength(11));
headers2.set(Host::new("foo.bar", None));
assert!(headers1 != headers2);
assert_ne!(headers1, headers2);
headers1 = Headers::new();
headers2 = Headers::new();
@@ -928,7 +928,7 @@ mod tests {
assert_eq!(headers1, headers2);
headers1.set(ContentLength(10));
assert!(headers1 != headers2);
assert_ne!(headers1, headers2);
headers1 = Headers::new();
headers2 = Headers::new();
@@ -936,7 +936,7 @@ mod tests {
headers1.set(Host::new("foo.bar", None));
headers1.set(ContentLength(11));
headers2.set(ContentLength(11));
assert!(headers1 != headers2);
assert_ne!(headers1, headers2);
}
#[cfg(feature = "nightly")]

View File

@@ -231,7 +231,7 @@ impl ::std::ops::Index<usize> for Raw {
macro_rules! literals {
($($len:expr => $($value:expr),+;)+) => (
fn maybe_literal<'a>(s: Cow<'a, [u8]>) -> Bytes {
fn maybe_literal(s: Cow<[u8]>) -> Bytes {
match s.len() {
$($len => {
$(