Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call tcx.fn_sig on closures #68563

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustc_mir/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/consts/issue-68542-closure-in-array-len.rs
Original file line number Diff line number Diff line change
@@ -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() {}
16 changes: 16 additions & 0 deletions src/test/ui/consts/issue-68542-closure-in-array-len.stderr
Original file line number Diff line number Diff line change
@@ -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`.