Просмотр исходного кода

chore: use easier to understand control flow for unsafe code

Since the original change was made, we bumped MSRV to 1.36.0, which
has enabled NLL on Rust 2015.
Dirkjan Ochtman 6 лет назад
Родитель
Сommit
2c0be97dc6
2 измененных файлов с 6 добавлено и 14 удалено
  1. 3 7
      form_urlencoded/src/query_encoding.rs
  2. 3 7
      percent_encoding/lib.rs

+ 3 - 7
form_urlencoded/src/query_encoding.rs

@@ -37,15 +37,11 @@ pub(crate) fn decode_utf8_lossy(input: Cow<[u8]>) -> Cow<str> {
 
 
                     // Given we know the original input bytes are valid UTF-8,
                     // Given we know the original input bytes are valid UTF-8,
                     // and we have ownership of those bytes, we re-use them and
                     // and we have ownership of those bytes, we re-use them and
-                    // return a Cow::Owned here. Ideally we'd put our return statement
-                    // right below this line, but to support the old lexically scoped
-                    // borrow checker the return must be moved to outside the match
-                    // statement.
+                    // return a Cow::Owned here.
+                    Cow::Owned(unsafe { String::from_utf8_unchecked(bytes) })
                 }
                 }
-                Cow::Owned(s) => return Cow::Owned(s),
+                Cow::Owned(s) => Cow::Owned(s),
             }
             }
-
-            Cow::Owned(unsafe { String::from_utf8_unchecked(bytes) })
         }
         }
     }
     }
 }
 }

+ 3 - 7
percent_encoding/lib.rs

@@ -461,15 +461,11 @@ fn decode_utf8_lossy(input: Cow<[u8]>) -> Cow<str> {
 
 
                     // Given we know the original input bytes are valid UTF-8,
                     // Given we know the original input bytes are valid UTF-8,
                     // and we have ownership of those bytes, we re-use them and
                     // and we have ownership of those bytes, we re-use them and
-                    // return a Cow::Owned here. Ideally we'd put our return statement
-                    // right below this line, but to support the old lexically scoped
-                    // borrow checker the return must be moved to outside the match
-                    // statement.
+                    // return a Cow::Owned here.
+                    Cow::Owned(unsafe { String::from_utf8_unchecked(bytes) })
                 }
                 }
-                Cow::Owned(s) => return Cow::Owned(s),
+                Cow::Owned(s) => Cow::Owned(s),
             }
             }
-
-            Cow::Owned(unsafe { String::from_utf8_unchecked(bytes) })
         }
         }
     }
     }
 }
 }