Skip to content

improve err msg for "cannot coerce non-statically resolved bare fn" #15273

Closed
@pnkfelix

Description

@pnkfelix
fn bar() {
    for i in range(0, 10u) {
        println!("{}", i)
    }
}

fn callit(f: ||) { f() }

fn main() {
    // callit(bar);
    let f = bar;
    callit(f)
}

play-pen

prints

<anon>:12:12: 12:13 error: cannot coerce non-statically resolved bare fn
<anon>:12     callit(f)
                     ^

We can do better here, e.g. by suggesting to the user that they make the closure construction explicit via eta-expansion, i.e. writing callit(||f()) (or callit(|x|g(x)), etc).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions