@@ -17,7 +17,7 @@ pub use self::unwind_safe::{AssertUnwindSafe, RefUnwindSafe, UnwindSafe};
17
17
18
18
#[ doc( hidden) ]
19
19
#[ unstable( feature = "edition_panic" , issue = "none" , reason = "use panic!() instead" ) ]
20
- #[ allow_internal_unstable( panic_internals, const_format_args) ]
20
+ #[ allow_internal_unstable( panic_internals, const_format_args, never_type , stmt_expr_attributes ) ]
21
21
#[ rustc_diagnostic_item = "core_panic_2015_macro" ]
22
22
#[ rustc_macro_transparency = "semitransparent" ]
23
23
pub macro panic_2015 {
@@ -28,23 +28,26 @@ pub macro panic_2015 {
28
28
$crate:: panicking:: panic ( $msg)
29
29
) ,
30
30
// Use `panic_str` instead of `panic_display::<&str>` for non_fmt_panic lint.
31
- ( $msg: expr $( , ) ?) => ( {
32
- $crate:: panicking:: panic_str ( $msg) ;
33
- } ) ,
31
+ ( $msg: expr $( , ) ?) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
32
+ let _never = $crate:: panicking:: panic_str ( $msg) ;
33
+ _never
34
+ } ) ) ,
34
35
// Special-case the single-argument case for const_panic.
35
- ( "{}" , $arg: expr $( , ) ?) => ( {
36
- $crate:: panicking:: panic_display ( & $arg) ;
37
- } ) ,
38
- ( $fmt: expr, $( $arg: tt) +) => ( {
36
+ ( "{}" , $arg: expr $( , ) ?) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
37
+ let _never = $crate:: panicking:: panic_display ( & $arg) ;
38
+ _never
39
+ } ) ) ,
40
+ ( $fmt: expr, $( $arg: tt) +) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
39
41
// Semicolon to prevent temporaries inside the formatting machinery from
40
42
// being considered alive in the caller after the panic_fmt call.
41
- $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $fmt, $( $arg) +) ) ;
42
- } ) ,
43
+ let _never = $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $fmt, $( $arg) +) ) ;
44
+ _never
45
+ } ) ) ,
43
46
}
44
47
45
48
#[ doc ( hidden) ]
46
49
#[ unstable ( feature = "edition_panic" , issue = "none" , reason = "use panic!() instead" ) ]
47
- #[ allow_internal_unstable( panic_internals, const_format_args) ]
50
+ #[ allow_internal_unstable ( panic_internals, const_format_args, never_type , stmt_expr_attributes ) ]
48
51
#[ rustc_diagnostic_item = "core_panic_2021_macro" ]
49
52
#[ rustc_macro_transparency = "semitransparent" ]
50
53
#[ cfg ( feature = "panic_immediate_abort" ) ]
@@ -53,14 +56,16 @@ pub macro panic_2021 {
53
56
$crate:: panicking:: panic ( "explicit panic" )
54
57
) ,
55
58
// Special-case the single-argument case for const_panic.
56
- ( "{}" , $arg: expr $( , ) ?) => ( {
57
- $crate:: panicking:: panic_display ( & $arg) ;
58
- } ) ,
59
- ( $( $t: tt) +) => ( {
59
+ ( "{}" , $arg: expr $( , ) ?) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
60
+ let _never = $crate:: panicking:: panic_display ( & $arg) ;
61
+ _never
62
+ } ) ) ,
63
+ ( $( $t: tt) +) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
60
64
// Semicolon to prevent temporaries inside the formatting machinery from
61
65
// being considered alive in the caller after the panic_fmt call.
62
- $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $( $t) +) ) ;
63
- } ) ,
66
+ let _never = $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $( $t) +) ) ;
67
+ _never
68
+ } ) ) ,
64
69
}
65
70
66
71
#[ doc ( hidden) ]
@@ -71,13 +76,15 @@ pub macro panic_2021 {
71
76
const_dispatch,
72
77
const_eval_select,
73
78
const_format_args,
74
- rustc_attrs
79
+ rustc_attrs,
80
+ never_type,
81
+ stmt_expr_attributes
75
82
) ]
76
83
#[ rustc_diagnostic_item = "core_panic_2021_macro" ]
77
84
#[ rustc_macro_transparency = "semitransparent" ]
78
85
#[ cfg ( not ( feature = "panic_immediate_abort" ) ) ]
79
86
pub macro panic_2021 {
80
- ( ) => ( {
87
+ ( ) => ( # [ allow ( unreachable_code ) ] $crate :: convert :: identity :: < ! > ( {
81
88
// Create a function so that the argument for `track_caller`
82
89
// can be moved inside if possible.
83
90
#[ cold]
@@ -86,10 +93,11 @@ pub macro panic_2021 {
86
93
const fn panic_cold_explicit ( ) -> ! {
87
94
$crate:: panicking:: panic_explicit ( )
88
95
}
89
- panic_cold_explicit ( ) ;
90
- } ) ,
96
+ let _never = panic_cold_explicit ( ) ;
97
+ _never
98
+ } ) ) ,
91
99
// Special-case the single-argument case for const_panic.
92
- ( "{}" , $arg: expr $( , ) ?) => ( {
100
+ ( "{}" , $arg: expr $( , ) ?) => ( # [ allow ( unreachable_code ) ] $crate :: convert :: identity :: < ! > ( {
93
101
#[ cold]
94
102
#[ track_caller]
95
103
#[ inline( never) ]
@@ -98,18 +106,20 @@ pub macro panic_2021 {
98
106
const fn panic_cold_display < T : $crate:: fmt:: Display > ( arg : & T ) -> ! {
99
107
$crate:: panicking:: panic_display ( arg)
100
108
}
101
- panic_cold_display ( & $arg) ;
102
- } ) ,
103
- ( $( $t: tt) +) => ( {
109
+ let _never = panic_cold_display ( & $arg) ;
110
+ _never
111
+ } ) ) ,
112
+ ( $( $t: tt) +) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
104
113
// Semicolon to prevent temporaries inside the formatting machinery from
105
114
// being considered alive in the caller after the panic_fmt call.
106
- $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $( $t) +) ) ;
107
- } ) ,
115
+ let _never = $crate:: panicking:: panic_fmt ( $crate:: const_format_args!( $( $t) +) ) ;
116
+ _never
117
+ } ) ) ,
108
118
}
109
119
110
120
#[ doc ( hidden) ]
111
121
#[ unstable ( feature = "edition_panic" , issue = "none" , reason = "use unreachable!() instead" ) ]
112
- #[ allow_internal_unstable( panic_internals) ]
122
+ #[ allow_internal_unstable ( panic_internals, never_type , stmt_expr_attributes ) ]
113
123
#[ rustc_diagnostic_item = "unreachable_2015_macro" ]
114
124
#[ rustc_macro_transparency = "semitransparent" ]
115
125
pub macro unreachable_2015 {
@@ -118,9 +128,10 @@ pub macro unreachable_2015 {
118
128
) ,
119
129
// Use of `unreachable_display` for non_fmt_panic lint.
120
130
// NOTE: the message ("internal error ...") is embedded directly in unreachable_display
121
- ( $msg: expr $( , ) ?) => ( {
122
- $crate:: panicking:: unreachable_display ( & $msg) ;
123
- } ) ,
131
+ ( $msg: expr $( , ) ?) => ( #[ allow( unreachable_code) ] $crate:: convert:: identity :: < !> ( {
132
+ let _never = $crate:: panicking:: unreachable_display ( & $msg) ;
133
+ _never
134
+ } ) ) ,
124
135
( $fmt: expr, $( $arg: tt) * ) => (
125
136
$crate:: panic!( $crate :: concat!( "internal error: entered unreachable code: " , $fmt) , $( $arg) * )
126
137
) ,
0 commit comments