From: Fabian Wolff Date: Sat, 12 Jun 2021 16:32:25 +0000 (+0200) Subject: Report an error if resolution of closure call functions failed X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=6ed16e23b1bd6a294508e2597914977b767c568c;p=rust.git Report an error if resolution of closure call functions failed --- diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index cb8f336721a..9362daa3c88 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -588,10 +588,17 @@ pub fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) { fcx.write_method_call(self.call_expr.hir_id, method_callee); } None => { - span_bug!( + // This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once` + // lang items are not defined (issue #86238). + let mut err = fcx.inh.tcx.sess.struct_span_err( self.call_expr.span, - "failed to find an overloaded call trait for closure call" + "failed to find an overloaded call trait for closure call", ); + err.help( + "make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \ + and have an associated `call`/`call_mut`/`call_once` function", + ); + err.emit(); } } } diff --git a/src/test/ui/lang-items/issue-86238.rs b/src/test/ui/lang-items/issue-86238.rs new file mode 100644 index 00000000000..509f94f3834 --- /dev/null +++ b/src/test/ui/lang-items/issue-86238.rs @@ -0,0 +1,16 @@ +// Regression test for the ICE described in issue #86238. + +#![feature(lang_items)] +#![feature(no_core)] + +#![no_core] +fn main() { + let one = || {}; + one() + //~^ ERROR: failed to find an overloaded call trait for closure call + //~| HELP: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined +} +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} diff --git a/src/test/ui/lang-items/issue-86238.stderr b/src/test/ui/lang-items/issue-86238.stderr new file mode 100644 index 00000000000..070f2762634 --- /dev/null +++ b/src/test/ui/lang-items/issue-86238.stderr @@ -0,0 +1,10 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/issue-86238.rs:9:5 + | +LL | one() + | ^^^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have an associated `call`/`call_mut`/`call_once` function + +error: aborting due to previous error +