|
1 | 1 | 0a1,2
|
2 | 2 | > // verifast_options{prover:z3v4.5 skip_specless_fns}
|
3 | 3 | >
|
4 |
| -13c15 |
| 4 | +13c15,27 |
5 | 5 | < #![stable(feature = "rust1", since = "1.0.0")]
|
6 | 6 | ---
|
7 | 7 | > // This is a slightly tweaked version of https://github.com/rust-lang/rust/blob/c290e9de32e8ba6a673ef125fde40eadd395d170/library/alloc/src/collections/linked_list.rs
|
8 |
| -14a17,28 |
| 8 | +> |
9 | 9 | > //#![stable(feature = "rust1", since = "1.0.0")]
|
10 | 10 | > #![feature(rustc_attrs)]
|
11 | 11 | > #![feature(dropck_eyepatch)]
|
|
17 | 17 | > #![feature(box_into_inner)]
|
18 | 18 | >
|
19 | 19 | > use std as core;
|
20 |
| -> |
21 | 20 | 15a30
|
22 | 21 | > use core::fmt;
|
23 | 22 | 16a32
|
|
26 | 25 | > use core::mem;
|
27 | 26 | 20d36
|
28 | 27 | < use core::{fmt, mem};
|
29 |
| -22,24c38,39 |
| 28 | +22,24c38,40 |
30 | 29 | < use super::SpecExtend;
|
31 | 30 | < use crate::alloc::{Allocator, Global};
|
32 | 31 | < use crate::boxed::Box;
|
33 | 32 | ---
|
34 | 33 | > use std::alloc::{Allocator, Global};
|
35 | 34 | > use std::boxed::Box;
|
36 |
| -25a41 |
37 | 35 | >
|
38 | 36 | 28a45,48
|
39 | 37 | > trait SpecExtend<I> {
|
|
194 | 192 | ---
|
195 | 193 | > unsafe fn pop_front_node<'a>(&'a mut self) -> Option<Box<Node<T>, &'a A>>
|
196 | 194 | > {
|
197 |
| -197,199c225,229 |
| 195 | +197,199c225,235 |
198 | 196 | < self.head.map(|node| unsafe {
|
199 | 197 | < let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
|
200 | 198 | < self.head = node.next;
|
|
204 | 202 | > Some(node) => unsafe {
|
205 | 203 | > self.head = (*node.as_ptr()).next;
|
206 | 204 | > let node_ = Box::from_raw_in(node.as_ptr(), &self.alloc);
|
207 |
| -201,205c231,235 |
208 |
| -< match self.head { |
209 |
| -< None => self.tail = None, |
210 |
| -< // Not creating new mutable (unique!) references overlapping `element`. |
211 |
| -< Some(head) => (*head.as_ptr()).prev = None, |
212 |
| -< } |
213 |
| ---- |
| 205 | +> |
214 | 206 | > match self.head {
|
215 | 207 | > None => self.tail = None,
|
216 | 208 | > // Not creating new mutable (unique!) references overlapping `element`.
|
217 | 209 | > Some(head) => (*head.as_ptr()).prev = None,
|
218 | 210 | > }
|
219 |
| -207,209c237,240 |
| 211 | +201,204c237,238 |
| 212 | +< match self.head { |
| 213 | +< None => self.tail = None, |
| 214 | +< // Not creating new mutable (unique!) references overlapping `element`. |
| 215 | +< Some(head) => (*head.as_ptr()).prev = None, |
| 216 | +--- |
| 217 | +> self.len -= 1; |
| 218 | +> Some(node_) |
| 219 | +206,209c240 |
| 220 | +< |
220 | 221 | < self.len -= 1;
|
221 | 222 | < node
|
222 | 223 | < })
|
223 | 224 | ---
|
224 |
| -> self.len -= 1; |
225 |
| -> Some(node_) |
226 |
| -> } |
227 | 225 | > }
|
228 | 226 | 224c255
|
229 | 227 | < let node = Some(node);
|
|
241 | 239 | < self.tail = node;
|
242 | 240 | ---
|
243 | 241 | > self.tail = node_;
|
244 |
| -242,244c273,277 |
| 242 | +242,244c273,283 |
245 | 243 | < self.tail.map(|node| unsafe {
|
246 | 244 | < let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
|
247 | 245 | < self.tail = node.prev;
|
|
251 | 249 | > Some(node) => unsafe {
|
252 | 250 | > let node_ = Box::from_raw_in(node.as_ptr(), &self.alloc);
|
253 | 251 | > self.tail = node_.prev;
|
254 |
| -246,250c279,283 |
255 |
| -< match self.tail { |
256 |
| -< None => self.head = None, |
257 |
| -< // Not creating new mutable (unique!) references overlapping `element`. |
258 |
| -< Some(tail) => (*tail.as_ptr()).next = None, |
259 |
| -< } |
260 |
| ---- |
| 252 | +> |
261 | 253 | > match self.tail {
|
262 | 254 | > None => self.head = None,
|
263 | 255 | > // Not creating new mutable (unique!) references overlapping `element`.
|
264 | 256 | > Some(tail) => (*tail.as_ptr()).next = None,
|
265 | 257 | > }
|
266 |
| -252,254c285,288 |
| 258 | +246,249c285,286 |
| 259 | +< match self.tail { |
| 260 | +< None => self.head = None, |
| 261 | +< // Not creating new mutable (unique!) references overlapping `element`. |
| 262 | +< Some(tail) => (*tail.as_ptr()).next = None, |
| 263 | +--- |
| 264 | +> self.len -= 1; |
| 265 | +> Some(node_) |
| 266 | +251,254c288 |
| 267 | +< |
267 | 268 | < self.len -= 1;
|
268 | 269 | < node
|
269 | 270 | < })
|
270 | 271 | ---
|
271 |
| -> self.len -= 1; |
272 |
| -> Some(node_) |
273 |
| -> } |
274 | 272 | > }
|
275 | 273 | 264,265c298,300
|
276 | 274 | < unsafe fn unlink_node(&mut self, mut node: NonNull<Node<T>>) {
|
|
543 | 541 | < #[stable(feature = "rust1", since = "1.0.0")]
|
544 | 542 | ---
|
545 | 543 | > //#[stable(feature = "rust1", since = "1.0.0")]
|
546 |
| -955,971c1036,1044 |
| 544 | +955,982c1036,1076 |
547 | 545 | < let len = self.len();
|
548 | 546 | < assert!(at <= len, "Cannot split off at a nonexistent index");
|
549 | 547 | < if at == 0 {
|
|
561 | 559 | < // depending on implementation details of Skip
|
562 | 560 | < for _ in 0..at - 1 {
|
563 | 561 | < iter.next();
|
564 |
| ---- |
565 |
| -> unsafe { |
566 |
| -> let len = self.len; |
567 |
| -> assert!(at <= len, "Cannot split off at a nonexistent index"); |
568 |
| -> if at == 0 { |
569 |
| -> let alloc1 = clone_allocator(&self.alloc); |
570 |
| -> return mem::replace(self, Self::new_in(alloc1)); |
571 |
| -> } else if at == len { |
572 |
| -> let alloc2 = clone_allocator(&self.alloc); |
573 |
| -> return Self::new_in(alloc2); |
574 |
| -973,982c1046,1076 |
| 562 | +< } |
575 | 563 | < iter.head
|
576 | 564 | < } else {
|
577 | 565 | < // better off starting from the end
|
|
583 | 571 | < };
|
584 | 572 | < unsafe { self.split_off_after_node(split_node, at) }
|
585 | 573 | ---
|
| 574 | +> unsafe { |
| 575 | +> let len = self.len; |
| 576 | +> assert!(at <= len, "Cannot split off at a nonexistent index"); |
| 577 | +> if at == 0 { |
| 578 | +> let alloc1 = clone_allocator(&self.alloc); |
| 579 | +> return mem::replace(self, Self::new_in(alloc1)); |
| 580 | +> } else if at == len { |
| 581 | +> let alloc2 = clone_allocator(&self.alloc); |
| 582 | +> return Self::new_in(alloc2); |
| 583 | +> } |
586 | 584 | >
|
587 | 585 | > // Below, we iterate towards the `i-1`th node, either from the start or the end,
|
588 | 586 | > // depending on which would be faster.
|
|
645 | 643 | ---
|
646 | 644 | > let r = ExtractIf { list: self, it, pred: filter, idx: 0, old_len };
|
647 | 645 | > r
|
648 |
| -1168,1171c1265 |
| 646 | +1168,1169c1265,1267 |
649 | 647 | < #[stable(feature = "rust1", since = "1.0.0")]
|
650 | 648 | < unsafe impl<#[may_dangle] T, A: Allocator> Drop for LinkedList<T, A> {
|
651 |
| -< fn drop(&mut self) { |
652 |
| -< struct DropGuard<'a, T, A: Allocator>(&'a mut LinkedList<T, A>); |
653 | 649 | ---
|
654 | 650 | > struct DropGuard<'a, T, A: Allocator>(&'a mut LinkedList<T, A>);
|
655 |
| -1173,1178c1267,1272 |
656 |
| -< impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> { |
657 |
| -< fn drop(&mut self) { |
658 |
| -< // Continue the same loop we do below. This only runs when a destructor has |
659 |
| -< // panicked. If another one panics this will abort. |
660 |
| -< while self.0.pop_front_node().is_some() {} |
661 |
| -< } |
662 |
| ---- |
| 651 | +> |
663 | 652 | > impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> {
|
664 |
| -> fn drop(&mut self) { |
| 653 | +1171c1269,1275 |
| 654 | +< struct DropGuard<'a, T, A: Allocator>(&'a mut LinkedList<T, A>); |
| 655 | +--- |
665 | 656 | > unsafe {
|
666 | 657 | > // Continue the same loop we do below. This only runs when a destructor has
|
667 | 658 | > // panicked. If another one panics this will abort.
|
668 | 659 | > while self.0.pop_front_node().is_some() {}
|
669 |
| -1179a1274,1275 |
| 660 | +> } |
670 | 661 | > }
|
671 | 662 | > }
|
672 |
| -1181,1184c1277,1292 |
673 |
| -< // Wrap self so that if a destructor panics, we can try to keep looping |
674 |
| -< let guard = DropGuard(self); |
675 |
| -< while guard.0.pop_front_node().is_some() {} |
676 |
| -< mem::forget(guard); |
| 663 | +1173,1177c1277,1289 |
| 664 | +< impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> { |
| 665 | +< fn drop(&mut self) { |
| 666 | +< // Continue the same loop we do below. This only runs when a destructor has |
| 667 | +< // panicked. If another one panics this will abort. |
| 668 | +< while self.0.pop_front_node().is_some() {} |
677 | 669 | ---
|
678 | 670 | > //#[stable(feature = "rust1", since = "1.0.0")]
|
679 | 671 | > unsafe impl<#[may_dangle] T, A: Allocator> Drop for LinkedList<T, A> {
|
|
688 | 680 | > Some(element) => {
|
689 | 681 | > }
|
690 | 682 | > }
|
691 |
| -> } |
| 683 | +1178a1291 |
692 | 684 | > mem::forget(guard);
|
693 |
| -> } |
| 685 | +1180,1184d1292 |
| 686 | +< |
| 687 | +< // Wrap self so that if a destructor panics, we can try to keep looping |
| 688 | +< let guard = DropGuard(self); |
| 689 | +< while guard.0.pop_front_node().is_some() {} |
| 690 | +< mem::forget(guard); |
694 | 691 | 1188c1296
|
695 | 692 | < #[stable(feature = "rust1", since = "1.0.0")]
|
696 | 693 | ---
|
|
901 | 898 | < #[unstable(feature = "linked_list_cursors", issue = "58533")]
|
902 | 899 | ---
|
903 | 900 | > /*#[unstable(feature = "linked_list_cursors", issue = "58533")]*/
|
904 |
| -1614,1625d1740 |
905 |
| -< } |
| 901 | +1615,1626d1741 |
906 | 902 | <
|
907 | 903 | < /// Provides a read-only reference to the cursor's parent list.
|
908 | 904 | < ///
|
|
914 | 910 | < #[unstable(feature = "linked_list_cursors", issue = "58533")]
|
915 | 911 | < pub fn as_list(&self) -> &LinkedList<T, A> {
|
916 | 912 | < self.list
|
| 913 | +< } |
917 | 914 | 1636c1751
|
918 | 915 | < #[unstable(feature = "linked_list_cursors", issue = "58533")]
|
919 | 916 | ---
|
|
1019 | 1016 | >
|
1020 | 1017 | > /*#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]*/
|
1021 | 1018 | > impl<'a, T, F, A: Allocator> Iterator for ExtractIf<'a, T, F, A>
|
1022 |
| -1959,1963c2087,2095 |
| 1019 | +1959,1968c2087,2103 |
1023 | 1020 | < fn next(&mut self) -> Option<T> {
|
1024 | 1021 | < while let Some(mut node) = self.it {
|
1025 | 1022 | < unsafe {
|
1026 | 1023 | < self.it = node.as_ref().next;
|
1027 | 1024 | < self.idx += 1;
|
| 1025 | +< |
| 1026 | +< if (self.pred)(&mut node.as_mut().element) { |
| 1027 | +< // `unlink_node` is okay with aliasing `element` references. |
| 1028 | +< self.list.unlink_node(node); |
| 1029 | +< return Some(Box::from_raw_in(node.as_ptr(), &self.list.alloc).element); |
1028 | 1030 | ---
|
1029 | 1031 | > fn next(&mut self) -> Option<T>
|
1030 | 1032 | > {
|
|
1035 | 1037 | > self.it = (*node.as_ptr()).next; //node.as_ref().next;
|
1036 | 1038 | > self.idx += 1;
|
1037 | 1039 | >
|
1038 |
| -1965,1968c2097,2103 |
1039 |
| -< if (self.pred)(&mut node.as_mut().element) { |
1040 |
| -< // `unlink_node` is okay with aliasing `element` references. |
1041 |
| -< self.list.unlink_node(node); |
1042 |
| -< return Some(Box::from_raw_in(node.as_ptr(), &self.list.alloc).element); |
1043 |
| ---- |
| 1040 | +> |
1044 | 1041 | > if call_pred(&mut self.pred, &mut node.as_mut().element) {
|
1045 | 1042 | > // `unlink_node` is okay with aliasing `element` references.
|
1046 | 1043 | > self.list.unlink_node(node);
|
|
1130 | 1127 | < #[stable(feature = "std_collections_from_array", since = "1.56.0")]
|
1131 | 1128 | ---
|
1132 | 1129 | > //#[stable(feature = "std_collections_from_array", since = "1.56.0")]
|
1133 |
| -2203,2212c2337,2338 |
| 1130 | +2203,2212c2337,2348 |
1134 | 1131 | < fn assert_covariance() {
|
1135 | 1132 | < fn a<'a>(x: LinkedList<&'static str>) -> LinkedList<&'a str> {
|
1136 | 1133 | < x
|
|
1144 | 1141 | ---
|
1145 | 1142 | > fn assert_covariance_a<'a>(x: LinkedList<&'static str>) -> LinkedList<&'a str> {
|
1146 | 1143 | > x
|
1147 |
| -2215c2341,2351 |
1148 |
| -< #[stable(feature = "rust1", since = "1.0.0")] |
1149 |
| ---- |
| 1144 | +> } |
| 1145 | +> |
1150 | 1146 | > #[allow(dead_code)]
|
1151 | 1147 | > fn assert_covariance_b<'i, 'a>(x: Iter<'i, &'static str>) -> Iter<'i, &'a str> {
|
1152 | 1148 | > x
|
|
1155 | 1151 | > #[allow(dead_code)]
|
1156 | 1152 | > fn assert_covariance_c<'a>(x: IntoIter<&'static str>) -> IntoIter<&'a str> {
|
1157 | 1153 | > x
|
1158 |
| -> } |
1159 |
| -> |
| 1154 | +2215c2351 |
| 1155 | +< #[stable(feature = "rust1", since = "1.0.0")] |
| 1156 | +--- |
1160 | 1157 | > //#[stable(feature = "rust1", since = "1.0.0")]
|
1161 | 1158 | 2218c2354
|
1162 | 1159 | < #[stable(feature = "rust1", since = "1.0.0")]
|
|
0 commit comments