Skip to content

Diagnostic: resolve bare fn in expected closure #18409

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

Merged
merged 1 commit into from
Oct 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/librustc/middle/typeck/check/writeback.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -282,7 +282,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
}
_ => {
span_err!(self.tcx().sess, reason.span(self.tcx()), E0100,
"cannot coerce non-statically resolved bare fn");
"cannot coerce non-statically resolved bare fn to closure");
span_help!(self.tcx().sess, reason.span(self.tcx()),
"consider embedding the function in a closure");
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/diagnostics/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ macro_rules! span_note(
})
)

#[macro_export]
macro_rules! span_help(
($session:expr, $span:expr, $($message:tt)*) => ({
($session).span_help($span, format!($($message)*).as_slice())
})
)

#[macro_export]
macro_rules! register_diagnostics(
($($code:tt),*) => (
Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fn foo() {}
fn main() {
let f = foo;
let f_closure: || = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn
//~^ ERROR: cannot coerce non-statically resolved bare fn to closure
//~^ HELP: consider embedding the function in a closure
let f_proc: proc() = f;
//~^ ERROR: cannot coerce non-statically resolved bare fn
//~^ ERROR: cannot coerce non-statically resolved bare fn to closure
//~^ HELP: consider embedding the function in a closure
}