Skip to content

"Try invoking the function" hint #63100

Closed
@Patryk27

Description

@Patryk27

Hi,

Let's consider following code:

fn foo() -> usize {
    0
}

fn bar(i: usize) {
    
}

fn main() {
    bar(foo);
}

Right now it fails with the expected usize, found fn item message - I think it would be helpful if compiler bragged about missing parentheses when function's return type matches expected type:

fn main() {
    bar(foo);
//      ^^^ expected usize, found fn item
//          hint: try invoking the function: foo()
}

It may even help a little bit when dealing with async functions - recently I've written:

async fn foo() {
    
}

fn bar(f: impl Future<Output=()>) {
    
}

fn main() {
    bar(foo);
}

... and it took me a few minutes to notice that what I actually wanted was bar(foo()).

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.T-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