Rollup merge of #90278 - notriddle:notriddle/highlight-ptr, r=jyn541,GuillaumeGomez
rustdoc: use better highlighting for *const, *mut, and &mut This generates more consistent HTML for these RefKeyWord combinations. Before: ![image](https://user-images.githubusercontent.com/1593513/138742752-7e00a3f7-4621-4c62-82d1-3e4c2ef503d1.png) After: ![image](https://user-images.githubusercontent.com/1593513/138743955-90abcdcd-fc88-4e2f-95bb-c1b1635c0001.png)
This commit is contained in:
commit
96c0e71788
@ -469,22 +469,37 @@ impl<'a> Classifier<'a> {
|
||||
// Assume that '&' or '*' is the reference or dereference operator
|
||||
// or a reference or pointer type. Unless, of course, it looks like
|
||||
// a logical and or a multiplication operator: `&&` or `* `.
|
||||
TokenKind::Star => match self.peek() {
|
||||
Some(TokenKind::Whitespace) => Class::Op,
|
||||
TokenKind::Star => match self.tokens.peek() {
|
||||
Some((TokenKind::Whitespace, _)) => Class::Op,
|
||||
Some((TokenKind::Ident, "mut")) => {
|
||||
self.next();
|
||||
sink(Highlight::Token { text: "*mut", class: Some(Class::RefKeyWord) });
|
||||
return;
|
||||
}
|
||||
Some((TokenKind::Ident, "const")) => {
|
||||
self.next();
|
||||
sink(Highlight::Token { text: "*const", class: Some(Class::RefKeyWord) });
|
||||
return;
|
||||
}
|
||||
_ => Class::RefKeyWord,
|
||||
},
|
||||
TokenKind::And => match lookahead {
|
||||
Some(TokenKind::And) => {
|
||||
TokenKind::And => match self.tokens.peek() {
|
||||
Some((TokenKind::And, _)) => {
|
||||
self.next();
|
||||
sink(Highlight::Token { text: "&&", class: Some(Class::Op) });
|
||||
return;
|
||||
}
|
||||
Some(TokenKind::Eq) => {
|
||||
Some((TokenKind::Eq, _)) => {
|
||||
self.next();
|
||||
sink(Highlight::Token { text: "&=", class: Some(Class::Op) });
|
||||
return;
|
||||
}
|
||||
Some(TokenKind::Whitespace) => Class::Op,
|
||||
Some((TokenKind::Whitespace, _)) => Class::Op,
|
||||
Some((TokenKind::Ident, "mut")) => {
|
||||
self.next();
|
||||
sink(Highlight::Token { text: "&mut", class: Some(Class::RefKeyWord) });
|
||||
return;
|
||||
}
|
||||
_ => Class::RefKeyWord,
|
||||
},
|
||||
|
||||
|
@ -15,11 +15,11 @@
|
||||
<span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">target_os</span> <span class="op">=</span> <span class="string">"linux"</span>)]</span>
|
||||
<span class="kw">fn</span> <span class="ident">main</span>() -> () {
|
||||
<span class="kw">let</span> <span class="ident">foo</span> <span class="op">=</span> <span class="bool-val">true</span> <span class="op">&&</span> <span class="bool-val">false</span> <span class="op">|</span><span class="op">|</span> <span class="bool-val">true</span>;
|
||||
<span class="kw">let</span> <span class="kw">_</span>: <span class="kw-2">*</span><span class="kw">const</span> () <span class="op">=</span> <span class="number">0</span>;
|
||||
<span class="kw">let</span> <span class="kw">_</span>: <span class="kw-2">*const</span> () <span class="op">=</span> <span class="number">0</span>;
|
||||
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="kw-2">&</span><span class="ident">foo</span>;
|
||||
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="op">&&</span><span class="ident">foo</span>;
|
||||
<span class="kw">let</span> <span class="kw">_</span> <span class="op">=</span> <span class="kw-2">*</span><span class="ident">foo</span>;
|
||||
<span class="macro">mac!</span>(<span class="ident">foo</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">bar</span>);
|
||||
<span class="macro">mac!</span>(<span class="ident">foo</span>, <span class="kw-2">&mut</span> <span class="ident">bar</span>);
|
||||
<span class="macro">assert!</span>(<span class="self">self</span>.<span class="ident">length</span> <span class="op"><</span> <span class="ident">N</span> <span class="op">&&</span> <span class="ident">index</span> <span class="op"><</span><span class="op">=</span> <span class="self">self</span>.<span class="ident">length</span>);
|
||||
<span class="ident">::std::env::var</span>(<span class="string">"gateau"</span>).<span class="ident">is_ok</span>();
|
||||
<span class="attribute">#[<span class="ident">rustfmt::skip</span>]</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user