mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
fix negative const generic integer literals
This commit is contained in:
parent
958a8d06e3
commit
d0bdedde0e
@ -299,6 +299,29 @@ impl<'a> TyLoweringContext<'a> {
|
|||||||
const_type,
|
const_type,
|
||||||
self.resolver.krate(),
|
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),
|
_ => unknown_const(const_type),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4738,7 +4738,7 @@ fn main() {
|
|||||||
*value*
|
*value*
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let value: Const<_>
|
let value: Const<-1>
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
Loading…
x
Reference in New Issue
Block a user