rust/library
Jonas Schievink e3808edeee
Rollup merge of #78119 - fusion-engineering-forks:panic-use-as-str, r=Amanieu
Throw core::panic!("message") as &str instead of String.

This makes `core::panic!("message")` consistent with `std::panic!("message")`, which throws a `&str` and not a `String`.

This also makes any other panics from `core::panicking::panic` result in a `&str` rather than a `String`, which includes compiler-generated panics such as the panics generated for `mem::zeroed()`.

---

Demonstration:

```rust
use std::panic;
use std::any::Any;

fn main() {
    panic::set_hook(Box::new(|panic_info| check(panic_info.payload())));

    check(&*panic::catch_unwind(|| core::panic!("core")).unwrap_err());
    check(&*panic::catch_unwind(|| std::panic!("std")).unwrap_err());
}

fn check(msg: &(dyn Any + Send)) {
    if let Some(s) = msg.downcast_ref::<String>() {
        println!("Got a String: {:?}", s);
    } else if let Some(s) = msg.downcast_ref::<&str>() {
        println!("Got a &str: {:?}", s);
    }
}
```

Before:
```
Got a String: "core"
Got a String: "core"
Got a &str: "std"
Got a &str: "std"
```

After:
```
Got a &str: "core"
Got a &str: "core"
Got a &str: "std"
Got a &str: "std"
```
2020-10-24 22:39:53 +02:00
..
alloc Rollup merge of #77610 - hermitcore:dtors, r=m-ou-se 2020-10-24 22:39:44 +02:00
backtrace@a6dd47bd58 Bump backtrace-rs 2020-10-15 15:21:12 -04:00
core Rollup merge of #78069 - fusion-engineering-forks:core-const-panic-str, r=RalfJung 2020-10-24 22:39:49 +02:00
panic_abort Rollup merge of #76866 - est31:master, r=lcnr 2020-09-20 15:51:50 +02:00
panic_unwind library/{panic_,}unwind: Add definitions for sparc-unknow-linux-gnu 2020-09-28 00:39:57 +02:00
proc_macro Bump to 1.48 bootstrap compiler 2020-10-07 19:51:36 -04:00
profiler_builtins Fix warning whe building profiler_builtins crate 2020-09-04 15:10:29 +02:00
rtstartup mv std libs to library/ 2020-07-27 19:51:13 -05:00
rustc-std-workspace-alloc mv std libs to library/ 2020-07-27 19:51:13 -05:00
rustc-std-workspace-core mv std libs to library/ 2020-07-27 19:51:13 -05:00
rustc-std-workspace-std mv std libs to library/ 2020-07-27 19:51:13 -05:00
std Rollup merge of #78119 - fusion-engineering-forks:panic-use-as-str, r=Amanieu 2020-10-24 22:39:53 +02:00
stdarch@3c3664355e Update stdarch submodule 2020-10-01 13:06:22 -04:00
term mv std libs to library/ 2020-07-27 19:51:13 -05:00
test Rollup merge of #77890 - gilescope:welformed-json-output-from-libtest, r=KodrAus 2020-10-23 18:26:20 +09:00
unwind Remove useless all in cfg 2020-10-09 13:24:05 +02:00