rust-analyzer/crates
bors 77e1969c15 Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykril
fix: Fix `inline_const_as_literal` error when the number >= 10

## Description

### The Bug

This PR fixes a small bug in the IDE assistence (`inline_const_as_literal`). When the being-inlined constant is a number and it is greater than or equal to 10, the assistence inserts unexpected string `(0x...)` after the number itself. A simple example is followed:

Current `inline_const_as_literal` changes

```rs
const A: usize = 16;

fn f() -> usize {
    A  // inline the constant
}
```

into

```rs
const A: usize = 16;

fn f() -> usize {
    16 (0x10)
}
```

The bug originates from #14925 & #15306 . #14925 added some unittests, but it just tested the number-inlining behavior when the number is `0`.

50882fbfa2/crates/ide-assists/src/handlers/inline_const_as_literal.rs (L124-L138)

And #15306 modified the behavior of `Const::render_eval` and added the `(0x...)` part after the number (if the number >= `10`). Because of insufficient unittests in #14925, changes about `Const::render_eval` in #15306 introduced this bug with no CI failure.

### The Fix

I think `Const::render_eval` is intended for user-facing value displaying (e.g. hover) and not designed for `inline_const_as_literal`. To fix the bug, I defined a new function named `Const::eval`, which evaluates the value itself faithfully and simply and does nothing else.

## Thanks

Thanks `@roife` for your kind help. Your guidance helped me better understand the code.
2024-09-11 10:48:32 +00:00
..
base-db minor: Downgrade cyclic deps error to warning 2024-09-01 10:02:41 +02:00
cfg Remove unnecessary CfgFlag definition in project-model 2024-08-07 14:27:59 +02:00
hir Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykril 2024-09-11 10:48:32 +00:00
hir-def Correctly escape strings in our quote macro 2024-09-10 19:00:32 +03:00
hir-expand Correctly escape strings in our quote macro 2024-09-10 19:00:32 +03:00
hir-ty Skip checks for cast to dyn traits 2024-09-11 01:40:13 +09:00
ide asm! parsing and lowering fixes 2024-09-05 15:08:16 +02:00
ide-assists Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykril 2024-09-11 10:48:32 +00:00
ide-completion Automatically add semicolon when completing unit-returning functions 2024-09-08 23:41:16 +03:00
ide-db Auto merge of #18041 - roife:fix-issue-17631, r=Veykril 2024-09-09 13:55:20 +00:00
ide-diagnostics Skip checks for cast to dyn traits 2024-09-11 01:40:13 +09:00
ide-ssr Properly account for editions in names 2024-08-16 16:46:24 +03:00
intern chore: fix some comments 2024-09-02 18:33:23 +08:00
limit Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
load-cargo Auto merge of #17864 - Veykril:lsif, r=Veykril 2024-08-12 12:34:31 +00:00
mbe internal: Lay basic ground work for standalone mbe tests 2024-09-01 12:42:44 +02:00
parser fix: Fix parser panicking on invalid asm options 2024-09-05 17:07:10 +02:00
paths Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
proc-macro-api Expand proc-macros in workspace root, not package root 2024-08-27 13:40:24 +02:00
proc-macro-srv fix: Fix TokenStream::to_string implementation dropping quotation marks 2024-08-29 08:45:35 +02:00
proc-macro-srv-cli Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
profile Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
project-model fix: Updating settings should not clobber discovered projects 2024-09-05 15:46:03 -07:00
rust-analyzer Auto merge of #18018 - ChayimFriedman2:unit-ret-complete-semi, r=Veykril 2024-09-11 10:33:43 +00:00
salsa Drop Apache license appendices 2024-08-27 14:52:34 +03:00
span chore: fix some comments 2024-09-02 18:33:23 +08:00
stdx Use crossbeam-channel from the workspace 2024-08-09 23:48:03 +02:00
syntax Auto merge of #18032 - DropDemBits:sed-tree-edits, r=davidbarsky 2024-09-10 14:13:08 +00:00
syntax-bridge internal: Lay basic ground work for standalone mbe tests 2024-09-01 12:42:44 +02:00
test-fixture fix: Always explicitly set trait ref self types when lowering 2024-09-06 14:06:41 +02:00
test-utils fix: Always explicitly set trait ref self types when lowering 2024-09-06 14:06:41 +02:00
text-edit Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
toolchain Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
tt fix: Fix TokenStream::to_string implementation dropping quotation marks 2024-08-29 08:45:35 +02:00
vfs internal: Lay basic ground work for standalone mbe tests 2024-09-01 12:42:44 +02:00
vfs-notify Auto merge of #17843 - mo8it:flycheck, r=Veykril 2024-08-12 09:27:47 +00:00