Skip to content

Commit 0f02309

Browse files
author
Jorge Aparicio
committed
try! -> ?
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
1 parent 0dcc413 commit 0f02309

File tree

132 files changed

+3760
-3775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+3760
-3775
lines changed

src/compiletest/compiletest.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,16 @@ fn collect_tests_from_dir(config: &Config,
280280
-> io::Result<()> {
281281
// Ignore directories that contain a file
282282
// `compiletest-ignore-dir`.
283-
for file in try!(fs::read_dir(dir)) {
284-
let file = try!(file);
283+
for file in fs::read_dir(dir)? {
284+
let file = file?;
285285
if file.file_name() == *"compiletest-ignore-dir" {
286286
return Ok(());
287287
}
288288
}
289289

290-
let dirs = try!(fs::read_dir(dir));
290+
let dirs = fs::read_dir(dir)?;
291291
for file in dirs {
292-
let file = try!(file);
292+
let file = file?;
293293
let file_path = file.path();
294294
debug!("inspecting file {:?}", file_path.display());
295295
if is_test(config, &file_path) {
@@ -310,11 +310,11 @@ fn collect_tests_from_dir(config: &Config,
310310
tests.push(make_test(config, &paths))
311311
} else if file_path.is_dir() {
312312
let relative_file_path = relative_dir_path.join(file.file_name());
313-
try!(collect_tests_from_dir(config,
313+
collect_tests_from_dir(config,
314314
base,
315315
&file_path,
316316
&relative_file_path,
317-
tests));
317+
tests)?;
318318
}
319319
}
320320
Ok(())

src/libcore/fmt/builders.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a, 'b: 'a> fmt::Write for PadAdapter<'a, 'b> {
2929
fn write_str(&mut self, mut s: &str) -> fmt::Result {
3030
while !s.is_empty() {
3131
if self.on_newline {
32-
try!(self.fmt.write_str(" "));
32+
self.fmt.write_str(" ")?;
3333
}
3434

3535
let split = match s.find('\n') {
@@ -42,7 +42,7 @@ impl<'a, 'b: 'a> fmt::Write for PadAdapter<'a, 'b> {
4242
s.len()
4343
}
4444
};
45-
try!(self.fmt.write_str(&s[..split]));
45+
self.fmt.write_str(&s[..split])?;
4646
s = &s[split..];
4747
}
4848

@@ -169,10 +169,10 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
169169
if self.fields > 0 {
170170
self.result = self.result.and_then(|_| {
171171
if self.is_pretty() {
172-
try!(self.fmt.write_str("\n"));
172+
self.fmt.write_str("\n")?;
173173
}
174174
if self.fields == 1 && self.empty_name {
175-
try!(self.fmt.write_str(","));
175+
self.fmt.write_str(",")?;
176176
}
177177
self.fmt.write_str(")")
178178
});

src/libcore/fmt/mod.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -795,24 +795,24 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
795795
None => {
796796
// We can use default formatting parameters for all arguments.
797797
for (arg, piece) in args.args.iter().zip(pieces.by_ref()) {
798-
try!(formatter.buf.write_str(*piece));
799-
try!((arg.formatter)(arg.value, &mut formatter));
798+
formatter.buf.write_str(*piece)?;
799+
(arg.formatter)(arg.value, &mut formatter)?;
800800
}
801801
}
802802
Some(fmt) => {
803803
// Every spec has a corresponding argument that is preceded by
804804
// a string piece.
805805
for (arg, piece) in fmt.iter().zip(pieces.by_ref()) {
806-
try!(formatter.buf.write_str(*piece));
807-
try!(formatter.run(arg));
806+
formatter.buf.write_str(*piece)?;
807+
formatter.run(arg)?;
808808
}
809809
}
810810
}
811811

812812
// There can be only one trailing string piece left.
813813
match pieces.next() {
814814
Some(piece) => {
815-
try!(formatter.buf.write_str(*piece));
815+
formatter.buf.write_str(*piece)?;
816816
}
817817
None => {}
818818
}
@@ -897,9 +897,9 @@ impl<'a> Formatter<'a> {
897897
// Writes the sign if it exists, and then the prefix if it was requested
898898
let write_prefix = |f: &mut Formatter| {
899899
if let Some(c) = sign {
900-
try!(f.buf.write_str(unsafe {
900+
f.buf.write_str(unsafe {
901901
str::from_utf8_unchecked(c.encode_utf8().as_slice())
902-
}));
902+
})?;
903903
}
904904
if prefixed { f.buf.write_str(prefix) }
905905
else { Ok(()) }
@@ -910,26 +910,26 @@ impl<'a> Formatter<'a> {
910910
// If there's no minimum length requirements then we can just
911911
// write the bytes.
912912
None => {
913-
try!(write_prefix(self)); self.buf.write_str(buf)
913+
write_prefix(self)?; self.buf.write_str(buf)
914914
}
915915
// Check if we're over the minimum width, if so then we can also
916916
// just write the bytes.
917917
Some(min) if width >= min => {
918-
try!(write_prefix(self)); self.buf.write_str(buf)
918+
write_prefix(self)?; self.buf.write_str(buf)
919919
}
920920
// The sign and prefix goes before the padding if the fill character
921921
// is zero
922922
Some(min) if self.sign_aware_zero_pad() => {
923923
self.fill = '0';
924-
try!(write_prefix(self));
924+
write_prefix(self)?;
925925
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
926926
f.buf.write_str(buf)
927927
})
928928
}
929929
// Otherwise, the sign and prefix goes after the padding
930930
Some(min) => {
931931
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
932-
try!(write_prefix(f)); f.buf.write_str(buf)
932+
write_prefix(f)?; f.buf.write_str(buf)
933933
})
934934
}
935935
}
@@ -1008,13 +1008,13 @@ impl<'a> Formatter<'a> {
10081008
};
10091009

10101010
for _ in 0..pre_pad {
1011-
try!(self.buf.write_str(fill));
1011+
self.buf.write_str(fill)?;
10121012
}
10131013

1014-
try!(f(self));
1014+
f(self)?;
10151015

10161016
for _ in 0..post_pad {
1017-
try!(self.buf.write_str(fill));
1017+
self.buf.write_str(fill)?;
10181018
}
10191019

10201020
Ok(())
@@ -1033,7 +1033,7 @@ impl<'a> Formatter<'a> {
10331033
if self.sign_aware_zero_pad() {
10341034
// a sign always goes first
10351035
let sign = unsafe { str::from_utf8_unchecked(formatted.sign) };
1036-
try!(self.buf.write_str(sign));
1036+
self.buf.write_str(sign)?;
10371037

10381038
// remove the sign from the formatted parts
10391039
formatted.sign = b"";
@@ -1065,19 +1065,19 @@ impl<'a> Formatter<'a> {
10651065
}
10661066

10671067
if !formatted.sign.is_empty() {
1068-
try!(write_bytes(self.buf, formatted.sign));
1068+
write_bytes(self.buf, formatted.sign)?;
10691069
}
10701070
for part in formatted.parts {
10711071
match *part {
10721072
flt2dec::Part::Zero(mut nzeroes) => {
10731073
const ZEROES: &'static str = // 64 zeroes
10741074
"0000000000000000000000000000000000000000000000000000000000000000";
10751075
while nzeroes > ZEROES.len() {
1076-
try!(self.buf.write_str(ZEROES));
1076+
self.buf.write_str(ZEROES)?;
10771077
nzeroes -= ZEROES.len();
10781078
}
10791079
if nzeroes > 0 {
1080-
try!(self.buf.write_str(&ZEROES[..nzeroes]));
1080+
self.buf.write_str(&ZEROES[..nzeroes])?;
10811081
}
10821082
}
10831083
flt2dec::Part::Num(mut v) => {
@@ -1087,10 +1087,10 @@ impl<'a> Formatter<'a> {
10871087
*c = b'0' + (v % 10) as u8;
10881088
v /= 10;
10891089
}
1090-
try!(write_bytes(self.buf, &s[..len]));
1090+
write_bytes(self.buf, &s[..len])?;
10911091
}
10921092
flt2dec::Part::Copy(buf) => {
1093-
try!(write_bytes(self.buf, buf));
1093+
write_bytes(self.buf, buf)?;
10941094
}
10951095
}
10961096
}
@@ -1349,20 +1349,20 @@ impl Display for bool {
13491349
#[stable(feature = "rust1", since = "1.0.0")]
13501350
impl Debug for str {
13511351
fn fmt(&self, f: &mut Formatter) -> Result {
1352-
try!(f.write_char('"'));
1352+
f.write_char('"')?;
13531353
let mut from = 0;
13541354
for (i, c) in self.char_indices() {
13551355
let esc = c.escape_default();
13561356
// If char needs escaping, flush backlog so far and write, else skip
13571357
if esc.size_hint() != (1, Some(1)) {
1358-
try!(f.write_str(&self[from..i]));
1358+
f.write_str(&self[from..i])?;
13591359
for c in esc {
1360-
try!(f.write_char(c));
1360+
f.write_char(c)?;
13611361
}
13621362
from = i + c.len_utf8();
13631363
}
13641364
}
1365-
try!(f.write_str(&self[from..]));
1365+
f.write_str(&self[from..])?;
13661366
f.write_char('"')
13671367
}
13681368
}
@@ -1377,9 +1377,9 @@ impl Display for str {
13771377
#[stable(feature = "rust1", since = "1.0.0")]
13781378
impl Debug for char {
13791379
fn fmt(&self, f: &mut Formatter) -> Result {
1380-
try!(f.write_char('\''));
1380+
f.write_char('\'')?;
13811381
for c in self.escape_default() {
1382-
try!(f.write_char(c))
1382+
f.write_char(c)?
13831383
}
13841384
f.write_char('\'')
13851385
}

src/libcore/num/dec2flt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> {
214214
}
215215
let (sign, s) = extract_sign(s);
216216
let flt = match parse_decimal(s) {
217-
ParseResult::Valid(decimal) => try!(convert(decimal)),
217+
ParseResult::Valid(decimal) => convert(decimal)?,
218218
ParseResult::ShortcutToInf => T::infinity(),
219219
ParseResult::ShortcutToZero => T::zero(),
220220
ParseResult::Invalid => match s {

src/libcore/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Utf8Error {
240240
/// ```
241241
#[stable(feature = "rust1", since = "1.0.0")]
242242
pub fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
243-
try!(run_utf8_validation(v));
243+
run_utf8_validation(v)?;
244244
Ok(unsafe { from_utf8_unchecked(v) })
245245
}
246246

src/libgraphviz/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
662662
{
663663
fn writeln<W: Write>(w: &mut W, arg: &[&str]) -> io::Result<()> {
664664
for &s in arg {
665-
try!(w.write_all(s.as_bytes()));
665+
w.write_all(s.as_bytes())?;
666666
}
667667
write!(w, "\n")
668668
}
@@ -671,9 +671,9 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
671671
w.write_all(b" ")
672672
}
673673

674-
try!(writeln(w, &["digraph ", g.graph_id().as_slice(), " {"]));
674+
writeln(w, &["digraph ", g.graph_id().as_slice(), " {"])?;
675675
for n in g.nodes().iter() {
676-
try!(indent(w));
676+
indent(w)?;
677677
let id = g.node_id(n);
678678

679679
let escaped = &g.node_label(n).to_dot_string();
@@ -702,12 +702,12 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
702702
}
703703

704704
text.push(";");
705-
try!(writeln(w, &text));
705+
writeln(w, &text)?;
706706
}
707707

708708
for e in g.edges().iter() {
709709
let escaped_label = &g.edge_label(e).to_dot_string();
710-
try!(indent(w));
710+
indent(w)?;
711711
let source = g.source(e);
712712
let target = g.target(e);
713713
let source_id = g.node_id(&source);
@@ -729,7 +729,7 @@ pub fn render_opts<'a, N, E, G, W>(g: &'a G,
729729
}
730730

731731
text.push(";");
732-
try!(writeln(w, &text));
732+
writeln(w, &text)?;
733733
}
734734

735735
writeln(w, &["}"])
@@ -959,7 +959,7 @@ mod tests {
959959
let mut writer = Vec::new();
960960
render(&g, &mut writer).unwrap();
961961
let mut s = String::new();
962-
try!(Read::read_to_string(&mut &*writer, &mut s));
962+
Read::read_to_string(&mut &*writer, &mut s)?;
963963
Ok(s)
964964
}
965965

0 commit comments

Comments
 (0)