Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pnkfelix opened this issue Jun 30, 2014 · 3 comments · Fixed by #18409
Closed

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

pnkfelix opened this issue Jun 30, 2014 · 3 comments · Fixed by #18409
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@pnkfelix
Copy link
Member

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).

@huonw
Copy link
Member

huonw commented Jun 30, 2014

It would be nice to say "cannot coerce ... to closure" explicitly too.

@Kleptine
Copy link

Kleptine commented Jul 3, 2014

I'm attempting this as an easy first fix. Are there guidelines for Rust's stance on error message length / style / complexity? I've got a simple fix that just makes the error message: "error: cannot coerce non-statically resolved bare fn to closure. Consider embedding the fn in a closure: callit(||f()) or callit(|x|f(g))".

Currently working to actually embed the names into the message.

@pnkfelix
Copy link
Member Author

pnkfelix commented Jul 3, 2014

@Kleptine I think we often put the longer info into a separate Note, via sess.note or sess.span_note. Would that work out for your "Consider embedding ..." ?

gamazeps added a commit to gamazeps/rust that referenced this issue Oct 29, 2014
Closes rust-lang#15273 (I did not find how to get the identifier in the message
:/)

Also creates the span_help! macro associated with rust-lang#18126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants