@@ -964,8 +964,16 @@ impl<T> Vec<T> {
964
964
#[ inline]
965
965
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
966
966
pub fn swap_remove ( & mut self , index : usize ) -> T {
967
+ #[ cold]
968
+ #[ inline( never) ]
969
+ fn assert_failed ( index : usize , len : usize ) -> ! {
970
+ panic ! ( "swap_remove index (is {}) should be < len (is {})" , index, len) ;
971
+ }
972
+
967
973
let len = self . len ( ) ;
968
- assert ! ( index < len) ;
974
+ if !( index < len) {
975
+ assert_failed ( index, len) ;
976
+ }
969
977
unsafe {
970
978
// We replace self[index] with the last element. Note that if the
971
979
// bounds check above succeeds there must be a last element (which
@@ -995,8 +1003,16 @@ impl<T> Vec<T> {
995
1003
/// ```
996
1004
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
997
1005
pub fn insert ( & mut self , index : usize , element : T ) {
1006
+ #[ cold]
1007
+ #[ inline( never) ]
1008
+ fn assert_failed ( index : usize , len : usize ) -> ! {
1009
+ panic ! ( "insertion index (is {}) should be <= len (is {})" , index, len) ;
1010
+ }
1011
+
998
1012
let len = self . len ( ) ;
999
- assert ! ( index <= len) ;
1013
+ if !( index <= len) {
1014
+ assert_failed ( index, len) ;
1015
+ }
1000
1016
1001
1017
// space for the new element
1002
1018
if len == self . buf . capacity ( ) {
@@ -1035,8 +1051,16 @@ impl<T> Vec<T> {
1035
1051
/// ```
1036
1052
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1037
1053
pub fn remove ( & mut self , index : usize ) -> T {
1054
+ #[ cold]
1055
+ #[ inline( never) ]
1056
+ fn assert_failed ( index : usize , len : usize ) -> ! {
1057
+ panic ! ( "removal index (is {}) should be < len (is {})" , index, len) ;
1058
+ }
1059
+
1038
1060
let len = self . len ( ) ;
1039
- assert ! ( index < len) ;
1061
+ if !( index < len) {
1062
+ assert_failed ( index, len) ;
1063
+ }
1040
1064
unsafe {
1041
1065
// infallible
1042
1066
let ret;
@@ -1294,8 +1318,25 @@ impl<T> Vec<T> {
1294
1318
Excluded ( & n) => n,
1295
1319
Unbounded => len,
1296
1320
} ;
1297
- assert ! ( start <= end) ;
1298
- assert ! ( end <= len) ;
1321
+
1322
+ #[ cold]
1323
+ #[ inline( never) ]
1324
+ fn start_assert_failed ( start : usize , end : usize ) -> ! {
1325
+ panic ! ( "start drain index (is {}) should be <= end drain index (is {})" , start, end) ;
1326
+ }
1327
+
1328
+ #[ cold]
1329
+ #[ inline( never) ]
1330
+ fn end_assert_failed ( end : usize , len : usize ) -> ! {
1331
+ panic ! ( "end drain index (is {}) should be <= len (is {})" , end, len) ;
1332
+ }
1333
+
1334
+ if !( start <= end) {
1335
+ start_assert_failed ( start, end) ;
1336
+ }
1337
+ if !( end <= len) {
1338
+ end_assert_failed ( end, len) ;
1339
+ }
1299
1340
1300
1341
unsafe {
1301
1342
// set self.vec length's to start, to be safe in case Drain is leaked
@@ -1385,7 +1426,15 @@ impl<T> Vec<T> {
1385
1426
#[ must_use = "use `.truncate()` if you don't need the other half" ]
1386
1427
#[ stable( feature = "split_off" , since = "1.4.0" ) ]
1387
1428
pub fn split_off ( & mut self , at : usize ) -> Self {
1388
- assert ! ( at <= self . len( ) , "`at` out of bounds" ) ;
1429
+ #[ cold]
1430
+ #[ inline( never) ]
1431
+ fn assert_failed ( at : usize , len : usize ) -> ! {
1432
+ panic ! ( "`at` split index (is {}) should be <= len (is {})" , at, len) ;
1433
+ }
1434
+
1435
+ if !( at <= self . len ( ) ) {
1436
+ assert_failed ( at, self . len ( ) ) ;
1437
+ }
1389
1438
1390
1439
let other_len = self . len - at;
1391
1440
let mut other = Vec :: with_capacity ( other_len) ;
0 commit comments