Auto merge of #14796 - jlevesy:jl-match-to-if-let, r=Wafflespeanut

replace match by if let statements if possible

<!-- Please describe your changes on the following line: -->
Hi there,

This PR replaces `match` statements by `if let` when possible.

Thanks for reviewing

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14788

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because this PR is a code cleanup patch.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14796)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-12-31 21:28:41 -08:00 committed by GitHub
commit d967d89fc0
7 changed files with 39 additions and 58 deletions

View file

@ -150,9 +150,8 @@ pub fn str_join<I, T>(strs: I, join: &str) -> String
/// Like AsciiExt::to_ascii_lowercase, but avoids allocating when the input is already lower-case.
pub fn cow_into_ascii_lowercase<'a, S: Into<Cow<'a, str>>>(s: S) -> Cow<'a, str> {
let mut cow = s.into();
match cow.bytes().position(|byte| byte >= b'A' && byte <= b'Z') {
Some(first_uppercase) => cow.to_mut()[first_uppercase..].make_ascii_lowercase(),
None => {}
if let Some(first_uppercase) = cow.bytes().position(|byte| byte >= b'A' && byte <= b'Z') {
cow.to_mut()[first_uppercase..].make_ascii_lowercase();
}
cow
}