Skip to content

Commit 5c1e5cb

Browse files
committed
Use Option::filter instead of open-coding it
1 parent 4ba5068 commit 5c1e5cb

File tree

1 file changed

+8
-12
lines changed
  • compiler/rustc_ast_pretty/src/pprust

1 file changed

+8
-12
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,15 @@ impl<'a> Comments<'a> {
6767
span: rustc_span::Span,
6868
next_pos: Option<BytePos>,
6969
) -> Option<Comment> {
70-
if let Some(cmnt) = self.next() {
71-
if cmnt.style != CommentStyle::Trailing {
72-
return None;
73-
}
74-
let span_line = self.sm.lookup_char_pos(span.hi());
75-
let comment_line = self.sm.lookup_char_pos(cmnt.pos);
76-
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));
77-
if span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line {
78-
return Some(cmnt);
79-
}
80-
}
70+
self.next().filter(|cmnt| {
71+
cmnt.style == CommentStyle::Trailing && {
72+
let span_line = self.sm.lookup_char_pos(span.hi());
73+
let comment_line = self.sm.lookup_char_pos(cmnt.pos);
74+
let next = next_pos.unwrap_or_else(|| cmnt.pos + BytePos(1));
8175

82-
None
76+
span.hi() < cmnt.pos && cmnt.pos < next && span_line.line == comment_line.line
77+
}
78+
})
8379
}
8480
}
8581

0 commit comments

Comments
 (0)