@@ -166,6 +166,10 @@ pub enum Ordering {
166
166
/// sequentially consistent operations in the same order.
167
167
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
168
168
SeqCst ,
169
+ // Prevent exhaustive matching to allow for future extension
170
+ #[ doc( hidden) ]
171
+ #[ unstable( feature = "future_atomic_orderings" , issue = "0" ) ]
172
+ __Nonexhaustive,
169
173
}
170
174
171
175
/// An `AtomicBool` initialized to `false`.
@@ -1277,6 +1281,7 @@ fn strongest_failure_ordering(order: Ordering) -> Ordering {
1277
1281
SeqCst => SeqCst ,
1278
1282
Acquire => Acquire ,
1279
1283
AcqRel => Acquire ,
1284
+ __Nonexhaustive => __Nonexhaustive,
1280
1285
}
1281
1286
}
1282
1287
@@ -1288,6 +1293,7 @@ unsafe fn atomic_store<T>(dst: *mut T, val: T, order: Ordering) {
1288
1293
SeqCst => intrinsics:: atomic_store ( dst, val) ,
1289
1294
Acquire => panic ! ( "there is no such thing as an acquire store" ) ,
1290
1295
AcqRel => panic ! ( "there is no such thing as an acquire/release store" ) ,
1296
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1291
1297
}
1292
1298
}
1293
1299
@@ -1299,6 +1305,7 @@ unsafe fn atomic_load<T>(dst: *const T, order: Ordering) -> T {
1299
1305
SeqCst => intrinsics:: atomic_load ( dst) ,
1300
1306
Release => panic ! ( "there is no such thing as a release load" ) ,
1301
1307
AcqRel => panic ! ( "there is no such thing as an acquire/release load" ) ,
1308
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1302
1309
}
1303
1310
}
1304
1311
@@ -1310,6 +1317,7 @@ unsafe fn atomic_swap<T>(dst: *mut T, val: T, order: Ordering) -> T {
1310
1317
AcqRel => intrinsics:: atomic_xchg_acqrel ( dst, val) ,
1311
1318
Relaxed => intrinsics:: atomic_xchg_relaxed ( dst, val) ,
1312
1319
SeqCst => intrinsics:: atomic_xchg ( dst, val) ,
1320
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1313
1321
}
1314
1322
}
1315
1323
@@ -1322,6 +1330,7 @@ unsafe fn atomic_add<T>(dst: *mut T, val: T, order: Ordering) -> T {
1322
1330
AcqRel => intrinsics:: atomic_xadd_acqrel ( dst, val) ,
1323
1331
Relaxed => intrinsics:: atomic_xadd_relaxed ( dst, val) ,
1324
1332
SeqCst => intrinsics:: atomic_xadd ( dst, val) ,
1333
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1325
1334
}
1326
1335
}
1327
1336
@@ -1334,6 +1343,7 @@ unsafe fn atomic_sub<T>(dst: *mut T, val: T, order: Ordering) -> T {
1334
1343
AcqRel => intrinsics:: atomic_xsub_acqrel ( dst, val) ,
1335
1344
Relaxed => intrinsics:: atomic_xsub_relaxed ( dst, val) ,
1336
1345
SeqCst => intrinsics:: atomic_xsub ( dst, val) ,
1346
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1337
1347
}
1338
1348
}
1339
1349
@@ -1354,6 +1364,8 @@ unsafe fn atomic_compare_exchange<T>(dst: *mut T,
1354
1364
( AcqRel , Relaxed ) => intrinsics:: atomic_cxchg_acqrel_failrelaxed ( dst, old, new) ,
1355
1365
( SeqCst , Relaxed ) => intrinsics:: atomic_cxchg_failrelaxed ( dst, old, new) ,
1356
1366
( SeqCst , Acquire ) => intrinsics:: atomic_cxchg_failacq ( dst, old, new) ,
1367
+ ( __Nonexhaustive, _) => panic ! ( "invalid memory ordering" ) ,
1368
+ ( _, __Nonexhaustive) => panic ! ( "invalid memory ordering" ) ,
1357
1369
( _, AcqRel ) => panic ! ( "there is no such thing as an acquire/release failure ordering" ) ,
1358
1370
( _, Release ) => panic ! ( "there is no such thing as a release failure ordering" ) ,
1359
1371
_ => panic ! ( "a failure ordering can't be stronger than a success ordering" ) ,
@@ -1378,6 +1390,8 @@ unsafe fn atomic_compare_exchange_weak<T>(dst: *mut T,
1378
1390
( AcqRel , Relaxed ) => intrinsics:: atomic_cxchgweak_acqrel_failrelaxed ( dst, old, new) ,
1379
1391
( SeqCst , Relaxed ) => intrinsics:: atomic_cxchgweak_failrelaxed ( dst, old, new) ,
1380
1392
( SeqCst , Acquire ) => intrinsics:: atomic_cxchgweak_failacq ( dst, old, new) ,
1393
+ ( __Nonexhaustive, _) => panic ! ( "invalid memory ordering" ) ,
1394
+ ( _, __Nonexhaustive) => panic ! ( "invalid memory ordering" ) ,
1381
1395
( _, AcqRel ) => panic ! ( "there is no such thing as an acquire/release failure ordering" ) ,
1382
1396
( _, Release ) => panic ! ( "there is no such thing as a release failure ordering" ) ,
1383
1397
_ => panic ! ( "a failure ordering can't be stronger than a success ordering" ) ,
@@ -1393,6 +1407,7 @@ unsafe fn atomic_and<T>(dst: *mut T, val: T, order: Ordering) -> T {
1393
1407
AcqRel => intrinsics:: atomic_and_acqrel ( dst, val) ,
1394
1408
Relaxed => intrinsics:: atomic_and_relaxed ( dst, val) ,
1395
1409
SeqCst => intrinsics:: atomic_and ( dst, val) ,
1410
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1396
1411
}
1397
1412
}
1398
1413
@@ -1404,6 +1419,7 @@ unsafe fn atomic_or<T>(dst: *mut T, val: T, order: Ordering) -> T {
1404
1419
AcqRel => intrinsics:: atomic_or_acqrel ( dst, val) ,
1405
1420
Relaxed => intrinsics:: atomic_or_relaxed ( dst, val) ,
1406
1421
SeqCst => intrinsics:: atomic_or ( dst, val) ,
1422
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1407
1423
}
1408
1424
}
1409
1425
@@ -1415,6 +1431,7 @@ unsafe fn atomic_xor<T>(dst: *mut T, val: T, order: Ordering) -> T {
1415
1431
AcqRel => intrinsics:: atomic_xor_acqrel ( dst, val) ,
1416
1432
Relaxed => intrinsics:: atomic_xor_relaxed ( dst, val) ,
1417
1433
SeqCst => intrinsics:: atomic_xor ( dst, val) ,
1434
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1418
1435
}
1419
1436
}
1420
1437
@@ -1448,6 +1465,7 @@ pub fn fence(order: Ordering) {
1448
1465
AcqRel => intrinsics:: atomic_fence_acqrel ( ) ,
1449
1466
SeqCst => intrinsics:: atomic_fence ( ) ,
1450
1467
Relaxed => panic ! ( "there is no such thing as a relaxed fence" ) ,
1468
+ __Nonexhaustive => panic ! ( "invalid memory ordering" ) ,
1451
1469
}
1452
1470
}
1453
1471
}
0 commit comments