diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2016-06-13 22:43:30 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2016-06-15 08:13:10 -0700 |
| commit | 8531d581046ad782e19ee0e877ef3819a7c123ba (patch) | |
| tree | b2c8a37b33e7b9b6af3a18803020a7cffc2b4f89 /src/libsyntax/print | |
| parent | 6551acc8e560d242f317f4fe4324be0962c5db75 (diff) | |
| download | rust-8531d581046ad782e19ee0e877ef3819a7c123ba.tar.gz rust-8531d581046ad782e19ee0e877ef3819a7c123ba.zip | |
prefer `if let` to match with `None => ()` arm in some places
Casual grepping revealed some places in the codebase (some of which antedated `if let`'s December 2014 stabilization in c200ae5a) where we were using a match with a `None => ()` arm where (in the present author's opinion) an `if let` conditional would be more readable. (Other places where matching to the unit value did seem to better express the intent were left alone.) It's likely that we don't care about making such trivial, non-functional, sheerly æsthetic changes. But if we do, this is a patch.
Diffstat (limited to 'src/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5b9ec924de9..8818acf9aef 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2459,12 +2459,9 @@ impl<'a> State<'a> { } } self.print_ident(path1.node)?; - match *sub { - Some(ref p) => { - word(&mut self.s, "@")?; - self.print_pat(&p)?; - } - None => () + if let Some(ref p) = *sub { + word(&mut self.s, "@")?; + self.print_pat(&p)?; } } PatKind::TupleStruct(ref path, ref elts, ddpos) => { @@ -3008,20 +3005,19 @@ impl<'a> State<'a> { Some(cm) => cm, _ => return Ok(()) }; - match self.next_comment() { - Some(ref cmnt) => { - if (*cmnt).style != comments::Trailing { return Ok(()) } - let span_line = cm.lookup_char_pos(span.hi); - let comment_line = cm.lookup_char_pos((*cmnt).pos); - let mut next = (*cmnt).pos + BytePos(1); - match next_pos { None => (), Some(p) => next = p } - if span.hi < (*cmnt).pos && (*cmnt).pos < next && - span_line.line == comment_line.line { - self.print_comment(cmnt)?; - self.cur_cmnt_and_lit.cur_cmnt += 1; - } + if let Some(ref cmnt) = self.next_comment() { + if (*cmnt).style != comments::Trailing { return Ok(()) } + let span_line = cm.lookup_char_pos(span.hi); + let comment_line = cm.lookup_char_pos((*cmnt).pos); + let mut next = (*cmnt).pos + BytePos(1); + if let Some(p) = next_pos { + next = p; + } + if span.hi < (*cmnt).pos && (*cmnt).pos < next && + span_line.line == comment_line.line { + self.print_comment(cmnt)?; + self.cur_cmnt_and_lit.cur_cmnt += 1; } - _ => () } Ok(()) } |
