Skip to content

Commit 27b9e6d

Browse files
committed
Auto merge of rust-lang#38569 - chris-morgan:rustdoc-highlight-kw-2, r=steveklabnik
Fix rustdoc highlighting of `&` and `*` Whitespace tokens were included, so the span check used with `&` was incorrect, and it was never highlighted as kw-2 (RefKeyword). The `*` in `*foo` and `*const T` should also be highlighted kw-2, so I added them. Note that this *will* cause mishighlighting of code like `1*2`, but that should have been written `1 * 2`. Same deal with `1&2`.
2 parents ac5046c + c9a6e87 commit 27b9e6d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/librustdoc/html/highlight.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ impl<'a> Classifier<'a> {
218218
token::Comment => Class::Comment,
219219
token::DocComment(..) => Class::DocComment,
220220

221-
// If this '&' token is directly adjacent to another token, assume
222-
// that it's the address-of operator instead of the and-operator.
223-
token::BinOp(token::And) if self.lexer.peek().sp.lo == tas.sp.hi => Class::RefKeyWord,
221+
// If this '&' or '*' token is followed by a non-whitespace token, assume that it's the
222+
// reference or dereference operator or a reference or pointer type, instead of the
223+
// bit-and or multiplication operator.
224+
token::BinOp(token::And) | token::BinOp(token::Star)
225+
if self.lexer.peek().tok != token::Whitespace => Class::RefKeyWord,
224226

225227
// Consider this as part of a macro invocation if there was a
226228
// leading identifier.

0 commit comments

Comments
 (0)