Skip to content

Commit

Permalink
Use Option::filter instead of open-coding it
Browse files Browse the repository at this point in the history
  • Loading branch information
LingMan committed Oct 14, 2020
1 parent 4ba5068 commit 5c1e5cb
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,15 @@ impl<'a> Comments<'a> {
span: rustc_span::Span,
next_pos: Option<BytePos>,
) -> Option<Comment> {
if let Some(cmnt) = self.next() {
if cmnt.style != CommentStyle::Trailing {
return None;
}
let span_line = self.sm.lookup_char_pos(span.hi());
let comment_line = self.sm.lookup_char_pos(cmnt.pos);
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));
if span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
return Some(cmnt);
}
}
self.next().filter(|cmnt| {
cmnt.style == CommentStyle::Trailing && {
let span_line = self.sm.lookup_char_pos(span.hi());
let comment_line = self.sm.lookup_char_pos(cmnt.pos);
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));

None
span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line
}
})
}
}

Expand Down

0 comments on commit 5c1e5cb

Please sign in to comment.