Skip to content

Commit 54aaca8

Browse files
committed
Auto merge of #86249 - FabianWolff:issue-86238, r=varkor
Report an error if resolution of closure call functions failed This pull request fixes #86238. The current implementation seems to assume that resolution of closure call functions (I'm not sure what the proper term is; I mean `call` of `Fn` etc.) can never fail: https://github.com/rust-lang/rust/blob/60f1a2fc4b535ead9c85ce085fdce49b1b097531/compiler/rustc_typeck/src/check/callee.rs#L590-L595 But actually, it can, if the `fn`/`fn_mut`/`fn_once` lang items are not defined, or don't have an associated `call`/`call_mut`/`call_once` function, leading to the ICE described in #86238. I have therefore turned the `span_bug!()` into an error message, which prevents the ICE.
2 parents 7a16cfc + dab25ab commit 54aaca8

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

compiler/rustc_typeck/src/check/callee.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,17 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> {
588588
fcx.write_method_call(self.call_expr.hir_id, method_callee);
589589
}
590590
None => {
591-
span_bug!(
591+
// This can happen if `#![no_core]` is used and the `fn/fn_mut/fn_once`
592+
// lang items are not defined (issue #86238).
593+
let mut err = fcx.inh.tcx.sess.struct_span_err(
592594
self.call_expr.span,
593-
"failed to find an overloaded call trait for closure call"
595+
"failed to find an overloaded call trait for closure call",
594596
);
597+
err.help(
598+
"make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \
599+
and have associated `call`/`call_mut`/`call_once` functions",
600+
);
601+
err.emit();
595602
}
596603
}
597604
}

src/test/ui/lang-items/issue-86238.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for the ICE described in issue #86238.
2+
3+
#![feature(lang_items)]
4+
#![feature(no_core)]
5+
6+
#![no_core]
7+
fn main() {
8+
let one = || {};
9+
one()
10+
//~^ ERROR: failed to find an overloaded call trait for closure call
11+
//~| HELP: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined
12+
}
13+
#[lang = "sized"]
14+
trait Sized {}
15+
#[lang = "copy"]
16+
trait Copy {}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: failed to find an overloaded call trait for closure call
2+
--> $DIR/issue-86238.rs:9:5
3+
|
4+
LL | one()
5+
| ^^^^^
6+
|
7+
= help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)