mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-27 18:26:19 +00:00
address review feedback
This commit is contained in:
parent
d0bdedde0e
commit
30031b84a8
1 changed files with 23 additions and 0 deletions
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue