about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOblarg <emichaelbrnett@gmail.com>2025-09-19 10:03:14 -0400
committerOblarg <emichaelbrnett@gmail.com>2025-09-19 10:03:14 -0400
commit9ba9869b335b56823753a6ce6614f8dffee4fcf3 (patch)
tree9567a2703975f8adc158649be48b3ead131e3ed6 /src
parent47d6936c7d37898a2de5549dcba8b50b25be21dd (diff)
downloadrust-9ba9869b335b56823753a6ce6614f8dffee4fcf3.tar.gz
rust-9ba9869b335b56823753a6ce6614f8dffee4fcf3.zip
address review feedback
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs
index b8e0599dba2..0076446a958 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs
@@ -285,6 +285,29 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
                 const_type,
                 self.resolver.krate(),
             ),
+            hir_def::hir::Expr::UnaryOp { expr: inner_expr, op: hir_def::hir::UnaryOp::Neg } => {
+                if let hir_def::hir::Expr::Literal(literal) = &self.store[*inner_expr] {
+                    // Only handle negation for signed integers and floats
+                    match literal {
+                        hir_def::hir::Literal::Int(_, _) | hir_def::hir::Literal::Float(_, _) => {
+                            if let Some(negated_literal) = literal.clone().negate() {
+                                intern_const_ref(
+                                    self.db,
+                                    &negated_literal.into(),
+                                    const_type,
+                                    self.resolver.krate(),
+                                )
+                            } else {
+                                unknown_const(const_type)
+                            }
+                        }
+                        // For unsigned integers, chars, bools, etc., negation is not meaningful
+                        _ => unknown_const(const_type),
+                    }
+                } else {
+                    unknown_const(const_type)
+                }
+            }
             _ => unknown_const(const_type),
         }
     }