rust-lang / rust-lang/rust-analyzer

inline_const_as_literal: drops type suffix from numeric literal producing E0689

Open
#22,051 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

inline_const_as_literal drops the type suffix when inlining a typed numeric constant. the resulting bare literal has an ambiguous numeric type causing E0689 when its used as the receiver of a method call that requires a concrete type.

reproduce:

const BASE: i32 = 24i32;
fn main() { let result = BASE.wrapping_add(7i32); }

expected (type suffix preserved. code compiles):

fn main() { let result = 24i32.wrapping_add(7i32); }

actual (type suffix dropped. code dosent compile):

fn main() { let result = 24.wrapping_add(7i32); }

24 is now {integer} — type inference cannot resolve it as the method receiver. rustc gives:

error[E0689]: can't call method `wrapping_add` on ambiguous numeric type `{integer}`

env:

  • rustc: 1.94.0
  • rust-analyzer: 0.3.2854
  • OS: Ubuntu
  • Editor: VS Code

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation of the inline_const_as_literal assist and its existing tests, then reproduce the provided i32 example. Done means inlining preserves the numeric type suffix so the resulting wrapping_add call compiles, with a regression test covering this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.