Skip to content

Commit 17c4985

Browse files
committed
Replace the try! macro with the question mark operator
1 parent fbc02d0 commit 17c4985

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ As a consequence, when calling another parsing function, either:
3131
3232
* Any `Err(())` return value must be propagated.
3333
This happens by definition for tail calls,
34-
and can otherwise be done with the `try!` macro.
34+
and can otherwise be done with the `?` operator.
3535
* Or the call must be wrapped in a `Parser::try` call.
3636
`try` takes a closure that takes a `Parser` and returns a `Result`,
3737
calls it once,
@@ -57,7 +57,7 @@ fn parse_background_image(context: &ParserContext, input: &mut Parser)
5757
// [ <length> | <percentage> ] [ <length> | <percentage> ]?
5858
fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
5959
-> Result<(LengthOrPercentage, LengthOrPercentage), ()> {
60-
let first = try!(LengthOrPercentage::parse);
60+
let first = LengthOrPercentage::parse?;
6161
let second = input.try(LengthOrPercentage::parse).unwrap_or(first);
6262
(first, second)
6363
}

src/nth.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), Basic
2121
} => {
2222
match_ignore_ascii_case! {
2323
&unit,
24-
"n" => Ok(try!(parse_b(input, a))),
25-
"n-" => Ok(try!(parse_signless_b(input, a, -1))),
24+
"n" => Ok(parse_b(input, a)?),
25+
"n-" => Ok(parse_signless_b(input, a, -1)?),
2626
_ => match parse_n_dash_digits(&*unit) {
2727
Ok(b) => Ok((a, b)),
2828
Err(()) => Err(input.new_basic_unexpected_token_error(Token::Ident(unit.clone())))
@@ -33,10 +33,10 @@ pub fn parse_nth<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(i32, i32), Basic
3333
match_ignore_ascii_case! { &value,
3434
"even" => Ok((2, 0)),
3535
"odd" => Ok((2, 1)),
36-
"n" => Ok(try!(parse_b(input, 1))),
37-
"-n" => Ok(try!(parse_b(input, -1))),
38-
"n-" => Ok(try!(parse_signless_b(input, 1, -1))),
39-
"-n-" => Ok(try!(parse_signless_b(input, -1, -1))),
36+
"n" => Ok(parse_b(input, 1)?),
37+
"-n" => Ok(parse_b(input, -1)?),
38+
"n-" => Ok(parse_signless_b(input, 1, -1)?),
39+
"-n-" => Ok(parse_signless_b(input, -1, -1)?),
4040
_ => {
4141
let (slice, a) = if value.starts_with("-") {
4242
(&value[1..], -1)

src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
340340
}
341341

342342
/// Check whether the input is exhausted. That is, if `.next()` would return a token.
343-
/// Return a `Result` so that the `try!` macro can be used: `try!(input.expect_exhausted())`
343+
/// Return a `Result` so that the `?` operator can be used: `input.expect_exhausted()?`
344344
///
345345
/// This ignores whitespace and comments.
346346
#[inline]

src/serializer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ where
284284
///
285285
/// ```{rust,ignore}
286286
/// fn write_foo<W>(foo: &Foo, dest: &mut W) -> fmt::Result where W: fmt::Write {
287-
/// try!(dest.write_str("\""));
287+
/// dest.write_str("\"")?;
288288
/// {
289289
/// let mut string_dest = CssStringWriter::new(dest);
290290
/// // Write into string_dest...
291291
/// }
292-
/// try!(dest.write_str("\""));
292+
/// dest.write_str("\"")?;
293293
/// Ok(())
294294
/// }
295295
/// ```

0 commit comments

Comments
 (0)