Skip to content

Commit 9ad1a8c

Browse files
committed
Don't call tcx.fn_sig on closures
Fixes #68542
1 parent c3681d6 commit 9ad1a8c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/librustc_mir/const_eval/fn_queries.rs

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ pub fn provide(providers: &mut Providers<'_>) {
8686
/// Const evaluability whitelist is here to check evaluability at the
8787
/// top level beforehand.
8888
fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option<bool> {
89+
if tcx.is_closure(def_id) {
90+
return None;
91+
}
92+
8993
match tcx.fn_sig(def_id).abi() {
9094
Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
9195
Some(tcx.lookup_const_stability(def_id).is_some())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for issue #68542
2+
// Tests that we don't ICE when a closure appears
3+
// in the length part of an array.
4+
5+
struct Bug {
6+
a: [(); (|| { 0 })()] //~ ERROR calls in constants are limited to
7+
//~^ ERROR evaluation of constant value failed
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
2+
--> $DIR/issue-68542-closure-in-array-len.rs:6:13
3+
|
4+
LL | a: [(); (|| { 0 })()]
5+
| ^^^^^^^^^^^^
6+
7+
error[E0080]: evaluation of constant value failed
8+
--> $DIR/issue-68542-closure-in-array-len.rs:6:13
9+
|
10+
LL | a: [(); (|| { 0 })()]
11+
| ^^^^^^^^^^^^ calling non-const function `Bug::a::{{constant}}#0::{{closure}}#0`
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors have detailed explanations: E0015, E0080.
16+
For more information about an error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)