diff options
| author | bors <bors@rust-lang.org> | 2024-09-15 23:30:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-09-15 23:30:25 +0000 |
| commit | b9be0f2cb6024d5e4e65943d551ed5c5aa7dbd89 (patch) | |
| tree | a6ab00b9928c56a6b8756843f92b2aafe30fed54 /src/tools | |
| parent | 004d6466338f13f2a8ceb7d39a7fcee9677ff36e (diff) | |
| parent | 3535507d5358fe9bab31e8ac7621e86311eea8ec (diff) | |
| download | rust-b9be0f2cb6024d5e4e65943d551ed5c5aa7dbd89.tar.gz rust-b9be0f2cb6024d5e4e65943d551ed5c5aa7dbd89.zip | |
Auto merge of #18119 - ChayimFriedman2:signed-const, r=HKalbasi
fix: Fix printing of constants greater than `i128::MAX` Fixes #18116.
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir/src/lib.rs | 12 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/hover/tests.rs | 18 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs index e3bd7562083..176c059bf62 100644 --- a/src/tools/rust-analyzer/crates/hir/src/lib.rs +++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs @@ -80,7 +80,7 @@ use nameres::diagnostics::DefDiagnosticKind; use rustc_hash::FxHashSet; use smallvec::SmallVec; use span::{Edition, EditionedFileId, FileId, MacroCallId, SyntaxContextId}; -use stdx::{impl_from, never}; +use stdx::{format_to, impl_from, never}; use syntax::{ ast::{self, HasAttrs as _, HasGenericParams, HasName}, format_smolstr, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, TextRange, ToSmolStr, T, @@ -2578,10 +2578,16 @@ impl Const { let value = u128::from_le_bytes(mir::pad16(b, false)); let value_signed = i128::from_le_bytes(mir::pad16(b, matches!(s, Scalar::Int(_)))); + let mut result = if let Scalar::Int(_) = s { + value_signed.to_string() + } else { + value.to_string() + }; if value >= 10 { - return Ok(format!("{value_signed} ({value:#X})")); + format_to!(result, " ({value:#X})"); + return Ok(result); } else { - return Ok(format!("{value_signed}")); + return Ok(result); } } } diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs index f2e5d24fcc6..8805ead818a 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs @@ -1497,6 +1497,24 @@ const foo$0: u32 = { } #[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] fn hover_eval_complex_constants() { check( r#" |
