Skip to content

Commit

Permalink
Fix rustdoc highlighting of & and *.
Browse files Browse the repository at this point in the history
Whitespace tokens were included, so the span check used with `&` was
incorrect, and it was never highlighted as kw-2.

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`.
  • Loading branch information
chris-morgan committed Dec 23, 2016
1 parent c217ab6 commit c9a6e87
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/librustdoc/html/highlight.rs
Expand Up @@ -218,9 +218,11 @@ impl<'a> Classifier<'a> {
token::Comment => Class::Comment,
token::DocComment(..) => Class::DocComment,

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

// Consider this as part of a macro invocation if there was a
// leading identifier.
Expand Down

0 comments on commit c9a6e87

Please sign in to comment.