Rollup merge of #68563 - Aaron1011:fix/fn-sig-closure, r=varkor

Don't call `tcx.fn_sig` on closures

Fixes #68542
This commit is contained in:
Yuki Okushi 2020-01-28 10:48:16 +09:00 committed by GitHub
commit c38e97cc61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -86,6 +86,10 @@ pub fn provide(providers: &mut Providers<'_>) {
/// Const evaluability whitelist is here to check evaluability at the
/// top level beforehand.
fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option<bool> {
if tcx.is_closure(def_id) {
return None;
}
match tcx.fn_sig(def_id).abi() {
Abi::RustIntrinsic | Abi::PlatformIntrinsic => {
Some(tcx.lookup_const_stability(def_id).is_some())

View File

@ -0,0 +1,10 @@
// Regression test for issue #68542
// Tests that we don't ICE when a closure appears
// in the length part of an array.
struct Bug {
a: [(); (|| { 0 })()] //~ ERROR calls in constants are limited to
//~^ ERROR evaluation of constant value failed
}
fn main() {}

View File

@ -0,0 +1,16 @@
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-68542-closure-in-array-len.rs:6:13
|
LL | a: [(); (|| { 0 })()]
| ^^^^^^^^^^^^
error[E0080]: evaluation of constant value failed
--> $DIR/issue-68542-closure-in-array-len.rs:6:13
|
LL | a: [(); (|| { 0 })()]
| ^^^^^^^^^^^^ calling non-const function `Bug::a::{{constant}}#0::{{closure}}#0`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0015, E0080.
For more information about an error, try `rustc --explain E0015`.