Skip to content

Commit 9a2ef96

Browse files
tesujialexcrichton
authored andcommitted
replace try! with ?
1 parent 6ee533b commit 9a2ef96

File tree

3 files changed

+173
-175
lines changed

3 files changed

+173
-175
lines changed

src/legacy.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,25 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), ()> {
7070

7171
let mut elements = 0;
7272
let mut chars = inner.chars();
73-
let mut c = try!(chars.next().ok_or(()));
73+
let mut c = chars.next().ok_or(())?;
7474
while c != 'E' {
7575
// Decode an identifier element's length.
7676
if !c.is_digit(10) {
7777
return Err(());
7878
}
7979
let mut len = 0usize;
8080
while let Some(d) = c.to_digit(10) {
81-
len = try!(len
81+
len = len
8282
.checked_mul(10)
8383
.and_then(|len| len.checked_add(d as usize))
84-
.ok_or(()));
85-
c = try!(chars.next().ok_or(()));
84+
.ok_or(())?;
85+
c = chars.next().ok_or(())?;
8686
}
8787

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

9494
elements += 1;
@@ -126,18 +126,18 @@ impl<'a> fmt::Display for Demangle<'a> {
126126
break;
127127
}
128128
if element != 0 {
129-
try!(f.write_str("::"));
129+
f.write_str("::")?;
130130
}
131131
if rest.starts_with("_$") {
132132
rest = &rest[1..];
133133
}
134134
loop {
135135
if rest.starts_with('.') {
136136
if let Some('.') = rest[1..].chars().next() {
137-
try!(f.write_str("::"));
137+
f.write_str("::")?;
138138
rest = &rest[2..];
139139
} else {
140-
try!(f.write_str("."));
140+
f.write_str(".")?;
141141
rest = &rest[1..];
142142
}
143143
} else if rest.starts_with('$') {
@@ -171,7 +171,7 @@ impl<'a> fmt::Display for Demangle<'a> {
171171
if let (true, Some(c)) = (all_lower_hex, c) {
172172
// FIXME(eddyb) do we need to filter out control codepoints?
173173
if !c.is_control() {
174-
try!(c.fmt(f));
174+
c.fmt(f)?;
175175
rest = after_escape;
176176
continue;
177177
}
@@ -180,16 +180,16 @@ impl<'a> fmt::Display for Demangle<'a> {
180180
break;
181181
}
182182
};
183-
try!(f.write_str(unescaped));
183+
f.write_str(unescaped)?;
184184
rest = after_escape;
185185
} else if let Some(i) = rest.find(|c| c == '$' || c == '.') {
186-
try!(f.write_str(&rest[..i]));
186+
f.write_str(&rest[..i])?;
187187
rest = &rest[i..];
188188
} else {
189189
break;
190190
}
191191
}
192-
try!(f.write_str(rest));
192+
f.write_str(rest)?;
193193
}
194194

195195
Ok(())

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ fn is_ascii_punctuation(c: char) -> bool {
179179
impl<'a> fmt::Display for Demangle<'a> {
180180
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
181181
match self.style {
182-
None => try!(f.write_str(self.original)),
183-
Some(DemangleStyle::Legacy(ref d)) => try!(fmt::Display::fmt(d, f)),
184-
Some(DemangleStyle::V0(ref d)) => try!(fmt::Display::fmt(d, f)),
182+
None => f.write_str(self.original)?,
183+
Some(DemangleStyle::Legacy(ref d)) => fmt::Display::fmt(d, f)?,
184+
Some(DemangleStyle::V0(ref d)) => fmt::Display::fmt(d, f)?,
185185
}
186186
f.write_str(self.suffix)
187187
}

0 commit comments

Comments
 (0)