rust-lang / rust-lang/rust-analyzer
inline_const_as_literal: drops type suffix from numeric literal producing E0689
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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