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