Skip to content

When calling a function that is actually a method, mention it #102518

@estebank

Description

@estebank

Given code like cos(3.3); where cos is a method of f64, we currently look for free functions elsewhere in the dependency tree:

error[E0425]: cannot find function `cos` in this scope
 --> src/main.rs:2:13
  |
2 |     let _ = cos(3.3);
  |             ^^^ not found in this scope
  |
help: consider importing this function
  |
1 | use libm::cos;
  |

But we should also check for existence of methods under that name for its sole argument.

error[E0425]: cannot find function `cos` in this scope
 --> src/main.rs:2:13
  |
2 |     let _ = cos(3.3);
  |             ^^^ not found in this scope
  |
help: you might have meant to call method `f64::cos`
  |
2 |     let _ = 3.3.cos();
  |             ~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-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