-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Hover on floating consts shows zero if their value is positive #12380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We never actually seem to lower the
|
Then I'm even more puzzled why negative numbers work as expected. |
So, the reason for this strange behavior is that const evaluation doesn't support negated unary op for floats: rust-analyzer/crates/hir-ty/src/consteval.rs Line 205 in 1f011fa
Thus, we fall-back to using the syntax tree to render the value: rust-analyzer/crates/ide/src/hover/render.rs Line 353 in 75689f2
However, when handling a raw literal e.g: rust-analyzer/crates/hir-ty/src/consteval.rs Line 159 in 1f011fa
So the fix here would be to fix the lowering code to actually specify a real value for the float. |
On looking into it, the reason it is not implemented over here:
is because of this rust-analyzer/crates/hir-def/src/expr.rs Line 49 in d7c1474
|
If that's not something quick to implement, could we at least fall back to raw literal handling as in
Instead of rendering zero? |
@jhgg would it better to return rust-analyzer/crates/hir-ty/src/consteval.rs Line 159 in d7c1474
And I will add a note around here rust-analyzer/crates/hir-def/src/expr.rs Line 49 in d7c1474
for fixing this error, in case we implement some semi-precisoned/hacky way of |
You could probably use |
We should be able to just encode the float into the u64 as bits, using |
That works too. Personally I'd still use some newtype wrapper that would use |
I'm seeing this issue on |
rust-analyzer version: rust-analyzer version: 81805d4 2022-05-24 nightly
rustc version: rustc 1.60.0 (7737e0b5c 2022-04-04)
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTUP_HOME
orCARGO_HOME
)If I have consts like those:
Then hovering on
INT_POS
,INT_NEG
,F32_NEG
andF64_NEG
shows their values as expected. E.g.:However, hovering
F32_POS
andF64_POS
, for some reason, shows zeros:The text was updated successfully, but these errors were encountered: