Skip to content

Commit

Permalink
replace try! with ?
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji authored and alexcrichton committed Oct 8, 2019
1 parent 6ee533b commit 9a2ef96
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 175 deletions.
24 changes: 12 additions & 12 deletions src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,25 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), ()> {

let mut elements = 0;
let mut chars = inner.chars();
let mut c = try!(chars.next().ok_or(()));
let mut c = chars.next().ok_or(())?;
while c != 'E' {
// Decode an identifier element's length.
if !c.is_digit(10) {
return Err(());
}
let mut len = 0usize;
while let Some(d) = c.to_digit(10) {
len = try!(len
len = len
.checked_mul(10)
.and_then(|len| len.checked_add(d as usize))
.ok_or(()));
c = try!(chars.next().ok_or(()));
.ok_or(())?;
c = chars.next().ok_or(())?;
}

// `c` already contains the first character of this identifier, skip it and
// all the other characters of this identifier, to reach the next element.
for _ in 0..len {
c = try!(chars.next().ok_or(()));
c = chars.next().ok_or(())?;
}

elements += 1;
Expand Down Expand Up @@ -126,18 +126,18 @@ impl<'a> fmt::Display for Demangle<'a> {
break;
}
if element != 0 {
try!(f.write_str("::"));
f.write_str("::")?;
}
if rest.starts_with("_$") {
rest = &rest[1..];
}
loop {
if rest.starts_with('.') {
if let Some('.') = rest[1..].chars().next() {
try!(f.write_str("::"));
f.write_str("::")?;
rest = &rest[2..];
} else {
try!(f.write_str("."));
f.write_str(".")?;
rest = &rest[1..];
}
} else if rest.starts_with('$') {
Expand Down Expand Up @@ -171,7 +171,7 @@ impl<'a> fmt::Display for Demangle<'a> {
if let (true, Some(c)) = (all_lower_hex, c) {
// FIXME(eddyb) do we need to filter out control codepoints?
if !c.is_control() {
try!(c.fmt(f));
c.fmt(f)?;
rest = after_escape;
continue;
}
Expand All @@ -180,16 +180,16 @@ impl<'a> fmt::Display for Demangle<'a> {
break;
}
};
try!(f.write_str(unescaped));
f.write_str(unescaped)?;
rest = after_escape;
} else if let Some(i) = rest.find(|c| c == '$' || c == '.') {
try!(f.write_str(&rest[..i]));
f.write_str(&rest[..i])?;
rest = &rest[i..];
} else {
break;
}
}
try!(f.write_str(rest));
f.write_str(rest)?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ fn is_ascii_punctuation(c: char) -> bool {
impl<'a> fmt::Display for Demangle<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.style {
None => try!(f.write_str(self.original)),
Some(DemangleStyle::Legacy(ref d)) => try!(fmt::Display::fmt(d, f)),
Some(DemangleStyle::V0(ref d)) => try!(fmt::Display::fmt(d, f)),
None => f.write_str(self.original)?,
Some(DemangleStyle::Legacy(ref d)) => fmt::Display::fmt(d, f)?,
Some(DemangleStyle::V0(ref d)) => fmt::Display::fmt(d, f)?,
}
f.write_str(self.suffix)
}
Expand Down
Loading

0 comments on commit 9a2ef96

Please sign in to comment.