Skip to content

Look for similar functions that might be available when encountering type mismatch on resolved fn call argument #164647

Open

Description

@estebank

Noticed when looking at #164589

On type mismatch on resolved associated functions, we currently output a diagnostic like the following:

[INFO] [stdout] error[E0308]: mismatched types
[INFO] [stdout]   --> src/main.rs:29:3
[INFO] [stdout]    |
[INFO] [stdout] 28 |     let mut nns: Vec<NeuralNetwork> = Vec::from_fn(
[INFO] [stdout]    |                                       ------------ arguments to this function are incorrect
[INFO] [stdout] 29 |         NUMBER_OF_NNS as u32,
[INFO] [stdout]    |         ^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u32`
[INFO] [stdout]    |
[INFO] [stdout] note: associated function defined here
[INFO] [stdout]   --> /rustc/e3feeb59cd1bdd011a2bfcc0747b55125d9b8527/library/alloc/src/vec/mod.rs:795:11
[INFO] [stdout] help: you can convert a `u32` to a `usize` and panic if the converted value doesn't fit
[INFO] [stdout]    |
[INFO] [stdout] 29 |         (NUMBER_OF_NNS as u32).try_into().unwrap(),
[INFO] [stdout]    |         +                    +++++++++++++++++++++

although serviceable, this diagnostic doesn't account that there's a different from_fn available for Vec (in that project) for which the params would have been correct. Ideally we'd provide a structured suggestion, but at the very least, when we've got enough information to point "arguments to this function are incorrect", it would be nice to look for other functions with the same/similar name within the same module/type (like detecting that foo::from_fn should have been foo::try_from_fn or foo::from_fn_in).

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    P-lowLow priority
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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