Skip to content

Commit 6916385

Browse files
committed
Auto merge of #53619 - japaric:panic-handler, r=SimonSapin
add #[panic_handler]; deprecate #[panic_implementation] r? @SimonSapin cc #44489
2 parents 36f14b9 + 40a38b0 commit 6916385

Some content is hidden

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

44 files changed

+164
-79
lines changed

src/doc/unstable-book/src/language-features/used.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ This condition can be met using `#[used]` and `#[link_section]` plus a linker
8787
script.
8888

8989
``` rust,ignore
90-
#![feature(panic_implementation)]
90+
#![feature(panic_handler)]
9191
#![feature(used)]
9292
#![no_main]
9393
#![no_std]
@@ -102,8 +102,8 @@ extern "C" fn reset_handler() -> ! {
102102
#[used]
103103
static RESET_HANDLER: extern "C" fn() -> ! = reset_handler;
104104
105-
#[panic_implementation]
106-
fn panic_impl(info: &PanicInfo) -> ! {
105+
#[panic_handler]
106+
fn panic(info: &PanicInfo) -> ! {
107107
loop {}
108108
}
109109
```

src/librustc/middle/dead.rs

+3-1
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

+3-1
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

+1-1
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

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

src/libstd/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@
309309
#![feature(doc_alias)]
310310
#![feature(doc_keyword)]
311311
#![feature(panic_info_message)]
312-
#![feature(panic_implementation)]
312+
#![cfg_attr(stage0, feature(panic_implementation))]
313+
#![cfg_attr(not(stage0), feature(panic_handler))]
313314
#![feature(non_exhaustive)]
314315

315316
#![default_lib_allocator]

src/libstd/panicking.rs

+2-1
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

+15-5
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,9 @@ declare_features! (
469469
// Integer match exhaustiveness checking
470470
(active, exhaustive_integer_patterns, "1.30.0", Some(50907), None),
471471

472-
// #[panic_implementation]
472+
// RFC 2070: #[panic_implementation] / #[panic_handler]
473473
(active, panic_implementation, "1.28.0", Some(44489), None),
474+
(active, panic_handler, "1.30.0", Some(44489), None),
474475

475476
// #[doc(keyword = "...")]
476477
(active, doc_keyword, "1.28.0", Some(51315), None),
@@ -1109,11 +1110,20 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
11091110
"infer 'static lifetime requirements",
11101111
cfg_fn!(infer_static_outlives_requirements))),
11111112

1113+
// RFC 2070 (deprecated attribute name)
1114+
("panic_implementation",
1115+
Normal,
1116+
Gated(Stability::Deprecated("https://github.com/rust-lang/rust/issues/44489\
1117+
#issuecomment-415140224"),
1118+
"panic_implementation",
1119+
"This attribute was renamed to `panic_handler`",
1120+
cfg_fn!(panic_implementation))),
1121+
11121122
// RFC 2070
1113-
("panic_implementation", Normal, Gated(Stability::Unstable,
1114-
"panic_implementation",
1115-
"#[panic_implementation] is an unstable feature",
1116-
cfg_fn!(panic_implementation))),
1123+
("panic_handler", Normal, Gated(Stability::Unstable,
1124+
"panic_handler",
1125+
"#[panic_handler] is an unstable feature",
1126+
cfg_fn!(panic_handler))),
11171127

11181128
("alloc_error_handler", Normal, Gated(Stability::Unstable,
11191129
"alloc_error_handler",

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

+2-2
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

+1-1
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

+2-2
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 {}

src/test/compile-fail/weak-lang-item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

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

src/test/run-make-fulldeps/issue-51671/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
#![crate_type = "bin"]
1212
#![feature(lang_items)]
13-
#![feature(panic_implementation)]
13+
#![feature(panic_handler)]
1414
#![no_main]
1515
#![no_std]
1616

1717
use core::alloc::Layout;
1818
use core::panic::PanicInfo;
1919

20-
#[panic_implementation]
20+
#[panic_handler]
2121
fn panic(_: &PanicInfo) -> ! {
2222
loop {}
2323
}

src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-provider.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// except according to those terms.
1010

1111
#![crate_type = "rlib"]
12-
#![feature(panic_implementation)]
12+
#![feature(panic_handler)]
1313
#![no_std]
1414

1515
use core::panic::PanicInfo;
1616

17-
#[panic_implementation]
17+
#[panic_handler]
1818
fn panic(info: &PanicInfo) -> ! {
1919
loop {}
2020
}

src/test/run-make/wasm-symbols-not-exported/bar.rs

+2-2
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-
#![feature(panic_implementation, alloc_error_handler)]
11+
#![feature(panic_handler, alloc_error_handler)]
1212
#![crate_type = "cdylib"]
1313
#![no_std]
1414

@@ -39,7 +39,7 @@ fn a(_: core::alloc::Layout) -> ! {
3939
loop {}
4040
}
4141

42-
#[panic_implementation]
42+
#[panic_handler]
4343
fn b(_: &core::panic::PanicInfo) -> ! {
4444
loop {}
4545
}

src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// compile-flags:-C panic=abort
1212

13-
#![feature(alloc_error_handler, panic_implementation)]
13+
#![feature(alloc_error_handler, panic_handler)]
1414
#![no_std]
1515
#![no_main]
1616

@@ -24,5 +24,5 @@ fn oom(
2424
loop {}
2525
}
2626

27-
#[panic_implementation]
27+
#[panic_handler]
2828
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }

src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// compile-flags:-C panic=abort
1212

13-
#![feature(alloc_error_handler, panic_implementation)]
13+
#![feature(alloc_error_handler, panic_handler)]
1414
#![no_std]
1515
#![no_main]
1616

@@ -23,5 +23,5 @@ fn oom(
2323
loop {}
2424
}
2525

26-
#[panic_implementation]
26+
#[panic_handler]
2727
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }

src/test/ui/alloc-error/alloc-error-handler-bad-signature-3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// compile-flags:-C panic=abort
1212

13-
#![feature(alloc_error_handler, panic_implementation)]
13+
#![feature(alloc_error_handler, panic_handler)]
1414
#![no_std]
1515
#![no_main]
1616

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

24-
#[panic_implementation]
24+
#[panic_handler]
2525
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }

