Sfoglia il codice sorgente

Fix various clippy warnings

Sebastian Dröge 5 anni fa
parent
commit
eb7330b529
5 ha cambiato i file con 15 aggiunte e 15 eliminazioni
  1. 2 2
      data-url/tests/wpt.rs
  2. 1 1
      idna/tests/uts46.rs
  3. 6 6
      url/src/host.rs
  4. 1 1
      url/src/lib.rs
  5. 5 5
      url/src/parser.rs

+ 2 - 2
data-url/tests/wpt.rs

@@ -17,7 +17,7 @@ fn run_data_url(
     if let Some(expected_mime) = expected_mime {
         let url = url.unwrap();
         let (body, _) = url.decode_to_vec().unwrap();
-        if expected_mime == "" {
+        if expected_mime.is_empty() {
             assert_eq!(url.mime_type().to_string(), "text/plain;charset=US-ASCII")
         } else {
             assert_eq!(url.mime_type().to_string(), expected_mime)
@@ -41,7 +41,7 @@ where
     enum TestCase {
         Two(String, Option<String>),
         Three(String, Option<String>, Vec<u8>),
-    };
+    }
 
     let v: Vec<TestCase> = serde_json::from_str(include_str!("data-urls.json")).unwrap();
     for test in v {

+ 1 - 1
idna/tests/uts46.rs

@@ -14,7 +14,7 @@ use idna::Errors;
 pub fn collect_tests<F: FnMut(String, TestFn)>(add_test: &mut F) {
     // https://www.unicode.org/Public/idna/13.0.0/IdnaTestV2.txt
     for (i, line) in include_str!("IdnaTestV2.txt").lines().enumerate() {
-        if line == "" || line.starts_with('#') {
+        if line.is_empty() || line.starts_with('#') {
             continue;
         }
 

+ 6 - 6
url/src/host.rs

@@ -263,11 +263,11 @@ fn parse_ipv4number(mut input: &str) -> Result<Option<u32>, ()> {
     // So instead we check if the input looks like a real number and only return
     // an error when it's an overflow.
     let valid_number = match r {
-        8 => input.chars().all(|c| c >= '0' && c <= '7'),
-        10 => input.chars().all(|c| c >= '0' && c <= '9'),
-        16 => input
-            .chars()
-            .all(|c| (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')),
+        8 => input.chars().all(|c| ('0'..='7').contains(&c)),
+        10 => input.chars().all(|c| ('0'..='9').contains(&c)),
+        16 => input.chars().all(|c| {
+            ('0'..='9').contains(&c) || ('a'..='f').contains(&c) || ('A'..='F').contains(&c)
+        }),
         _ => false,
     };
 
@@ -302,7 +302,7 @@ fn parse_ipv4addr(input: &str) -> ParseResult<Option<Ipv4Addr>> {
     let mut numbers: Vec<u32> = Vec::new();
     let mut overflow = false;
     for part in parts {
-        if part == "" {
+        if part.is_empty() {
             return Ok(None);
         }
         match parse_ipv4number(part) {

+ 1 - 1
url/src/lib.rs

@@ -1657,7 +1657,7 @@ impl Url {
         }
 
         if let Some(host) = host {
-            if host == "" && SchemeType::from(self.scheme()).is_special() {
+            if host.is_empty() && SchemeType::from(self.scheme()).is_special() {
                 return Err(ParseError::EmptyHost);
             }
             let mut host_substr = host;

+ 5 - 5
url/src/parser.rs

@@ -295,17 +295,17 @@ impl<'i> Input<'i> {
 }
 
 pub trait Pattern {
-    fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool;
+    fn split_prefix(self, input: &mut Input) -> bool;
 }
 
 impl Pattern for char {
-    fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
+    fn split_prefix(self, input: &mut Input) -> bool {
         input.next() == Some(self)
     }
 }
 
 impl<'a> Pattern for &'a str {
-    fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
+    fn split_prefix(self, input: &mut Input) -> bool {
         for c in self.chars() {
             if input.next() != Some(c) {
                 return false;
@@ -316,7 +316,7 @@ impl<'a> Pattern for &'a str {
 }
 
 impl<F: FnMut(char) -> bool> Pattern for F {
-    fn split_prefix<'i>(self, input: &mut Input<'i>) -> bool {
+    fn split_prefix(self, input: &mut Input) -> bool {
         input.next().map_or(false, self)
     }
 }
@@ -1071,7 +1071,7 @@ impl<'a> Parser<'a> {
         Ok((has_host, host, remaining))
     }
 
-    pub fn file_host<'i>(input: Input<'i>) -> ParseResult<(bool, String, Input<'i>)> {
+    pub fn file_host(input: Input) -> ParseResult<(bool, String, Input)> {
         // Undo the Input abstraction here to avoid allocating in the common case
         // where the host part of the input does not contain any tab or newline
         let input_str = input.chars.as_str();