Skip to content

Commit 89d1e98

Browse files
committed
Re-use closure instead of open-coding it again, just for one param
1 parent 44f8cf3 commit 89d1e98

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -950,19 +950,19 @@ impl<'src> Classifier<'src> {
950950
let file_span = self.file_span;
951951
let no_highlight =
952952
|| (new_span(before, text, file_span), Highlight::Token { text, class: None });
953-
let mut whitespace = || {
953+
let mut whitespace = |class| {
954954
let mut start = 0u32;
955955
for part in text.split('\n').intersperse("\n").filter(|s| !s.is_empty()) {
956956
sink(
957957
new_span(before + start, part, file_span),
958-
Highlight::Token { text: part, class: None },
958+
Highlight::Token { text: part, class },
959959
);
960960
start += part.len() as u32;
961961
}
962962
};
963963
let class = match token {
964964
TokenKind::Whitespace => {
965-
whitespace();
965+
whitespace(None);
966966
return;
967967
}
968968
TokenKind::LineComment { doc_style } | TokenKind::BlockComment { doc_style, .. } => {
@@ -986,7 +986,7 @@ impl<'src> Classifier<'src> {
986986
// a logical and or a multiplication operator: `&&` or `* `.
987987
TokenKind::Star => match self.tokens.peek() {
988988
Some((TokenKind::Whitespace, _)) => {
989-
whitespace();
989+
whitespace(None);
990990
return;
991991
}
992992
Some((TokenKind::Ident, "mut")) => {
@@ -1019,7 +1019,7 @@ impl<'src> Classifier<'src> {
10191019
return;
10201020
}
10211021
Some((TokenKind::Whitespace, _)) => {
1022-
whitespace();
1022+
whitespace(None);
10231023
return;
10241024
}
10251025
Some((TokenKind::Ident, "mut")) => {
@@ -1206,14 +1206,7 @@ impl<'src> Classifier<'src> {
12061206
};
12071207
// Anything that didn't return above is the simple case where we the
12081208
// class just spans a single token, so we can use the `string` method.
1209-
let mut start = 0u32;
1210-
for part in text.split('\n').intersperse("\n").filter(|s| !s.is_empty()) {
1211-
sink(
1212-
new_span(before + start, part, file_span),
1213-
Highlight::Token { text: part, class: Some(class) },
1214-
);
1215-
start += part.len() as u32;
1216-
}
1209+
whitespace(Some(class));
12171210
}
12181211

12191212
fn peek(&mut self) -> Option<TokenKind> {

0 commit comments

Comments
 (0)