Skip to content

suggestion for "can't call method ... on ambiguous numeric type" does not account for references #147312

@shepmaster

Description

@shepmaster

Code

(0..10).filter(|&v| v.pow(2) > 0);

Current output

error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}`
 --> src/lib.rs:2:27
  |
2 |     (0..10).filter(|&v| v.pow(2) > 0);
  |                      -    ^^^
  |                      |
  |                      you must specify a type for this binding, like `i32`

Desired output

There are two changes I'd like to see:

  1. Show the exact place to put the type
  2. Show the correct type, with the reference
error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}`
 --> src/lib.rs:2:27
  |
2 |     (0..10).filter(|&v| v.pow(2) > 0);
  |                      -    ^^^
  |                      |
  |                      you must specify a type for this binding
help: specify the type in the closure argument list
  |
2 |     (0..10).filter(|&v: &i32| v.pow(2) > 0);
  |                       ++++++

Rust Version

rustc 1.92.0-nightly (5c7ae0c7e 2025-10-02)
binary: rustc
commit-hash: 5c7ae0c7ed184c603e5224604a9f33ca0e8e0b36
commit-date: 2025-10-02
host: aarch64-apple-darwin
release: 1.92.0-nightly
LLVM version: 21.1.2

Anything else?

Discovered while giving training to newcomers to Rust.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions