@@ -194,78 +194,92 @@ fn expand_struct_operators(strct: &Struct) -> TokenStream {
194
194
Trait :: PartialEq => {
195
195
let link_name = mangle:: operator ( & strct. name , "eq" ) ;
196
196
let local_name = format_ident ! ( "__operator_eq_{}" , strct. name. rust) ;
197
+ let prevent_unwind_label = format ! ( "::{} as PartialEq>::eq" , strct. name. rust) ;
197
198
operators. extend ( quote_spanned ! { span=>
198
199
#[ doc( hidden) ]
199
200
#[ export_name = #link_name]
200
201
extern "C" fn #local_name( lhs: & #ident, rhs: & #ident) -> bool {
201
- * lhs == * rhs
202
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
203
+ :: cxx:: private:: prevent_unwind( __fn, || * lhs == * rhs)
202
204
}
203
205
} ) ;
204
206
205
207
if !derive:: contains ( & strct. derives , Trait :: Eq ) {
206
208
let link_name = mangle:: operator ( & strct. name , "ne" ) ;
207
209
let local_name = format_ident ! ( "__operator_ne_{}" , strct. name. rust) ;
210
+ let prevent_unwind_label = format ! ( "::{} as PartialEq>::ne" , strct. name. rust) ;
208
211
operators. extend ( quote_spanned ! { span=>
209
212
#[ doc( hidden) ]
210
213
#[ export_name = #link_name]
211
214
extern "C" fn #local_name( lhs: & #ident, rhs: & #ident) -> bool {
212
- * lhs != * rhs
215
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
216
+ :: cxx:: private:: prevent_unwind( __fn, || * lhs != * rhs)
213
217
}
214
218
} ) ;
215
219
}
216
220
}
217
221
Trait :: PartialOrd => {
218
222
let link_name = mangle:: operator ( & strct. name , "lt" ) ;
219
223
let local_name = format_ident ! ( "__operator_lt_{}" , strct. name. rust) ;
224
+ let prevent_unwind_label = format ! ( "::{} as PartialOrd>::lt" , strct. name. rust) ;
220
225
operators. extend ( quote_spanned ! { span=>
221
226
#[ doc( hidden) ]
222
227
#[ export_name = #link_name]
223
228
extern "C" fn #local_name( lhs: & #ident, rhs: & #ident) -> bool {
224
- * lhs < * rhs
229
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
230
+ :: cxx:: private:: prevent_unwind( __fn, || * lhs < * rhs)
225
231
}
226
232
} ) ;
227
233
228
234
let link_name = mangle:: operator ( & strct. name , "le" ) ;
229
235
let local_name = format_ident ! ( "__operator_le_{}" , strct. name. rust) ;
236
+ let prevent_unwind_label = format ! ( "::{} as PartialOrd>::le" , strct. name. rust) ;
230
237
operators. extend ( quote_spanned ! { span=>
231
238
#[ doc( hidden) ]
232
239
#[ export_name = #link_name]
233
240
extern "C" fn #local_name( lhs: & #ident, rhs: & #ident) -> bool {
234
- * lhs <= * rhs
241
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
242
+ :: cxx:: private:: prevent_unwind( __fn, || * lhs <= * rhs)
235
243
}
236
244
} ) ;
237
245
238
246
if !derive:: contains ( & strct. derives , Trait :: Ord ) {
239
247
let link_name = mangle:: operator ( & strct. name , "gt" ) ;
240
248
let local_name = format_ident ! ( "__operator_gt_{}" , strct. name. rust) ;
249
+ let prevent_unwind_label = format ! ( "::{} as PartialOrd>::gt" , strct. name. rust) ;
241
250
operators. extend ( quote_spanned ! { span=>
242
251
#[ doc( hidden) ]
243
252
#[ export_name = #link_name]
244
253
extern "C" fn #local_name( lhs: & #ident, rhs: & #ident) -> bool {
245
- * lhs > * rhs
254
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
255
+ :: cxx:: private:: prevent_unwind( __fn, || * lhs > * rhs)
246
256
}
247
257
} ) ;
248
258
249
259
let link_name = mangle:: operator ( & strct. name , "ge" ) ;
250
260
let local_name = format_ident ! ( "__operator_ge_{}" , strct. name. rust) ;
261
+ let prevent_unwind_label = format ! ( "::{} as PartialOrd>::ge" , strct. name. rust) ;
251
262
operators. extend ( quote_spanned ! { span=>
252
263
#[ doc( hidden) ]
253
264
#[ export_name = #link_name]
254
265
extern "C" fn #local_name( lhs: & #ident, rhs: & #ident) -> bool {
255
- * lhs >= * rhs
266
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
267
+ :: cxx:: private:: prevent_unwind( __fn, || * lhs >= * rhs)
256
268
}
257
269
} ) ;
258
270
}
259
271
}
260
272
Trait :: Hash => {
261
273
let link_name = mangle:: operator ( & strct. name , "hash" ) ;
262
274
let local_name = format_ident ! ( "__operator_hash_{}" , strct. name. rust) ;
275
+ let prevent_unwind_label = format ! ( "::{} as Hash>::hash" , strct. name. rust) ;
263
276
operators. extend ( quote_spanned ! { span=>
264
277
#[ doc( hidden) ]
265
278
#[ export_name = #link_name]
266
279
#[ allow( clippy:: cast_possible_truncation) ]
267
280
extern "C" fn #local_name( this: & #ident) -> usize {
268
- :: cxx:: private:: hash( this)
281
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_label) ;
282
+ :: cxx:: private:: prevent_unwind( __fn, || :: cxx:: private:: hash( this) )
269
283
}
270
284
} ) ;
271
285
}
@@ -1222,13 +1236,16 @@ fn expand_rust_box(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl
1222
1236
let begin_span = explicit_impl. map_or ( key. begin_span , |explicit| explicit. impl_token . span ) ;
1223
1237
let end_span = explicit_impl. map_or ( key. end_span , |explicit| explicit. brace_token . span ) ;
1224
1238
let unsafe_token = format_ident ! ( "unsafe" , span = begin_span) ;
1239
+ let prevent_unwind_drop_label = format ! ( "::{} as Drop>::drop" , ident) ;
1225
1240
1226
1241
quote_spanned ! { end_span=>
1227
1242
#[ doc( hidden) ]
1228
1243
#unsafe_token impl #impl_generics :: cxx:: private:: ImplBox for #ident #ty_generics { }
1229
1244
#[ doc( hidden) ]
1230
1245
#[ export_name = #link_alloc]
1231
1246
unsafe extern "C" fn #local_alloc #impl_generics( ) -> * mut :: cxx:: core:: mem:: MaybeUninit <#ident #ty_generics> {
1247
+ // No prevent_unwind: the global allocator is not allowed to panic.
1248
+ //
1232
1249
// TODO: replace with Box::new_uninit when stable.
1233
1250
// https://doc.rust-lang.org/std/boxed/struct.Box.html#method.new_uninit
1234
1251
// https://github.com/rust-lang/rust/issues/63291
@@ -1237,12 +1254,14 @@ fn expand_rust_box(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl
1237
1254
#[ doc( hidden) ]
1238
1255
#[ export_name = #link_dealloc]
1239
1256
unsafe extern "C" fn #local_dealloc #impl_generics( ptr: * mut :: cxx:: core:: mem:: MaybeUninit <#ident #ty_generics>) {
1257
+ // No prevent_unwind: the global allocator is not allowed to panic.
1240
1258
:: cxx:: alloc:: boxed:: Box :: from_raw( ptr) ;
1241
1259
}
1242
1260
#[ doc( hidden) ]
1243
1261
#[ export_name = #link_drop]
1244
1262
unsafe extern "C" fn #local_drop #impl_generics( this: * mut :: cxx:: alloc:: boxed:: Box <#ident #ty_generics>) {
1245
- :: cxx:: core:: ptr:: drop_in_place( this) ;
1263
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_drop_label) ;
1264
+ :: cxx:: private:: prevent_unwind( __fn, || :: cxx:: core:: ptr:: drop_in_place( this) ) ;
1246
1265
}
1247
1266
}
1248
1267
}
@@ -1275,49 +1294,58 @@ fn expand_rust_vec(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl
1275
1294
let begin_span = explicit_impl. map_or ( key. begin_span , |explicit| explicit. impl_token . span ) ;
1276
1295
let end_span = explicit_impl. map_or ( key. end_span , |explicit| explicit. brace_token . span ) ;
1277
1296
let unsafe_token = format_ident ! ( "unsafe" , span = begin_span) ;
1297
+ let prevent_unwind_drop_label = format ! ( "::{} as Drop>::drop" , elem) ;
1278
1298
1279
1299
quote_spanned ! { end_span=>
1280
1300
#[ doc( hidden) ]
1281
1301
#unsafe_token impl #impl_generics :: cxx:: private:: ImplVec for #elem #ty_generics { }
1282
1302
#[ doc( hidden) ]
1283
1303
#[ export_name = #link_new]
1284
1304
unsafe extern "C" fn #local_new #impl_generics( this: * mut :: cxx:: private:: RustVec <#elem #ty_generics>) {
1305
+ // No prevent_unwind: cannot panic.
1285
1306
:: cxx:: core:: ptr:: write( this, :: cxx:: private:: RustVec :: new( ) ) ;
1286
1307
}
1287
1308
#[ doc( hidden) ]
1288
1309
#[ export_name = #link_drop]
1289
1310
unsafe extern "C" fn #local_drop #impl_generics( this: * mut :: cxx:: private:: RustVec <#elem #ty_generics>) {
1290
- :: cxx:: core:: ptr:: drop_in_place( this) ;
1311
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_drop_label) ;
1312
+ :: cxx:: private:: prevent_unwind( __fn, || :: cxx:: core:: ptr:: drop_in_place( this) ) ;
1291
1313
}
1292
1314
#[ doc( hidden) ]
1293
1315
#[ export_name = #link_len]
1294
1316
unsafe extern "C" fn #local_len #impl_generics( this: * const :: cxx:: private:: RustVec <#elem #ty_generics>) -> usize {
1317
+ // No prevent_unwind: cannot panic.
1295
1318
( * this) . len( )
1296
1319
}
1297
1320
#[ doc( hidden) ]
1298
1321
#[ export_name = #link_capacity]
1299
1322
unsafe extern "C" fn #local_capacity #impl_generics( this: * const :: cxx:: private:: RustVec <#elem #ty_generics>) -> usize {
1323
+ // No prevent_unwind: cannot panic.
1300
1324
( * this) . capacity( )
1301
1325
}
1302
1326
#[ doc( hidden) ]
1303
1327
#[ export_name = #link_data]
1304
1328
unsafe extern "C" fn #local_data #impl_generics( this: * const :: cxx:: private:: RustVec <#elem #ty_generics>) -> * const #elem #ty_generics {
1329
+ // No prevent_unwind: cannot panic.
1305
1330
( * this) . as_ptr( )
1306
1331
}
1307
1332
#[ doc( hidden) ]
1308
1333
#[ export_name = #link_reserve_total]
1309
1334
unsafe extern "C" fn #local_reserve_total #impl_generics( this: * mut :: cxx:: private:: RustVec <#elem #ty_generics>, new_cap: usize ) {
1335
+ // No prevent_unwind: the global allocator is not allowed to panic.
1310
1336
( * this) . reserve_total( new_cap) ;
1311
1337
}
1312
1338
#[ doc( hidden) ]
1313
1339
#[ export_name = #link_set_len]
1314
1340
unsafe extern "C" fn #local_set_len #impl_generics( this: * mut :: cxx:: private:: RustVec <#elem #ty_generics>, len: usize ) {
1341
+ // No prevent_unwind: cannot panic.
1315
1342
( * this) . set_len( len) ;
1316
1343
}
1317
1344
#[ doc( hidden) ]
1318
1345
#[ export_name = #link_clear]
1319
1346
unsafe extern "C" fn #local_clear #impl_generics( this: * mut :: cxx:: private:: RustVec <#elem #ty_generics>) {
1320
- ( * this) . clear( ) ;
1347
+ let __fn = concat!( "<" , module_path!( ) , #prevent_unwind_drop_label) ;
1348
+ :: cxx:: private:: prevent_unwind( __fn, || ( * this) . clear( ) ) ;
1321
1349
}
1322
1350
}
1323
1351
}
0 commit comments