Skip to content
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

implement #[panic_implementation] #50338

Merged
merged 12 commits into from
Jun 3, 2018
Merged

implement #[panic_implementation] #50338

merged 12 commits into from
Jun 3, 2018

Conversation

japaric
Copy link
Member

@japaric japaric commented Apr 30, 2018

This implements the #[panic_implementation] attribute as instructed in #44489 (comment)

I haven't run the full test suite yet but at least all the compile-fail tests pass.

r? @nagisa

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 30, 2018

#[cfg(not(stage0))]
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
extern "C" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extern "Rust"? Would that solve the improper_ctypes warning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint seems to apply regardless of the ABI ("C" or "Rust").

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should indicate why it is fine to pass such an object anyway (it never actually passes a FFI boundary and is a Rust-to-Rust call)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:47:12] .................................i..................................................................
[00:47:24] ..................................................................i.................................
[00:47:37] .....................................................i..............................................
[00:47:54] ....................................................................................................
[00:48:12] ........................................................F...........................................
[00:48:50] ...............i....................................................................................
[00:49:18] .............i......................................................................................
[00:49:25] ..............test [run-pass] run-pass/mir_heavy_promoted.rs has been running for over 60 seconds
[00:49:49] ......................................................................................
---
[00:52:55] failures:
[00:52:55] 
[00:52:55] ---- [run-pass] run-pass/macro-comma-behavior.rs stdout ----
[00:52:55]  
[00:52:55] error in revision `core`: test run failed!
[00:52:55] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/macro-comma-behavior.stage2-x86_64-unknown-linux-gnu"
[00:52:55] stdout:
[00:52:55] ------------------------------------------
[00:52:55] 
[00:52:55] 
[00:52:55] running 3 tests
[00:52:55] test debug_assert_1arg ... FAILED
[00:52:55] test to_format_or_not_to_format ... ok
[00:52:55] test assert_1arg ... FAILED
[00:52:55] failures:
[00:52:55] failures:
[00:52:55n-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-3.9/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "3.9.1\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:52:55] 
[00:52:55] 
[00:52:55] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[00:52:55] Build completed unsuccessfully in 0:13:18
[00:52:55] Build completed unsuccessfully in 0:13:18
[00:52:55] Makefile:58: recipe for target 'check' failed
[00:52:55] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental
111308 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu
111308 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu
111304 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release
107420 ./obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/deps
102820 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends
102808 ./obj/build/bootstrap/debug/incremental/bootstrap-2wettvttcntnm
102804 ./obj/build/bootstrap/debug/incremental/bootstrap-2wettvttcntnm/s-f0lgpm65kh-1jc4cti-v7hez0f2m5v0
90744 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
90744 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz
90740 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental/core-31lccp6wy7orz/s-f0lgn98ibl-4n1z2x-q6snowoabdxz
89896 ./obj/build/x86_64-unknown-linux-gnu/stage1/lib
89684 ./src/llvm/test/CodeGen
86672 ./obj/build/x86_64-unknown-linux-gnu/doc/core
84688 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The travis failure has to be fixed as well. The failure seems pretty weird for the changes in this PR.


#[cfg(not(stage0))]
#[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
extern "C" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should indicate why it is fine to pass such an object anyway (it never actually passes a FFI boundary and is a Rust-to-Rust call)

@nagisa
Copy link
Member

nagisa commented Apr 30, 2018

The changes look good otherwise.

#[cfg(not(stage0))]
#[cold] #[inline(never)]
pub fn panic_fmt(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
struct NoPayload;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this "null" payload used?

@japaric
Copy link
Member Author

japaric commented May 1, 2018

The travis failure has to be fixed as well.

I fixed those.


I seem to have broken a bit the panicking (/ unwinding?) stuff; I'm seeing some proc-macro related tests fail. I won't have time to dig further any time soon but here's the list of failing tests if someone wants to investigate:

  • ui-fulldeps/proc-macro/load-panic.rs -- there's some extra test in the stderr output:
    "thread .. panicked .."

  • run-pass-fulldeps/compiler-calls.rs -- "cannot access a scoped thread local variable without
    calling set first', /home/japaric/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/scoped-tls-0.1.1/src/lib.rs:186:9"

  • run-pass-fulldeps/proc-macro/modify-ast.rs -- "proc_macro::__internal::with_sess() called before
    set_parse_sess()!"

  • run-pass-fulldeps/proc-macro/span-api-tests.rs -- "proc_macro::__internal::with_sess() called
    before set_parse_sess()!"


#[cfg(not(stage0))]
#[cold] #[inline(never)]
pub fn panic_payload<M>(msg: M, file_line_col: &(&'static str, u32, u32)) -> !
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget, but is this something we want to enable for libcore? I thought that we didn't have a path to actually supporting this yet?

(support in the sense of transmitting the value all the way to the caught value of thread::spawn)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget, but is this something we want to enable for libcore?

Well, this (adding payload support to core::panic!) is in the accepted RFC. Though we don't have to add it right now; we can stabilize #[panic_implementation] w/o payload support and add payload support later on in a backwards compatible fashion (or at least I think it's possible).

@@ -1148,6 +1148,48 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
}
}

// Check that a function marked as `#[panic_implementation]` has signature `fn(&PanicInfo) -> !`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally more of a fan of generating AST nodes which correspond to the structure we want which avoids reaching into the internals of the typechecker where possible. For example I don't think this disallows something like this:

#[panic_implementation]
fn foo<T>(a: &PanicInfo) -> ! {
}

right?

I was thinking that we'd basically expand #[panic_implementation] to #[lang = "panic_impl"] where the lang item internally dispatches to #[panic_implementation] (automatically typechecking it along the way). That may be slightly more difficult to architect, though, but I'm curious what you think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language items are not type-checked at all at the moment, so there is nothing to hand the type-checking over to.

panic_fmt has no benefits over the new language item and IIRC (from when I wrote the instructions) complicates the implementation of this feature unnecessarily.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right yeah, my point is that we generate a language item which internally dispatches to the function annotated #[panic_implementation], which by construction will typecheck the panic implementation and not require typechekcing of lang ites.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton you mean something like this?

// this
// (signature is totally wrong)
#[panic_implementation]
fn foo<T>(pi: &i32) {
    // body
}

// expands into
#[lang = "panic_impl"]
fn __secret_name_maybe(pi: &PanicInfo) -> ! {
    // user input
    fn foo<T>(pi: &i32) {
        // body
    }

    let f: fn(&PanicInfo) -> ! = foo;
    f()
}

That would work typechecking wise, but will it report error messages with meaningful spans? (My experience with proc macros says that most errors will wrongly report the whole #[panic_implementation] item as their span)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this disallows something like this:
fn foo(a: &PanicInfo) -> ! {

I can add a check and test to reject that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@japaric yeah that latter idea is what I was thinking, where basically the compiler manufactures the actual lang item which is hooked up to call the #[panic_implementation]. That way the compiler has full control over ABI and whatnot

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly in many cases this approach results in kind-of suboptimal errors.

For example

fn foo() {
    fn bar<T>(i: i32) -> ! { loop {} }
    let foo: fn(i32) -> ! = bar;
}

gives

error[E0282]: type annotations needed
 --> src/main.rs:3:29
  |
3 |     let foo: fn(i32) -> ! = bar;
  |                             ^^^ cannot infer type for `T`

but if expanded within a macro it would be something like this instead:

error[E0282]: type annotations needed
 --> src/main.rs:3:29
  |
3 |     #[panic_implementation]
  |     fn panic<T>(...) -> ! { loop {} }
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `T`

which is just… incomprehensible.

That being said, I have a long time wish to eventually implement universal checking of the language item signatures (similar to one we do for intrinsics), which would resolve this issue universally. Thus, I’d recommend going for the simplest complete approach possible for now.

@@ -180,7 +180,7 @@ fn default_hook(info: &PanicInfo) {

let location = info.location().unwrap(); // The current implementation always returns Some

let msg = match info.payload().downcast_ref::<&'static str>() {
let msg = match info.payload().downcast_ref::<&str>() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this was necessary? I thought Any-style things could only be with 'static types?

@bors
Copy link
Contributor

bors commented May 1, 2018

☔ The latest upstream changes (presumably #49789) made this pull request unmergeable. Please resolve the merge conflicts.

@shepmaster shepmaster added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 6, 2018
@shepmaster
Copy link
Member

Ping from triage, @japaric ! You've got merge conflicts and some review comments pending.

@pietroalbini
Copy link
Member

Ping from triage @japaric! Will you have time to work on this soon?

@japaric japaric force-pushed the panic-impl branch 2 times, most recently from 6cbc8af to 5830bc2 Compare May 16, 2018 18:49
@japaric
Copy link
Member Author

japaric commented May 16, 2018

I have reverted the payload in core::panic! stuff hoping that it makes this PR less controversial. See also #50338 (comment).

This has been rebased and passes the test suite when using stage 2. Turns out all the weird errors around proc-macros that I was seeing only occur when testing stage 1 (x.py test --stage 1) so I actually didn't break unwinding.

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned nagisa May 16, 2018
@alexcrichton
Copy link
Member

Could some tests also be added for situations like:

  • Linking a #[panic_implementation] with libstd should be an error
  • Linking two #[panic_implementation] crates together should be an error
  • A transitive crate can come in and provide #[panic_implementation]

@bors
Copy link
Contributor

bors commented May 17, 2018

☔ The latest upstream changes (presumably #50629) made this pull request unmergeable. Please resolve the merge conflicts.

@pietroalbini
Copy link
Member

Ping from triage @japaric! The reviewer provided some feedback, do you have time to address it?

@japaric
Copy link
Member Author

japaric commented May 29, 2018

@alexcrichton requested tests have been added. r?

@rust-highfive

This comment has been minimized.

@pietroalbini pietroalbini added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 29, 2018
@rust-highfive
Copy link
Collaborator

The job wasm32-unknown of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:55:10] status: exit code: 2
[00:55:10] command: "make"
[00:55:10] stdout:
[00:55:10] ------------------------------------------
[00:55:10] LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/panic-impl-transitive/panic-impl-transitive:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib:" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/panic-impl-transitive/panic-impl-transitive -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/panic-impl-transitive/panic-impl-transitive  panic-impl-provider.rs
[00:55:10] Makefile:6: recipe for target 'all' failed
[00:55:10] ------------------------------------------
[00:55:10] stderr:
[00:55:10] ------------------------------------------
[00:55:10] error[E0463]: can't find crate for `core`
[00:55:10] error[E0463]: can't find crate for `core`
[00:55:10] 
[00:55:10] error: aborting due to previous error
[00:55:10] 
[00:55:10] For more information about this error, try `rustc --explain E0463`.
[00:55:10] make: *** [all] Error 101
[00:55:10] ------------------------------------------
[00:55:10] 
[00:55:10] 
[00:55:10] thread '[run-make] run-make/panic-impl-transitive' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3096:9
[00:55:10] 
[00:55:10] 
[00:55:10] failures:
[00:55:10]     [run-make] run-make/panic-impl-transitive
[00:55:10]     [run-make] run-make/panic-impl-transitive
[00:55:10] 
[00:55:10] test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
[00:55:10] 
[00:55:10] thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:498:22
[00:55:10] 
[00:55:10] 
[00:55:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/wasm32-unknown-unknown/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-make" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make" "--stage-id" "stage2-wasm32-unknown-unknown" "--mode" "run-make" "--target" "wasm32-unknown-unknown" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--nodejs" "/node-v9.2.0-linux-x64/bin/node" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/wasm32-unknown-unknown/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--llvm-version" "6.0.1\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[00:55:10] 
[00:55:10] 
[00:55:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --target wasm32-unknown-unknown src/test/run-make src/test/ui src/test/run-pass src/test/compile-fail src/test/parse-fail src/test/mir-opt src/test/codegen-units src/libcore
[00:55:10] Build completed unsuccessfully in 0:52:19

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2018
@japaric
Copy link
Member Author

japaric commented Jun 3, 2018

@bors r=alexcrichton

@bors
Copy link
Contributor

bors commented Jun 3, 2018

📌 Commit 8ad15de has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 3, 2018
@bors
Copy link
Contributor

bors commented Jun 3, 2018

⌛ Testing commit 8ad15de with merge 29f48cc...

bors added a commit that referenced this pull request Jun 3, 2018
implement #[panic_implementation]

This implements the `#[panic_implementation]` attribute as instructed in #44489 (comment)

I haven't run the full test suite yet but at least all the compile-fail tests pass.

r? @nagisa
@bors
Copy link
Contributor

bors commented Jun 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 29f48cc to master...

@bors bors merged commit 8ad15de into rust-lang:master Jun 3, 2018
sdemos added a commit to sdemos/uefi-rs that referenced this pull request Jun 4, 2018
sdemos added a commit to sdemos/uefi-rs that referenced this pull request Jun 4, 2018
sdemos added a commit to sdemos/uefi-rs that referenced this pull request Jun 4, 2018
@japaric japaric deleted the panic-impl branch June 21, 2018 00:10
kennytm added a commit to kennytm/rust that referenced this pull request Sep 7, 2018
…imulacrum

stabilize #[panic_handler]

closes rust-lang#44489

### Update(2018-09-07)

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

Documentation PRs:

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

---

`#[panic_implementation]` was implemented recently in rust-lang#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. rust-lang#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 rust-lang#43054

Some unresolved questions from rust-lang#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 rust-lang#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
kennytm added a commit to kennytm/rust that referenced this pull request Sep 8, 2018
…imulacrum

stabilize #[panic_handler]

closes rust-lang#44489

### Update(2018-09-07)

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

Documentation PRs:

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

---

`#[panic_implementation]` was implemented recently in rust-lang#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. rust-lang#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 rust-lang#43054

Some unresolved questions from rust-lang#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 rust-lang#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
bors added a commit that referenced this pull request Sep 8, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.