Skip to content

Commit a774c81

Browse files
committed
add #[panic_handler]; deprecate #[panic_implementation]
1 parent e5284b0 commit a774c81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+134
-83
lines changed

src/librustc/middle/dead.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt,
293293
}
294294

295295
// (To be) stable attribute for #[lang = "panic_impl"]
296-
if attr::contains_name(attrs, "panic_implementation") {
296+
if attr::contains_name(attrs, "panic_implementation") ||
297+
attr::contains_name(attrs, "panic_handler")
298+
{
297299
return true;
298300
}
299301

src/librustc/middle/lang_items.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
185185
if let Some(value) = attribute.value_str() {
186186
return Some((value, attribute.span));
187187
}
188-
} else if attribute.check_name("panic_implementation") {
188+
} else if attribute.check_name("panic_implementation") ||
189+
attribute.check_name("panic_handler")
190+
{
189191
return Some((Symbol::intern("panic_impl"), attribute.span))
190192
} else if attribute.check_name("alloc_error_handler") {
191193
return Some((Symbol::intern("oom"), attribute.span))

src/librustc/middle/weak_lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
113113
!whitelisted(tcx, lang_items::$item) &&
114114
items.$name().is_none() {
115115
if lang_items::$item == lang_items::PanicImplLangItem {
116-
tcx.sess.err(&format!("`#[panic_implementation]` function required, \
116+
tcx.sess.err(&format!("`#[panic_handler]` function required, \
117117
but not found"));
118118
} else if lang_items::$item == lang_items::OomLangItem {
119119
tcx.sess.err(&format!("`#[alloc_error_handler]` function required, \

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11711171
if !generics.params.is_empty() {
11721172
fcx.tcx.sess.span_err(
11731173
span,
1174-
"`#[panic_implementation]` function should have no type \
1175-
parameters",
1174+
"should have no type parameters",
11761175
);
11771176
}
11781177
}

src/libstd/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@
310310
#![feature(doc_alias)]
311311
#![feature(doc_keyword)]
312312
#![feature(panic_info_message)]
313-
#![feature(panic_implementation)]
313+
#![cfg_attr(stage0, feature(panic_implementation))]
314+
#![cfg_attr(not(stage0), feature(panic_handler))]
314315
#![feature(non_exhaustive)]
315316

316317
#![default_lib_allocator]

src/libstd/panicking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ pub fn panicking() -> bool {
319319

320320
/// Entry point of panic from the libcore crate.
321321
#[cfg(not(test))]
322-
#[panic_implementation]
322+
#[cfg_attr(stage0, panic_implementation)]
323+
#[cfg_attr(not(stage0), panic_handler)]
323324
#[unwind(allowed)]
324325
pub fn rust_begin_panic(info: &PanicInfo) -> ! {
325326
continue_panic_fmt(&info)

src/libsyntax/feature_gate.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ declare_features! (
472472
// Integer match exhaustiveness checking
473473
(active, exhaustive_integer_patterns, "1.30.0", Some(50907), None),
474474

475-
// #[panic_implementation]
475+
// RFC 2070: #[panic_implementation] / #[panic_handler]
476476
(active, panic_implementation, "1.28.0", Some(44489), None),
477+
(active, panic_handler, "1.30.0", Some(44489), None),
477478

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

1108+
// RFC 2070 (deprecated attribute name)
1109+
("panic_implementation",
1110+
Normal, Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489#issuecomment-415140224"),
1111+
"panic_implementation",
1112+
"This attribute was renamed to `panic_handler`",
1113+
cfg_fn!(panic_implementation))),
1114+
11071115
// RFC 2070
1108-
("panic_implementation", Normal, Gated(Stability::Unstable,
1109-
"panic_implementation",
1110-
"#[panic_implementation] is an unstable feature",
1111-
cfg_fn!(panic_implementation))),
1116+
("panic_handler", Normal, Gated(Stability::Unstable,
1117+
"panic_handler",
1118+
"#[panic_handler] is an unstable feature",
1119+
cfg_fn!(panic_handler))),
11121120

11131121
("alloc_error_handler", Normal, Gated(Stability::Unstable,
11141122
"alloc_error_handler",

src/test/compile-fail/auxiliary/some-panic-impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
// no-prefer-dynamic
1212

1313
#![crate_type = "rlib"]
14-
#![feature(panic_implementation)]
14+
#![feature(panic_handler)]
1515
#![no_std]
1616

1717
use core::panic::PanicInfo;
1818

19-
#[panic_implementation]
19+
#[panic_handler]
2020
fn panic(info: &PanicInfo) -> ! {
2121
loop {}
2222
}

src/test/compile-fail/panic-implementation-missing.rs renamed to src/test/compile-fail/panic-handler-missing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

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

1313
#![feature(lang_items)]
1414
#![no_main]

src/test/compile-fail/panic-implementation-twice.rs renamed to src/test/compile-fail/panic-handler-twice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

13-
#![feature(panic_implementation)]
13+
#![feature(panic_handler)]
1414
#![feature(lang_items)]
1515
#![no_std]
1616
#![no_main]
@@ -19,7 +19,7 @@ extern crate some_panic_impl;
1919

2020
use core::panic::PanicInfo;
2121

22-
#[panic_implementation]
22+
#[panic_handler]
2323
fn panic(info: &PanicInfo) -> ! {
2424
//~^ error duplicate lang item found: `panic_impl`
2525
loop {}

0 commit comments

Comments
 (0)