Skip to content

minor: Sync from rust #15306

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

Merged
merged 2 commits into from
Jul 17, 2023
Merged

minor: Sync from rust #15306

merged 2 commits into from
Jul 17, 2023

Conversation

lnicola
Copy link
Member

@lnicola lnicola commented Jul 17, 2023

No description provided.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 17, 2023
@lnicola
Copy link
Member Author

lnicola commented Jul 17, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jul 17, 2023

📌 Commit 84897fd has been approved by lnicola

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 17, 2023

⌛ Testing commit 84897fd with merge cc2f0ec...

@bors
Copy link
Contributor

bors commented Jul 17, 2023

☀️ Test successful - checks-actions
Approved by: lnicola
Pushing cc2f0ec to master...

@bors bors merged commit cc2f0ec into rust-lang:master Jul 17, 2023
@lnicola lnicola deleted the sync-from-rust branch July 17, 2023 18:35
bors added a commit that referenced this pull request Sep 11, 2024
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`.

https://github.com/rust-lang/rust-analyzer/blob/50882fbfa204027c84753e6d51a1a12884dc1b19/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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants