Skip to content

inline_const_as_literal: drops type suffix from numeric literal producing E0689 #22051

@Albab-Hasan

Description

@Albab-Hasan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions