diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 43d1b8f794c..8ed69962875 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -435,7 +435,27 @@ impl<'a> Classifier<'a> { _ => Class::RefKeyWord, }, - // Operators. + // These can either be operators, or arrows. + TokenKind::Eq => match lookahead { + Some(TokenKind::Eq) => { + self.next(); + sink(Highlight::Token { text: "==", class: Some(Class::Op) }); + return; + } + Some(TokenKind::Gt) => { + self.next(); + sink(Highlight::Token { text: "=>", class: None }); + return; + } + _ => Class::Op, + }, + TokenKind::Minus if lookahead == Some(TokenKind::Gt) => { + self.next(); + sink(Highlight::Token { text: "->", class: None }); + return; + } + + // Other operators. TokenKind::Minus | TokenKind::Plus | TokenKind::Or @@ -443,7 +463,6 @@ impl<'a> Classifier<'a> { | TokenKind::Caret | TokenKind::Percent | TokenKind::Bang - | TokenKind::Eq | TokenKind::Lt | TokenKind::Gt => Class::Op, diff --git a/src/librustdoc/html/highlight/fixtures/sample.html b/src/librustdoc/html/highlight/fixtures/sample.html index 866caea9256..22e650af7e2 100644 --- a/src/librustdoc/html/highlight/fixtures/sample.html +++ b/src/librustdoc/html/highlight/fixtures/sample.html @@ -13,7 +13,7 @@ use std::path::{Path, PathBuf}; #[cfg(target_os = "linux")] -fn main() { +fn main() -> () { let foo = true && false || true; let _: *const () = 0; let _ = &foo; @@ -27,11 +27,11 @@ let mut s = String::new(); match &s { - ref mut x => {} + ref mut x => {} } } macro_rules! bar { - ($foo:tt) => {}; + ($foo:tt) => {}; } diff --git a/src/librustdoc/html/highlight/fixtures/sample.rs b/src/librustdoc/html/highlight/fixtures/sample.rs index b027203655d..fbfdc676733 100644 --- a/src/librustdoc/html/highlight/fixtures/sample.rs +++ b/src/librustdoc/html/highlight/fixtures/sample.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; #[cfg(target_os = "linux")] -fn main() { +fn main() -> () { let foo = true && false || true; let _: *const () = 0; let _ = &foo;