@@ -155,56 +155,64 @@ pub const fn panic(expr: &'static str) -> ! {
155
155
// reducing binary size impact.
156
156
macro_rules! panic_const {
157
157
( $( $lang: ident = $message: expr, ) +) => {
158
- pub mod panic_const {
159
- use super :: * ;
160
-
161
- $(
162
- /// This is a panic called with a message that's a result of a MIR-produced Assert.
163
- //
164
- // never inline unless panic_immediate_abort to avoid code
165
- // bloat at the call sites as much as possible
166
- #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) , cold) ]
167
- #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
168
- #[ track_caller]
169
- #[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
170
- #[ lang = stringify!( $lang) ]
171
- pub const fn $lang( ) -> ! {
172
- // Use Arguments::new_const instead of format_args!("{expr}") to potentially
173
- // reduce size overhead. The format_args! macro uses str's Display trait to
174
- // write expr, which calls Formatter::pad, which must accommodate string
175
- // truncation and padding (even though none is used here). Using
176
- // Arguments::new_const may allow the compiler to omit Formatter::pad from the
177
- // output binary, saving up to a few kilobytes.
178
- panic_fmt( fmt:: Arguments :: new_const( & [ $message] ) ) ;
179
- }
180
- ) +
181
- }
158
+ $(
159
+ /// This is a panic called with a message that's a result of a MIR-produced Assert.
160
+ //
161
+ // never inline unless panic_immediate_abort to avoid code
162
+ // bloat at the call sites as much as possible
163
+ #[ cfg_attr( not( feature = "panic_immediate_abort" ) , inline( never) , cold) ]
164
+ #[ cfg_attr( feature = "panic_immediate_abort" , inline) ]
165
+ #[ track_caller]
166
+ #[ rustc_const_stable_indirect] // must follow stable const rules since it is exposed to stable
167
+ #[ lang = stringify!( $lang) ]
168
+ pub const fn $lang( ) -> ! {
169
+ // Use Arguments::new_const instead of format_args!("{expr}") to potentially
170
+ // reduce size overhead. The format_args! macro uses str's Display trait to
171
+ // write expr, which calls Formatter::pad, which must accommodate string
172
+ // truncation and padding (even though none is used here). Using
173
+ // Arguments::new_const may allow the compiler to omit Formatter::pad from the
174
+ // output binary, saving up to a few kilobytes.
175
+ panic_fmt( fmt:: Arguments :: new_const( & [ $message] ) ) ;
176
+ }
177
+ ) +
182
178
}
183
179
}
184
180
185
181
// Unfortunately this set of strings is replicated here and in a few places in the compiler in
186
182
// slightly different forms. It's not clear if there's a good way to deduplicate without adding
187
183
// special cases to the compiler (e.g., a const generic function wouldn't have a single definition
188
184
// shared across crates, which is exactly what we want here).
189
- panic_const ! {
190
- panic_const_add_overflow = "attempt to add with overflow" ,
191
- panic_const_sub_overflow = "attempt to subtract with overflow" ,
192
- panic_const_mul_overflow = "attempt to multiply with overflow" ,
193
- panic_const_div_overflow = "attempt to divide with overflow" ,
194
- panic_const_rem_overflow = "attempt to calculate the remainder with overflow" ,
195
- panic_const_neg_overflow = "attempt to negate with overflow" ,
196
- panic_const_shr_overflow = "attempt to shift right with overflow" ,
197
- panic_const_shl_overflow = "attempt to shift left with overflow" ,
198
- panic_const_div_by_zero = "attempt to divide by zero" ,
199
- panic_const_rem_by_zero = "attempt to calculate the remainder with a divisor of zero" ,
200
- panic_const_coroutine_resumed = "coroutine resumed after completion" ,
201
- panic_const_async_fn_resumed = "`async fn` resumed after completion" ,
202
- panic_const_async_gen_fn_resumed = "`async gen fn` resumed after completion" ,
203
- panic_const_gen_fn_none = "`gen fn` should just keep returning `None` after completion" ,
204
- panic_const_coroutine_resumed_panic = "coroutine resumed after panicking" ,
205
- panic_const_async_fn_resumed_panic = "`async fn` resumed after panicking" ,
206
- panic_const_async_gen_fn_resumed_panic = "`async gen fn` resumed after panicking" ,
207
- panic_const_gen_fn_none_panic = "`gen fn` should just keep returning `None` after panicking" ,
185
+ pub mod panic_const {
186
+ use super :: * ;
187
+ panic_const ! {
188
+ panic_const_add_overflow = "attempt to add with overflow" ,
189
+ panic_const_sub_overflow = "attempt to subtract with overflow" ,
190
+ panic_const_mul_overflow = "attempt to multiply with overflow" ,
191
+ panic_const_div_overflow = "attempt to divide with overflow" ,
192
+ panic_const_rem_overflow = "attempt to calculate the remainder with overflow" ,
193
+ panic_const_neg_overflow = "attempt to negate with overflow" ,
194
+ panic_const_shr_overflow = "attempt to shift right with overflow" ,
195
+ panic_const_shl_overflow = "attempt to shift left with overflow" ,
196
+ panic_const_div_by_zero = "attempt to divide by zero" ,
197
+ panic_const_rem_by_zero = "attempt to calculate the remainder with a divisor of zero" ,
198
+ panic_const_coroutine_resumed = "coroutine resumed after completion" ,
199
+ panic_const_async_fn_resumed = "`async fn` resumed after completion" ,
200
+ panic_const_async_gen_fn_resumed = "`async gen fn` resumed after completion" ,
201
+ panic_const_gen_fn_none = "`gen fn` should just keep returning `None` after completion" ,
202
+ panic_const_coroutine_resumed_panic = "coroutine resumed after panicking" ,
203
+ panic_const_async_fn_resumed_panic = "`async fn` resumed after panicking" ,
204
+ panic_const_async_gen_fn_resumed_panic = "`async gen fn` resumed after panicking" ,
205
+ panic_const_gen_fn_none_panic = "`gen fn` should just keep returning `None` after panicking" ,
206
+ }
207
+ // Separated panic constants list for async drop feature
208
+ // (May be joined when the corresponding lang items will be in the bootstrap)
209
+ #[ cfg( not( bootstrap) ) ]
210
+ panic_const ! {
211
+ panic_const_coroutine_resumed_drop = "coroutine resumed after async drop" ,
212
+ panic_const_async_fn_resumed_drop = "`async fn` resumed after async drop" ,
213
+ panic_const_async_gen_fn_resumed_drop = "`async gen fn` resumed after async drop" ,
214
+ panic_const_gen_fn_none_drop = "`gen fn` resumed after async drop" ,
215
+ }
208
216
}
209
217
210
218
/// Like `panic`, but without unwinding and track_caller to reduce the impact on codesize on the caller.
0 commit comments