Skip to content

Commit

Permalink
Auto merge of #51366 - japaric:stable-panic-impl, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
stabilize #[panic_handler]

closes #44489

### Update(2018-09-07)

This was proposed for stabilization in #44489 (comment) and its FCP with disposition to merge / accept is nearly over. The summary of what's being stabilized can be found in #44489 (comment)

Documentation PRs:

- Reference. rust-lang/reference#362
- Nomicon. rust-lang/nomicon#75

---

`#[panic_implementation]` was implemented recently in #50338. `#[panic_implementation]` is basically the old `panic_fmt` language item but in a less error prone (\*) shape. There are still some issues and questions to sort out around this feature (cf. #44489) but this PR is meant to start a discussion about those issues / questions with the language team.

(\*) `panic_fmt` was not type checked; changes in its function signature caused serious, silent binary size regressions like the one observed in #43054

Some unresolved questions from #44489:

> Should the Display of PanicInfo format the panic information as "panicked at 'reason',
> src/main.rs:27:4", as "'reason', src/main.rs:27:4", or simply as "reason".

The current implementation formats `PanicInfo` as the first alternative, which is how panic messages are formatted by the `std` panic handler. The `Display` implementation is more than a convenience: `PanicInfo.message` is unstable so it's not possible to replicate the `Display` implementation on stable.

> Is this design compatible, or can it be extended to work, with unwinding implementations for
> no-std environments?

I believe @whitequark made more progress with unwinding in no-std since their last comment in #44489. Perhaps they can give us an update?

---

Another unresolved question is where this feature should be documented. The feature currently doesn't have any documentation.

cc @rust-lang/lang
cc @jackpot51 @alevy @phil-opp
  • Loading branch information
bors committed Sep 8, 2018
2 parents 06da917 + 358fc5b commit ff59ab1
Show file tree
Hide file tree
Showing 25 changed files with 17 additions and 67 deletions.
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@
#![feature(doc_keyword)]
#![feature(panic_info_message)]
#![cfg_attr(stage0, feature(panic_implementation))]
#![cfg_attr(not(stage0), feature(panic_handler))]
#![feature(non_exhaustive)]

#![default_lib_allocator]
Expand Down
7 changes: 2 additions & 5 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ declare_features! (

// 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 @@ -674,6 +673,7 @@ declare_features! (
(accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None),
// Allows all literals in attribute lists and values of key-value pairs.
(accepted, attr_literals, "1.30.0", Some(34981), None),
(accepted, panic_handler, "1.30.0", Some(44489), None),
);

// If you change this, please modify src/doc/unstable-book as well. You must
Expand Down Expand Up @@ -1143,10 +1143,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
cfg_fn!(panic_implementation))),

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

