Skip to content

Commit 9897a95

Browse files
authored
Rollup merge of rust-lang#121689 - GuillaumeGomez:rustdoc-highlighting-whitespace, r=notriddle
[rustdoc] Prevent inclusion of whitespace character after macro_rules ident Discovered this bug randomly when looking at: ![image](https://github.com/rust-lang/rust/assets/3050060/dca38047-9085-4377-bfac-f98890224be4) We were too eagerly trying to merge tokens that shouldn't be merged together (for example if you have a code comment followed by a code comment, we merge them in one attribute to reduce the DOM size). r? `@notriddle`
2 parents 3628a67 + e9dbf44 commit 9897a95

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/librustdoc/html/highlight.rs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ fn can_merge(class1: Option<Class>, class2: Option<Class>, text: &str) -> bool {
136136
match (class1, class2) {
137137
(Some(c1), Some(c2)) => c1.is_equal_to(c2),
138138
(Some(Class::Ident(_)), None) | (None, Some(Class::Ident(_))) => true,
139+
(Some(Class::Macro(_)), _) => false,
139140
(Some(_), None) | (None, Some(_)) => text.trim().is_empty(),
140141
(None, None) => true,
141142
}

src/librustdoc/html/highlight/fixtures/sample.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
}
3333
}
3434

35-
<span class="macro">macro_rules! </span>bar {
35+
<span class="macro">macro_rules!</span> bar {
3636
(<span class="macro-nonterminal">$foo</span>:tt) =&gt; {};
3737
}
3838
</code></pre>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// We need this option to be enabled for the `foo` macro declaration to ensure
2+
// that the link on the ident is not including whitespace characters.
3+
4+
//@ compile-flags: -Zunstable-options --generate-link-to-definition
5+
#![crate_name = "foo"]
6+
7+
// @has 'src/foo/source-code-highlight.rs.html'
8+
9+
// @hasraw - '<a href="../../foo/macro.foo.html">foo</a>'
10+
#[macro_export]
11+
macro_rules! foo {
12+
() => {}
13+
}
14+
15+
// @hasraw - '<span class="macro">foo!</span>'
16+
foo! {}
17+
18+
// @hasraw - '<a href="../../foo/fn.f.html">f</a>'
19+
#[rustfmt::skip]
20+
pub fn f () {}
21+
// @hasraw - '<a href="../../foo/struct.Bar.html">Bar</a>'
22+
// @hasraw - '<a href="../../foo/struct.Bar.html">Bar</a>'
23+
// @hasraw - '<a href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>'
24+
#[rustfmt::skip]
25+
pub struct Bar ( u32 );
26+
// @hasraw - '<a href="../../foo/enum.Foo.html">Foo</a>'
27+
pub enum Foo {
28+
A,
29+
}

0 commit comments

Comments
 (0)