Skip to content

add #[panic_handler]; deprecate #[panic_implementation] #53619

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

Merged
merged 4 commits into from
Aug 26, 2018
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
6 changes: 3 additions & 3 deletions src/doc/unstable-book/src/language-features/used.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ This condition can be met using `#[used]` and `#[link_section]` plus a linker
script.

``` rust,ignore
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![feature(used)]
#![no_main]
#![no_std]
Expand All @@ -102,8 +102,8 @@ extern "C" fn reset_handler() -> ! {
#[used]
static RESET_HANDLER: extern "C" fn() -> ! = reset_handler;

#[panic_implementation]
fn panic_impl(info: &PanicInfo) -> ! {
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
loop {}
}
```
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt,
}

// (To be) stable attribute for #[lang = "panic_impl"]
if attr::contains_name(attrs, "panic_implementation") {
if attr::contains_name(attrs, "panic_implementation") ||
attr::contains_name(attrs, "panic_handler")
{
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
if let Some(value) = attribute.value_str() {
return Some((value, attribute.span));
}
} else if attribute.check_name("panic_implementation") {
} else if attribute.check_name("panic_implementation") ||
attribute.check_name("panic_handler")
{
return Some((Symbol::intern("panic_impl"), attribute.span))
} else if attribute.check_name("alloc_error_handler") {
return Some((Symbol::intern("oom"), attribute.span))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/weak_lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
!whitelisted(tcx, lang_items::$item) &&
items.$name().is_none() {
if lang_items::$item == lang_items::PanicImplLangItem {
tcx.sess.err(&format!("`#[panic_implementation]` function required, \
tcx.sess.err(&format!("`#[panic_handler]` function required, \
but not found"));
} else if lang_items::$item == lang_items::OomLangItem {
tcx.sess.err(&format!("`#[alloc_error_handler]` function required, \
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
if !generics.params.is_empty() {
fcx.tcx.sess.span_err(
span,
"`#[panic_implementation]` function should have no type \
parameters",
"should have no type parameters",
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@
#![feature(doc_alias)]
#![feature(doc_keyword)]
#![feature(panic_info_message)]
#![feature(panic_implementation)]
#![cfg_attr(stage0, feature(panic_implementation))]
#![cfg_attr(not(stage0), feature(panic_handler))]
#![feature(non_exhaustive)]

#![default_lib_allocator]
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ pub fn panicking() -> bool {

/// Entry point of panic from the libcore crate.
#[cfg(not(test))]
#[panic_implementation]
#[cfg_attr(stage0, panic_implementation)]
#[cfg_attr(not(stage0), panic_handler)]
#[unwind(allowed)]
pub fn rust_begin_panic(info: &PanicInfo) -> ! {
continue_panic_fmt(&info)
Expand Down
20 changes: 15 additions & 5 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,9 @@ declare_features! (
// Integer match exhaustiveness checking
(active, exhaustive_integer_patterns, "1.30.0", Some(50907), None),

// #[panic_implementation]
// RFC 2070: #[panic_implementation] / #[panic_handler]
(active, panic_implementation, "1.28.0", Some(44489), None),
(active, panic_handler, "1.30.0", Some(44489), None),

// #[doc(keyword = "...")]
(active, doc_keyword, "1.28.0", Some(51315), None),
Expand Down Expand Up @@ -1104,11 +1105,20 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
"infer 'static lifetime requirements",
cfg_fn!(infer_static_outlives_requirements))),

// RFC 2070 (deprecated attribute name)
("panic_implementation",
Normal,
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\
#issuecomment-415140224"),
"panic_implementation",
"This attribute was renamed to `panic_handler`",
cfg_fn!(panic_implementation))),

// RFC 2070
("panic_implementation", Normal, Gated(Stability::Unstable,
"panic_implementation",
"#[panic_implementation] is an unstable feature",
cfg_fn!(panic_implementation))),
("panic_handler", Normal, Gated(Stability::Unstable,
"panic_handler",
"#[panic_handler] is an unstable feature",
cfg_fn!(panic_handler))),

("alloc_error_handler", Normal, Gated(Stability::Unstable,
"alloc_error_handler",
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/auxiliary/some-panic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// no-prefer-dynamic

#![crate_type = "rlib"]
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![no_std]

use core::panic::PanicInfo;

#[panic_implementation]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: `#[panic_implementation]` function required, but not found
// error-pattern: `#[panic_handler]` function required, but not found

#![feature(lang_items)]
#![no_main]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:some-panic-impl.rs

#![feature(panic_implementation)]
#![feature(panic_handler)]
#![feature(lang_items)]
#![no_std]
#![no_main]
Expand All @@ -19,7 +19,7 @@ extern crate some_panic_impl;

use core::panic::PanicInfo;

#[panic_implementation]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
//~^ error duplicate lang item found: `panic_impl`
loop {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/weak-lang-item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// aux-build:weak-lang-items.rs
// error-pattern: `#[panic_implementation]` function required, but not found
// error-pattern: `#[panic_handler]` function required, but not found
// error-pattern: language item required, but not found: `eh_personality`
// ignore-wasm32-bare compiled with panic=abort, personality not required

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-make-fulldeps/issue-51671/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

#![crate_type = "bin"]
#![feature(lang_items)]
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![no_main]
#![no_std]

use core::alloc::Layout;
use core::panic::PanicInfo;

#[panic_implementation]
#[panic_handler]
fn panic(_: &PanicInfo) -> ! {
loop {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// except according to those terms.

#![crate_type = "rlib"]
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![no_std]

use core::panic::PanicInfo;

#[panic_implementation]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
loop {}
}
4 changes: 2 additions & 2 deletions src/test/run-make/wasm-symbols-not-exported/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(panic_implementation, alloc_error_handler)]
#![feature(panic_handler, alloc_error_handler)]
#![crate_type = "cdylib"]
#![no_std]

Expand Down Expand Up @@ -39,7 +39,7 @@ fn a(_: core::alloc::Layout) -> ! {
loop {}
}

#[panic_implementation]
#[panic_handler]
fn b(_: &core::panic::PanicInfo) -> ! {
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// compile-flags:-C panic=abort

#![feature(alloc_error_handler, panic_implementation)]
#![feature(alloc_error_handler, panic_handler)]
#![no_std]
#![no_main]

Expand All @@ -24,5 +24,5 @@ fn oom(
loop {}
}

#[panic_implementation]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// compile-flags:-C panic=abort

#![feature(alloc_error_handler, panic_implementation)]
#![feature(alloc_error_handler, panic_handler)]
#![no_std]
#![no_main]

Expand All @@ -23,5 +23,5 @@ fn oom(
loop {}
}

#[panic_implementation]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// compile-flags:-C panic=abort

#![feature(alloc_error_handler, panic_implementation)]
#![feature(alloc_error_handler, panic_handler)]
#![no_std]
#![no_main]

Expand All @@ -21,5 +21,5 @@ fn oom() -> ! { //~ ERROR function should have one argument
loop {}
}

#[panic_implementation]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }
4 changes: 2 additions & 2 deletions src/test/ui/consts/const-eval/const_panic_libcore_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#![crate_type = "bin"]
#![feature(lang_items)]
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![feature(const_panic)]
#![no_main]
#![no_std]
Expand All @@ -31,7 +31,7 @@ fn eh() {}
#[lang = "eh_unwind_resume"]
fn eh_unwind_resume() {}

#[panic_implementation]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
21 changes: 21 additions & 0 deletions src/test/ui/feature-gates/feature-gate-panic-handler.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags:-C panic=abort

#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_handler] //~ ERROR #[panic_handler] is an unstable feature (see issue #44489)
fn panic(info: &PanicInfo) -> ! {
loop {}
}
11 changes: 11 additions & 0 deletions src/test/ui/feature-gates/feature-gate-panic-handler.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0658]: #[panic_handler] is an unstable feature (see issue #44489)
--> $DIR/feature-gate-panic-handler.rs:18:1
|
LL | #[panic_handler] //~ ERROR #[panic_handler] is an unstable feature (see issue #44489)
| ^^^^^^^^^^^^^^^^
|
= help: add #![feature(panic_handler)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use core::panic::PanicInfo;

#[panic_implementation] //~ ERROR #[panic_implementation] is an unstable feature (see issue #44489)
#[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
fn panic(info: &PanicInfo) -> ! {
loop {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error[E0658]: #[panic_implementation] is an unstable feature (see issue #44489)
error[E0658]: This attribute was renamed to `panic_handler` (see issue #44489)
--> $DIR/feature-gate-panic-implementation.rs:18:1
|
LL | #[panic_implementation] //~ ERROR #[panic_implementation] is an unstable feature (see issue #44489)
LL | #[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(panic_implementation)] to the crate attributes to enable
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/missing/missing-alloc_error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#![no_std]
#![crate_type = "staticlib"]
#![feature(panic_implementation, alloc_error_handler, alloc)]
#![feature(panic_handler, alloc_error_handler, alloc)]

#[panic_implementation]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/missing/missing-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#![no_std]
#![crate_type = "staticlib"]
#![feature(panic_implementation, alloc_error_handler, alloc)]
#![feature(panic_handler, alloc_error_handler, alloc)]

#[panic_implementation]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// no-prefer-dynamic

#![crate_type = "rlib"]
#![feature(panic_implementation)]
#![feature(panic_handler)]
#![no_std]

use core::panic::PanicInfo;

#[panic_implementation]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
loop {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

// compile-flags:-C panic=abort

#![feature(panic_implementation)]
#![feature(panic_handler)]
#![no_std]
#![no_main]

use core::panic::PanicInfo;

#[panic_implementation]
#[panic_handler]
fn panic(
info: PanicInfo, //~ ERROR argument should be `&PanicInfo`
) -> () //~ ERROR return type should be `!`
Expand Down
Loading