From 617e13548fded5d8b1deafc73c60db8677dc4886 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 15 Mar 2021 15:44:07 -0700 Subject: [PATCH 1/2] rustdoc: highlight macros more efficiently Instead of producing `assert_eq!`, just produce `assert_eq!`. --- src/librustdoc/html/highlight.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 7e50d72e60f7d..3a4319d5d9aad 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -189,7 +189,9 @@ impl<'a> Classifier<'a> { // leading identifier. TokenKind::Bang if self.in_macro => { self.in_macro = false; - Class::Macro + sink(Highlight::Token { text, class: None }); + sink(Highlight::ExitSpan); + return; } // Assume that '&' or '*' is the reference or dereference operator @@ -298,7 +300,9 @@ impl<'a> Classifier<'a> { }, TokenKind::Ident | TokenKind::RawIdent if lookahead == Some(TokenKind::Bang) => { self.in_macro = true; - Class::Macro + sink(Highlight::EnterSpan { class: Class::Macro }); + sink(Highlight::Token { text, class: None }); + return; } TokenKind::Ident => match text { "ref" | "mut" => Class::RefKeyWord, From f64038f9833f1940f64276fcab9bd53f21f9443b Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 2 Apr 2021 17:46:12 -0700 Subject: [PATCH 2/2] rustdoc: update macro highlight tests --- src/librustdoc/html/highlight/fixtures/dos_line.html | 2 +- src/librustdoc/html/highlight/fixtures/sample.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/highlight/fixtures/dos_line.html b/src/librustdoc/html/highlight/fixtures/dos_line.html index 4400f85681d8a..1c8dbffe78c22 100644 --- a/src/librustdoc/html/highlight/fixtures/dos_line.html +++ b/src/librustdoc/html/highlight/fixtures/dos_line.html @@ -1,3 +1,3 @@ pub fn foo() { -println!("foo"); +println!("foo"); } diff --git a/src/librustdoc/html/highlight/fixtures/sample.html b/src/librustdoc/html/highlight/fixtures/sample.html index d937246f4665a..4966e0ac6bbd3 100644 --- a/src/librustdoc/html/highlight/fixtures/sample.html +++ b/src/librustdoc/html/highlight/fixtures/sample.html @@ -17,11 +17,11 @@ let _ = &foo; let _ = &&foo; let _ = *foo; - mac!(foo, &mut bar); - assert!(self.length < N && index <= self.length); + mac!(foo, &mut bar); + assert!(self.length < N && index <= self.length); } -macro_rules! bar { +macro_rules! bar { ($foo:tt) => {}; }