Skip to content

Commit 9ba9869

Browse files
author
Oblarg
committed
address review feedback
1 parent 47d6936 commit 9ba9869

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/lower_nextsolver.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,29 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
285285
const_type,
286286
self.resolver.krate(),
287287
),
288+
hir_def::hir::Expr::UnaryOp { expr: inner_expr, op: hir_def::hir::UnaryOp::Neg } => {
289+
if let hir_def::hir::Expr::Literal(literal) = &self.store[*inner_expr] {
290+
// Only handle negation for signed integers and floats
291+
match literal {
292+
hir_def::hir::Literal::Int(_, _) | hir_def::hir::Literal::Float(_, _) => {
293+
if let Some(negated_literal) = literal.clone().negate() {
294+
intern_const_ref(
295+
self.db,
296+
&negated_literal.into(),
297+
const_type,
298+
self.resolver.krate(),
299+
)
300+
} else {
301+
unknown_const(const_type)
302+
}
303+
}
304+
// For unsigned integers, chars, bools, etc., negation is not meaningful
305+
_ => unknown_const(const_type),
306+
}
307+
} else {
308+
unknown_const(const_type)
309+
}
310+
}
288311
_ => unknown_const(const_type),
289312
}
290313
}

0 commit comments

Comments
 (0)