Skip to content

Commit b2f44f8

Browse files
tesujialexcrichton
authored andcommitted
use if let and while let
1 parent e9a47da commit b2f44f8

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

src/v0.rs

+18-30
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), Invalid> {
4949
parser.skip_path()?;
5050

5151
// Instantiating crate (paths always start with uppercase characters).
52-
match parser.sym.as_bytes().get(parser.next) {
53-
Some(&(b'A'..=b'Z')) => {
54-
parser.skip_path()?;
55-
}
56-
_ => {}
52+
if let Some(&(b'A'..=b'Z')) = parser.sym.as_bytes().get(parser.next) {
53+
parser.skip_path()?;
5754
}
5855

5956
Ok((Demangle { inner }, &parser.sym[parser.next..]))
@@ -374,14 +371,9 @@ impl<'s> Parser<'s> {
374371
let is_punycode = self.eat(b'u');
375372
let mut len = self.digit_10()? as usize;
376373
if len != 0 {
377-
loop {
378-
match self.digit_10() {
379-
Ok(d) => {
380-
len = len.checked_mul(10).ok_or(Invalid)?;
381-
len = len.checked_add(d as usize).ok_or(Invalid)?;
382-
}
383-
Err(Invalid) => break,
384-
}
374+
while let Ok(d) = self.digit_10() {
375+
len = len.checked_mul(10).ok_or(Invalid)?;
376+
len = len.checked_add(d as usize).ok_or(Invalid)?;
385377
}
386378
}
387379

@@ -772,9 +764,8 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
772764
fn print_type(&mut self) -> fmt::Result {
773765
let tag = parse!(self, next);
774766

775-
match basic_type(tag) {
776-
Some(ty) => return self.out.write_str(ty),
777-
None => {}
767+
if let Some(ty) = basic_type(tag) {
768+
return self.out.write_str(ty);
778769
}
779770

780771
match tag {
@@ -840,22 +831,19 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
840831
this.out.write_str("unsafe ")?;
841832
}
842833

843-
match abi {
844-
Some(abi) => {
845-
this.out.write_str("extern \"")?;
846-
847-
// If the ABI had any `-`, they were replaced with `_`,
848-
// so the parts between `_` have to be re-joined with `-`.
849-
let mut parts = abi.split('_');
850-
this.out.write_str(parts.next().unwrap())?;
851-
for part in parts {
852-
this.out.write_str("-")?;
853-
this.out.write_str(part)?;
854-
}
834+
if let Some(abi) = abi {
835+
this.out.write_str("extern \"")?;
855836

856-
this.out.write_str("\" ")?;
837+
// If the ABI had any `-`, they were replaced with `_`,
838+
// so the parts between `_` have to be re-joined with `-`.
839+
let mut parts = abi.split('_');
840+
this.out.write_str(parts.next().unwrap())?;
841+
for part in parts {
842+
this.out.write_str("-")?;
843+
this.out.write_str(part)?;
857844
}
858-
None => {}
845+
846+
this.out.write_str("\" ")?;
859847
}
860848

861849
this.out.write_str("fn(")?;

0 commit comments

Comments
 (0)