From d37edef9dd088d953c5e272db37686a338c31778 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 3 Jul 2016 14:38:37 -0700 Subject: prefer `if let` to match with `None => {}` arm in some places This is a spiritual succesor to #34268/8531d581, in which we replaced a number of matches of None to the unit value with `if let` conditionals where it was judged that this made for clearer/simpler code (as would be recommended by Manishearth/rust-clippy's `single_match` lint). The same rationale applies to matches of None to the empty block. --- src/libsyntax_ext/format.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/libsyntax_ext/format.rs') diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index f311f16f11b..dc572e652c6 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -126,16 +126,13 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) panictry!(p.expect(&token::Eq)); let e = panictry!(p.parse_expr()); - match names.get(name) { - None => {} - Some(prev) => { - ecx.struct_span_err(e.span, - &format!("duplicate argument named `{}`", - name)) - .span_note(prev.span, "previously here") - .emit(); - continue - } + if let Some(prev) = names.get(name) { + ecx.struct_span_err(e.span, + &format!("duplicate argument named `{}`", + name)) + .span_note(prev.span, "previously here") + .emit(); + continue; } order.push(name.to_string()); names.insert(name.to_string(), e); @@ -665,13 +662,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, Some(piece) => { if !parser.errors.is_empty() { break } cx.verify_piece(&piece); - match cx.trans_piece(&piece) { - Some(piece) => { - let s = cx.trans_literal_string(); - cx.str_pieces.push(s); - cx.pieces.push(piece); - } - None => {} + if let Some(piece) = cx.trans_piece(&piece) { + let s = cx.trans_literal_string(); + cx.str_pieces.push(s); + cx.pieces.push(piece); } } None => break -- cgit 1.4.1-3-g733a5