src/test/ui/consts/const-eval/const_panic_libcore_main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![crate_type = "bin"]
1212
#![feature(lang_items)]
13-
#![feature(panic_implementation)]
13+
#![feature(panic_handler)]
1414
#![feature(const_panic)]
1515
#![no_main]
1616
#![no_std]
@@ -31,7 +31,7 @@ fn eh() {}
3131
#[lang = "eh_unwind_resume"]
3232
fn eh_unwind_resume() {}
3333

34-
#[panic_implementation]
34+
#[panic_handler]
3535
fn panic(_info: &PanicInfo) -> ! {
3636
loop {}
3737
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-C panic=abort
12+
13+
#![no_std]
14+
#![no_main]
15+
16+
use core::panic::PanicInfo;
17+
18+
#[panic_handler] //~ ERROR #[panic_handler] is an unstable feature (see issue #44489)
19+
fn panic(info: &PanicInfo) -> ! {
20+
loop {}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: #[panic_handler] is an unstable feature (see issue #44489)
2+
--> $DIR/feature-gate-panic-handler.rs:18:1
3+
|
4+
LL | #[panic_handler] //~ ERROR #[panic_handler] is an unstable feature (see issue #44489)
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: add #![feature(panic_handler)] to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/feature-gates/feature-gate-panic-implementation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use core::panic::PanicInfo;
1717

18-
#[panic_implementation] //~ ERROR #[panic_implementation] is an unstable feature (see issue #44489)
18+
#[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
1919
fn panic(info: &PanicInfo) -> ! {
2020
loop {}
2121
}

src/test/ui/feature-gates/feature-gate-panic-implementation.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0658]: #[panic_implementation] is an unstable feature (see issue #44489)
1+
error[E0658]: This attribute was renamed to `panic_handler` (see issue #44489)
22
--> $DIR/feature-gate-panic-implementation.rs:18:1
33
|
4-
LL | #[panic_implementation] //~ ERROR #[panic_implementation] is an unstable feature (see issue #44489)
4+
LL | #[panic_implementation] //~ ERROR This attribute was renamed to `panic_handler` (see issue #44489)
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(panic_implementation)] to the crate attributes to enable

src/test/ui/missing/missing-alloc_error_handler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
#![no_std]
1515
#![crate_type = "staticlib"]
16-
#![feature(panic_implementation, alloc_error_handler, alloc)]
16+
#![feature(panic_handler, alloc_error_handler, alloc)]
1717

18-
#[panic_implementation]
18+
#[panic_handler]
1919
fn panic(_: &core::panic::PanicInfo) -> ! {
2020
loop {}
2121
}

src/test/ui/missing/missing-allocator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
#![no_std]
1515
#![crate_type = "staticlib"]
16-
#![feature(panic_implementation, alloc_error_handler, alloc)]
16+
#![feature(panic_handler, alloc_error_handler, alloc)]
1717

18-
#[panic_implementation]
18+
#[panic_handler]
1919
fn panic(_: &core::panic::PanicInfo) -> ! {
2020
loop {}
2121
}

src/test/ui/panic-implementation/auxiliary/some-panic-impl.rs renamed to src/test/ui/panic-handler/auxiliary/some-panic-impl.rs

+2-2
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/ui/panic-implementation/panic-implementation-bad-signature-1.rs renamed to src/test/ui/panic-handler/panic-handler-bad-signature-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
// compile-flags:-C panic=abort
1212

13-
#![feature(panic_implementation)]
13+
#![feature(panic_handler)]
1414
#![no_std]
1515
#![no_main]
1616

1717
use core::panic::PanicInfo;
1818

19-
#[panic_implementation]
19+
#[panic_handler]
2020
fn panic(
2121
info: PanicInfo, //~ ERROR argument should be `&PanicInfo`
2222
) -> () //~ ERROR return type should be `!`

0 commit comments

Comments
 (0)