6360: Fix unary minus highlighting r=matklad a=Veykril

Fixes #6358

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2020-10-26 13:07:25 +00:00 committed by GitHub
commit 35ed3d2c00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -579,7 +579,14 @@ fn highlight_element(
}
}
T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
HighlightTag::NumericLiteral.into()
let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
let expr = prefix_expr.expr()?;
match expr {
ast::Expr::Literal(_) => HighlightTag::NumericLiteral,
_ => HighlightTag::Operator,
}
.into()
}
_ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
HighlightTag::Operator.into()

View file

@ -176,6 +176,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="keyword">let</span> <span class="variable declaration callable">a</span> <span class="operator">=</span> <span class="punctuation">|</span><span class="value_param declaration">x</span><span class="punctuation">|</span> <span class="value_param">x</span><span class="punctuation">;</span>
<span class="keyword">let</span> <span class="variable declaration callable">bar</span> <span class="operator">=</span> <span class="struct">Foo</span><span class="operator">::</span><span class="function">baz</span><span class="punctuation">;</span>
<span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="numeric_literal">-</span><span class="numeric_literal">42</span><span class="punctuation">;</span>
<span class="keyword">let</span> <span class="variable declaration">baz</span> <span class="operator">=</span> <span class="operator">-</span><span class="variable">baz</span><span class="punctuation">;</span>
<span class="punctuation">}</span>
<span class="keyword">enum</span> <span class="enum declaration">Option</span><span class="punctuation">&lt;</span><span class="type_param declaration">T</span><span class="punctuation">&gt;</span> <span class="punctuation">{</span>

View file

@ -150,6 +150,9 @@ fn main() {
let a = |x| x;
let bar = Foo::baz;
let baz = -42;
let baz = -baz;
}
enum Option<T> {