File tree Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Expand file tree Collapse file tree 5 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,14 @@ pub macro panic_2015 {
27
27
( $msg: literal $( , ) ?) => (
28
28
$crate:: panicking:: panic ( $msg)
29
29
) ,
30
+ // Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
30
31
( $msg: expr $( , ) ?) => (
31
32
$crate:: panicking:: panic_str ( $msg)
32
33
) ,
34
+ // Special-case the single-argument case for const_panic.
35
+ ( "{}" , $arg: expr $( , ) ?) => (
36
+ $crate:: panicking:: panic_display ( & $arg)
37
+ ) ,
33
38
( $fmt: expr, $( $arg: tt) +) => (
34
39
$crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $fmt, $( $arg) +) )
35
40
) ,
@@ -44,6 +49,10 @@ pub macro panic_2021 {
44
49
( ) => (
45
50
$crate:: panicking:: panic ( "explicit panic" )
46
51
) ,
52
+ // Special-case the single-argument case for const_panic.
53
+ ( "{}" , $arg: expr $( , ) ?) => (
54
+ $crate:: panicking:: panic_display ( & $arg)
55
+ ) ,
47
56
( $( $t: tt) +) => (
48
57
$crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $( $t) +) )
49
58
) ,
Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ pub fn panic_str(expr: &str) -> ! {
60
60
panic_fmt ( format_args ! ( "{}" , expr) ) ;
61
61
}
62
62
63
+ #[ inline]
64
+ #[ track_caller]
65
+ #[ cfg_attr( not( bootstrap) , lang = "panic_display" ) ] // needed for const-evaluated panics
66
+ pub fn panic_display < T : fmt:: Display > ( x : & T ) -> ! {
67
+ panic_fmt ( format_args ! ( "{}" , * x) ) ;
68
+ }
69
+
63
70
#[ cold]
64
71
#[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) ) ]
65
72
#[ track_caller]
Original file line number Diff line number Diff line change 258
258
#![ feature( const_trait_impl) ]
259
259
#![ feature( container_error_extra) ]
260
260
#![ feature( core_intrinsics) ]
261
+ #![ feature( core_panic) ]
261
262
#![ feature( custom_test_frameworks) ]
262
263
#![ feature( decl_macro) ]
263
264
#![ feature( doc_cfg) ]
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ use crate::thread::Result;
10
10
11
11
#[ doc( hidden) ]
12
12
#[ unstable( feature = "edition_panic" , issue = "none" , reason = "use panic!() instead" ) ]
13
- #[ allow_internal_unstable( libstd_sys_internals, const_format_args) ]
13
+ #[ allow_internal_unstable( libstd_sys_internals, const_format_args, core_panic ) ]
14
14
#[ cfg_attr( not( test) , rustc_diagnostic_item = "std_panic_2015_macro" ) ]
15
15
#[ rustc_macro_transparency = "semitransparent" ]
16
16
pub macro panic_2015 {
@@ -20,6 +20,10 @@ pub macro panic_2015 {
20
20
( $msg: expr $( , ) ?) => ( {
21
21
$crate:: rt:: begin_panic ( $msg)
22
22
} ) ,
23
+ // Special-case the single-argument case for const_panic.
24
+ ( "{}" , $arg: expr $( , ) ?) => ( {
25
+ $crate:: rt:: panic_display ( & $arg)
26
+ } ) ,
23
27
( $fmt: expr, $( $arg: tt) +) => ( {
24
28
$crate:: rt:: begin_panic_fmt ( & $crate:: const_format_args!( $fmt, $( $arg) +) )
25
29
} ) ,
Original file line number Diff line number Diff line change 16
16
17
17
// Re-export some of our utilities which are expected by other crates.
18
18
pub use crate :: panicking:: { begin_panic, begin_panic_fmt, panic_count} ;
19
+ pub use core:: panicking:: panic_display;
19
20
20
21
// To reduce the generated code of the new `lang_start`, this function is doing
21
22
// the real work.
You can’t perform that action at this time.
0 commit comments