Skip to content

Commit

Permalink
Auto merge of rust-lang#38569 - chris-morgan:rustdoc-highlight-kw-2, …
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
bors committed Jan 12, 2017
2 parents ac5046c + c9a6e87 commit 27b9e6d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
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 27b9e6d

Please sign in to comment.