("alloc_error_handler", Normal, Gated(Stability::Unstable,
"alloc_error_handler",
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/auxiliary/some-panic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// no-prefer-dynamic

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

use core::panic::PanicInfo;
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/panic-handler-twice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

#![feature(panic_handler)]
#![feature(lang_items)]
#![no_std]
#![no_main]
Expand Down
1 change: 0 additions & 1 deletion src/test/run-make-fulldeps/issue-51671/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

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

use core::panic::PanicInfo;
Expand Down
1 change: 0 additions & 1 deletion 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,6 @@

#![crate_type = "bin"]
#![feature(lang_items)]
#![feature(panic_handler)]
#![feature(const_panic)]
#![no_main]
#![no_std]
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/consts/const-eval/const_panic_libcore_main.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: this constant cannot be used
--> $DIR/const_panic_libcore_main.rs:20:1
--> $DIR/const_panic_libcore_main.rs:19:1
|
LL | const Z: () = panic!("cheese");
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:20:15
| the evaluated program panicked at 'cheese', $DIR/const_panic_libcore_main.rs:19:15
|
= note: #[deny(const_err)] on by default
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: this constant cannot be used
--> $DIR/const_panic_libcore_main.rs:23:1
--> $DIR/const_panic_libcore_main.rs:22:1
|
LL | const Y: () = unreachable!();
| ^^^^^^^^^^^^^^--------------^
| |
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:23:15
| the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_main.rs:22:15
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: this constant cannot be used
--> $DIR/const_panic_libcore_main.rs:26:1
--> $DIR/const_panic_libcore_main.rs:25:1
|
LL | const X: () = unimplemented!();
| ^^^^^^^^^^^^^^----------------^
| |
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore_main.rs:26:15
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore_main.rs:25:15
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Expand Down
21 changes: 0 additions & 21 deletions src/test/ui/feature-gates/feature-gate-panic-handler.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/feature-gates/feature-gate-panic-handler.stderr

This file was deleted.

1 change: 0 additions & 1 deletion src/test/ui/panic-handler/auxiliary/some-panic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// no-prefer-dynamic

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

use core::panic::PanicInfo;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic-handler/panic-handler-bad-signature-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// compile-flags:-C panic=abort

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: return type should be `!`
--> $DIR/panic-handler-bad-signature-1.rs:22:6
--> $DIR/panic-handler-bad-signature-1.rs:21:6
|
LL | ) -> () //~ ERROR return type should be `!`
| ^^

error: argument should be `&PanicInfo`
--> $DIR/panic-handler-bad-signature-1.rs:21:11
--> $DIR/panic-handler-bad-signature-1.rs:20:11
|
LL | info: PanicInfo, //~ ERROR argument should be `&PanicInfo`
| ^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic-handler/panic-handler-bad-signature-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// compile-flags:-C panic=abort

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: argument should be `&PanicInfo`
--> $DIR/panic-handler-bad-signature-2.rs:21:11
--> $DIR/panic-handler-bad-signature-2.rs:20:11
|
LL | info: &'static PanicInfo, //~ ERROR argument should be `&PanicInfo`
| ^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic-handler/panic-handler-bad-signature-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// compile-flags:-C panic=abort

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: function should have one argument
--> $DIR/panic-handler-bad-signature-3.rs:20:1
--> $DIR/panic-handler-bad-signature-3.rs:19:1
|
LL | fn panic() -> ! { //~ ERROR function should have one argument
| ^^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic-handler/panic-handler-bad-signature-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// compile-flags:-C panic=abort

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: should have no type parameters
--> $DIR/panic-handler-bad-signature-4.rs:20:1
--> $DIR/panic-handler-bad-signature-4.rs:19:1
|
LL | / fn panic<T>(pi: &PanicInfo) -> ! {
LL | | //~^ ERROR should have no type parameters
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic-handler/panic-handler-duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// compile-flags:-C panic=abort

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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/panic-handler/panic-handler-duplicate.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0152]: duplicate lang item found: `panic_impl`.
--> $DIR/panic-handler-duplicate.rs:26:1
--> $DIR/panic-handler-duplicate.rs:25:1
|
LL | / fn panic2(info: &PanicInfo) -> ! { //~ ERROR duplicate lang item found: `panic_impl`.
LL | | loop {}
LL | | }
| |_^
|
note: first defined here.
--> $DIR/panic-handler-duplicate.rs:21:1
--> $DIR/panic-handler-duplicate.rs:20:1
|
LL | / fn panic(info: &PanicInfo) -> ! {
LL | | loop {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#![feature(lang_items)]
#![feature(no_core)]
#![feature(panic_handler)]
#![no_core]
#![no_main]

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic-handler/panic-handler-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// error-pattern: duplicate lang item found: `panic_impl`.

#![feature(panic_handler)]

use std::panic::PanicInfo;

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/panic-handler/panic-handler-std.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0152]: duplicate lang item found: `panic_impl`.
--> $DIR/panic-handler-std.rs:18:1
--> $DIR/panic-handler-std.rs:17:1
|
LL | / fn panic(info: PanicInfo) -> ! {
LL | | loop {}
Expand All @@ -9,7 +9,7 @@ LL | | }
= note: first defined in crate `std`.

error: argument should be `&PanicInfo`
--> $DIR/panic-handler-std.rs:18:16
--> $DIR/panic-handler-std.rs:17:16
|
LL | fn panic(info: PanicInfo) -> ! {
| ^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/panic_implementation-closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

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

#[panic_handler]
pub fn panic_fmt(_: &::core::panic::PanicInfo) -> ! {
Expand Down

0 comments on commit ff59ab1

Please sign in to comment.