Fix printing of constants greater than i128::MAX
This commit is contained in:
parent
004d646633
commit
3535507d53
@ -80,7 +80,7 @@
|
|||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use span::{Edition, EditionedFileId, FileId, MacroCallId, SyntaxContextId};
|
use span::{Edition, EditionedFileId, FileId, MacroCallId, SyntaxContextId};
|
||||||
use stdx::{impl_from, never};
|
use stdx::{format_to, impl_from, never};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasAttrs as _, HasGenericParams, HasName},
|
ast::{self, HasAttrs as _, HasGenericParams, HasName},
|
||||||
format_smolstr, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, ToSmolStr, T,
|
format_smolstr, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, ToSmolStr, T,
|
||||||
@ -2578,10 +2578,16 @@ pub fn render_eval(
|
|||||||
let value = u128::from_le_bytes(mir::pad16(b, false));
|
let value = u128::from_le_bytes(mir::pad16(b, false));
|
||||||
let value_signed =
|
let value_signed =
|
||||||
i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_))));
|
i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_))));
|
||||||
if value >= 10 {
|
let mut result = if let Scalar::Int(_) = s {
|
||||||
return Ok(format!("{value_signed} ({value:#X})"));
|
value_signed.to_string()
|
||||||
} else {
|
} else {
|
||||||
return Ok(format!("{value_signed}"));
|
value.to_string()
|
||||||
|
};
|
||||||
|
if value >= 10 {
|
||||||
|
format_to!(result, " ({value:#X})");
|
||||||
|
return Ok(result);
|
||||||
|
} else {
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1496,6 +1496,24 @@ fn hover_const_static() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hover_unsigned_max_const() {
|
||||||
|
check(
|
||||||
|
r#"const $0A: u128 = -1_i128 as u128;"#,
|
||||||
|
expect![[r#"
|
||||||
|
*A*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
test
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const A: u128 = 340282366920938463463374607431768211455 (0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hover_eval_complex_constants() {
|
fn hover_eval_complex_constants() {
|
||||||
check(
|
check(
|
||||||
|
Loading…
Reference in New Issue
Block a user