From 6ed16e23b1bd6a294508e2597914977b767c568c Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Sat, 12 Jun 2021 18:32:25 +0200 Subject: [PATCH 1/2] Report an error if resolution of closure call functions failed --- compiler/rustc_typeck/src/check/callee.rs | 11 +++++++++-- src/test/ui/lang-items/issue-86238.rs | 16 ++++++++++++++++ src/test/ui/lang-items/issue-86238.stderr | 10 ++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/lang-items/issue-86238.rs create mode 100644 src/test/ui/lang-items/issue-86238.stderr diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index cb8f336721ad6..9362daa3c889e 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -588,10 +588,17 @@ impl<'a, 'tcx> DeferredCallResolution<'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 0000000000000..509f94f3834a5 --- /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 0000000000000..070f2762634bb --- /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 + From dab25ab56cd7a8132281621ecdf7aee8dfdabd15 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Thu, 1 Jul 2021 13:26:17 +0200 Subject: [PATCH 2/2] Reword error message slightly --- compiler/rustc_typeck/src/check/callee.rs | 2 +- src/test/ui/lang-items/issue-86238.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_typeck/src/check/callee.rs b/compiler/rustc_typeck/src/check/callee.rs index 9362daa3c889e..f55093d82f883 100644 --- a/compiler/rustc_typeck/src/check/callee.rs +++ b/compiler/rustc_typeck/src/check/callee.rs @@ -596,7 +596,7 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> { ); err.help( "make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \ - and have an associated `call`/`call_mut`/`call_once` function", + and have associated `call`/`call_mut`/`call_once` functions", ); err.emit(); } diff --git a/src/test/ui/lang-items/issue-86238.stderr b/src/test/ui/lang-items/issue-86238.stderr index 070f2762634bb..767e6de2263b9 100644 --- a/src/test/ui/lang-items/issue-86238.stderr +++ b/src/test/ui/lang-items/issue-86238.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call 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 + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions error: aborting due to previous error