Mitigate focused memory leaks in alloc
doctests for Miri. · model-checking/verify-rust-std@20d6cb3 (original) (raw)
4 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1213,6 +1213,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> { | ||
1213 | 1213 | /// let static_ref: &'static mut usize = Box::leak(x); |
1214 | 1214 | /// *static_ref += 1; |
1215 | 1215 | /// assert_eq!(*static_ref, 42); |
1216 | + /// # // FIXME(https://github.com/rust-lang/miri/issues/3670): | |
1217 | + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. | |
1218 | + /// # drop(unsafe { Box::from_raw(static_ref) }); | |
1216 | 1219 | /// ``` |
1217 | 1220 | /// |
1218 | 1221 | /// Unsized data: |
@@ -1222,6 +1225,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> { | ||
1222 | 1225 | /// let static_ref = Box::leak(x); |
1223 | 1226 | /// static_ref[0] = 4; |
1224 | 1227 | /// assert_eq!(*static_ref, [4, 2, 3]); |
1228 | + /// # // FIXME(https://github.com/rust-lang/miri/issues/3670): | |
1229 | + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. | |
1230 | + /// # drop(unsafe { Box::from_raw(static_ref) }); | |
1225 | 1231 | /// ``` |
1226 | 1232 | #[stable(feature = "box_leak", since = "1.26.0")] |
1227 | 1233 | #[inline] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1984,6 +1984,9 @@ impl String { | ||
1984 | 1984 | /// let x = String::from("bucket"); |
1985 | 1985 | /// let static_ref: &'static mut str = x.leak(); |
1986 | 1986 | /// assert_eq!(static_ref, "bucket"); |
1987 | + /// # // FIXME(https://github.com/rust-lang/miri/issues/3670): | |
1988 | + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. | |
1989 | + /// # drop(unsafe { Box::from_raw(static_ref) }); | |
1987 | 1990 | /// ``` |
1988 | 1991 | #[stable(feature = "string_leak", since = "1.72.0")] |
1989 | 1992 | #[inline] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -120,10 +120,15 @@ impl<T, A: Allocator> IntoIter<T, A> { | ||
120 | 120 | /// This is roughly equivalent to the following, but more efficient |
121 | 121 | /// |
122 | 122 | /// ``` |
123 | - /// # let mut into_iter = Vec::::with_capacity(10).into_iter(); | |
123 | + /// # let mut vec = Vec::::with_capacity(10); | |
124 | + /// # let ptr = vec.as_mut_ptr(); | |
125 | + /// # let mut into_iter = vec.into_iter(); | |
124 | 126 | /// let mut into_iter = std::mem::replace(&mut into_iter, Vec::new().into_iter()); |
125 | 127 | /// (&mut into_iter).for_each(drop); |
126 | 128 | /// std::mem::forget(into_iter); |
129 | + /// # // FIXME(https://github.com/rust-lang/miri/issues/3670): | |
130 | + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. | |
131 | + /// # drop(unsafe { Vec::::from_raw_parts(ptr, 0, 10) }); | |
127 | 132 | /// ``` |
128 | 133 | /// |
129 | 134 | /// This method is used by in-place iteration, refer to the vec::in_place_collect |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1473,6 +1473,9 @@ impl<T, A: Allocator> Vec<T, A> { | ||
1473 | 1473 | /// // 2. `0 <= capacity` always holds whatever `capacity` is. |
1474 | 1474 | /// unsafe { |
1475 | 1475 | /// vec.set_len(0); |
1476 | + /// # // FIXME(https://github.com/rust-lang/miri/issues/3670): | |
1477 | + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. | |
1478 | + /// # vec.set_len(3); | |
1476 | 1479 | /// } |
1477 | 1480 | /// ``` |
1478 | 1481 | /// |
@@ -2391,6 +2394,9 @@ impl<T, A: Allocator> Vec<T, A> { | ||
2391 | 2394 | /// let static_ref: &'static mut [usize] = x.leak(); |
2392 | 2395 | /// static_ref[0] += 1; |
2393 | 2396 | /// assert_eq!(static_ref, &[2, 2, 3]); |
2397 | + /// # // FIXME(https://github.com/rust-lang/miri/issues/3670): | |
2398 | + /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak. | |
2399 | + /// # drop(unsafe { Box::from_raw(static_ref) }); | |
2394 | 2400 | /// ``` |
2395 | 2401 | #[stable(feature = "vec_leak", since = "1.47.0")] |
2396 | 2402 | #[inline] |