diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index 7508484676..9f864179e2 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -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()
diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
index 0cb84866d6..c6b4f5a002 100644
--- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html
+++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html
@@ -176,6 +176,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
let a = |x| x;
let bar = Foo::baz;
+
+ let baz = -42;
+ let baz = -baz;
}
enum Option<T> {
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs
index da20c300e2..dd43f9dd95 100644
--- a/crates/ide/src/syntax_highlighting/tests.rs
+++ b/crates/ide/src/syntax_highlighting/tests.rs
@@ -150,6 +150,9 @@ fn main() {
let a = |x| x;
let bar = Foo::baz;
+
+ let baz = -42;
+ let baz = -baz;
}
enum Option {