From f37557764d0f1ca32d6b0c2525c88e49319e13d3 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 5 Jun 2018 14:36:36 +0100 Subject: [PATCH] Fix the use of closures within #[panic_implementation] --- src/librustc_typeck/check/mod.rs | 2 +- .../panic_implementation-closures.rs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/panic_implementation-closures.rs diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c2c71d90f06..0c1c2ab4817 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1131,7 +1131,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[panic_implementation]` has signature `fn(&PanicInfo) -> !` if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { - if panic_impl_did == fn_hir_id.owner_def_id() { + if panic_impl_did == fcx.tcx.hir.local_def_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { if declared_ret_ty.sty != ty::TyNever { fcx.tcx.sess.span_err( diff --git a/src/test/compile-fail/panic_implementation-closures.rs b/src/test/compile-fail/panic_implementation-closures.rs new file mode 100644 index 00000000000..4fa9a639928 --- /dev/null +++ b/src/test/compile-fail/panic_implementation-closures.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass + +#![crate_type = "rlib"] +#![no_std] +#![feature(panic_implementation)] + +#[panic_implementation] +pub fn panic_fmt(_: &::core::panic::PanicInfo) -> ! { + |x: u8| x; + loop {} +}