Skip to content

Commit 4cd8dc6

Browse files
committed
Auto merge of rust-lang#127705 - workingjubilee:rollup-sjlzycu, r=workingjubilee
Rollup of 3 pull requests Successful merges: - rust-lang#127370 (Windows: Add experimental support for linking std-required system DLLs using raw-dylib) - rust-lang#127446 (Remove memory leaks in doctests in `core`, `alloc`, and `std`) - rust-lang#127677 (using correct tool mode for `run-make-support` crate) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00167ab + 9201f18 commit 4cd8dc6

File tree

17 files changed

+145
-75
lines changed

17 files changed

+145
-75
lines changed

library/alloc/src/boxed.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12131213
/// let static_ref: &'static mut usize = Box::leak(x);
12141214
/// *static_ref += 1;
12151215
/// 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) });
12161219
/// ```
12171220
///
12181221
/// Unsized data:
@@ -1222,6 +1225,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12221225
/// let static_ref = Box::leak(x);
12231226
/// static_ref[0] = 4;
12241227
/// 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) });
12251231
/// ```
12261232
#[stable(feature = "box_leak", since = "1.26.0")]
12271233
#[inline]

library/alloc/src/rc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,8 @@ impl<T: ?Sized> Rc<T> {
12771277
///
12781278
/// let five = Rc::from_raw(ptr);
12791279
/// assert_eq!(2, Rc::strong_count(&five));
1280+
/// # // Prevent leaks for Miri.
1281+
/// # Rc::decrement_strong_count(ptr);
12801282
/// }
12811283
/// ```
12821284
#[inline]
@@ -1345,6 +1347,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13451347
/// let x = Rc::new("hello".to_owned());
13461348
/// let x_ptr = Rc::into_raw(x);
13471349
/// assert_eq!(unsafe { &*x_ptr }, "hello");
1350+
/// # // Prevent leaks for Miri.
1351+
/// # drop(unsafe { Rc::from_raw(x_ptr) });
13481352
/// ```
13491353
#[must_use = "losing the pointer will leak memory"]
13501354
#[stable(feature = "rc_raw", since = "1.17.0")]
@@ -1572,6 +1576,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
15721576
///
15731577
/// let five = Rc::from_raw_in(ptr, System);
15741578
/// assert_eq!(2, Rc::strong_count(&five));
1579+
/// # // Prevent leaks for Miri.
1580+
/// # Rc::decrement_strong_count_in(ptr, System);
15751581
/// }
15761582
/// ```
15771583
#[inline]

library/alloc/src/string.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,9 @@ impl String {
19841984
/// let x = String::from("bucket");
19851985
/// let static_ref: &'static mut str = x.leak();
19861986
/// 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) });
19871990
/// ```
19881991
#[stable(feature = "string_leak", since = "1.72.0")]
19891992
#[inline]

library/alloc/src/sync.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,8 @@ impl<T: ?Sized> Arc<T> {
14141414
/// // the `Arc` between threads.
14151415
/// let five = Arc::from_raw(ptr);
14161416
/// assert_eq!(2, Arc::strong_count(&five));
1417+
/// # // Prevent leaks for Miri.
1418+
/// # Arc::decrement_strong_count(ptr);
14171419
/// }
14181420
/// ```
14191421
#[inline]
@@ -1484,6 +1486,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
14841486
/// let x = Arc::new("hello".to_owned());
14851487
/// let x_ptr = Arc::into_raw(x);
14861488
/// assert_eq!(unsafe { &*x_ptr }, "hello");
1489+
/// # // Prevent leaks for Miri.
1490+
/// # drop(unsafe { Arc::from_raw(x_ptr) });
14871491
/// ```
14881492
#[must_use = "losing the pointer will leak memory"]
14891493
#[stable(feature = "rc_raw", since = "1.17.0")]
@@ -1766,6 +1770,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
17661770
/// // the `Arc` between threads.
17671771
/// let five = Arc::from_raw_in(ptr, System);
17681772
/// assert_eq!(2, Arc::strong_count(&five));
1773+
/// # // Prevent leaks for Miri.
1774+
/// # Arc::decrement_strong_count_in(ptr, System);
17691775
/// }
17701776
/// ```
17711777
#[inline]

library/alloc/src/vec/into_iter.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ impl<T, A: Allocator> IntoIter<T, A> {
120120
/// This is roughly equivalent to the following, but more efficient
121121
///
122122
/// ```
123-
/// # let mut into_iter = Vec::<u8>::with_capacity(10).into_iter();
123+
/// # let mut vec = Vec::<u8>::with_capacity(10);
124+
/// # let ptr = vec.as_mut_ptr();
125+
/// # let mut into_iter = vec.into_iter();
124126
/// let mut into_iter = std::mem::replace(&mut into_iter, Vec::new().into_iter());
125127
/// (&mut into_iter).for_each(drop);
126128
/// 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::<u8>::from_raw_parts(ptr, 0, 10) });
127132
/// ```
128133
///
129134
/// This method is used by in-place iteration, refer to the vec::in_place_collect

library/alloc/src/vec/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,9 @@ impl<T, A: Allocator> Vec<T, A> {
14731473
/// // 2. `0 <= capacity` always holds whatever `capacity` is.
14741474
/// unsafe {
14751475
/// 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);
14761479
/// }
14771480
/// ```
14781481
///
@@ -2391,6 +2394,9 @@ impl<T, A: Allocator> Vec<T, A> {
23912394
/// let static_ref: &'static mut [usize] = x.leak();
23922395
/// static_ref[0] += 1;
23932396
/// 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) });
23942400
/// ```
23952401
#[stable(feature = "vec_leak", since = "1.47.0")]
23962402
#[inline]

library/core/src/mem/manually_drop.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ impl<T> ManuallyDrop<T> {
6262
/// x.truncate(5); // You can still safely operate on the value
6363
/// assert_eq!(*x, "Hello");
6464
/// // But `Drop` will not be run here
65+
/// # // FIXME(https://github.com/rust-lang/miri/issues/3670):
66+
/// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
67+
/// # let _ = ManuallyDrop::into_inner(x);
6568
/// ```
6669
#[must_use = "if you don't need the wrapper, you can use `mem::forget` instead"]
6770
#[stable(feature = "manually_drop", since = "1.20.0")]

library/core/src/mem/maybe_uninit.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ impl<T> MaybeUninit<T> {
274274
/// use std::mem::MaybeUninit;
275275
///
276276
/// let v: MaybeUninit<Vec<u8>> = MaybeUninit::new(vec![42]);
277+
/// # // Prevent leaks for Miri
278+
/// # unsafe { let _ = MaybeUninit::assume_init(v); }
277279
/// ```
278280
///
279281
/// [`assume_init`]: MaybeUninit::assume_init
@@ -446,6 +448,9 @@ impl<T> MaybeUninit<T> {
446448
/// let mut x = MaybeUninit::<String>::uninit();
447449
///
448450
/// x.write("Hello".to_string());
451+
/// # // FIXME(https://github.com/rust-lang/miri/issues/3670):
452+
/// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
453+
/// # unsafe { MaybeUninit::assume_init_drop(&mut x); }
449454
/// // This leaks the contained string:
450455
/// x.write("hello".to_string());
451456
/// // x is initialized now:
@@ -506,6 +511,8 @@ impl<T> MaybeUninit<T> {
506511
/// // Create a reference into the `MaybeUninit<T>`. This is okay because we initialized it.
507512
/// let x_vec = unsafe { &*x.as_ptr() };
508513
/// assert_eq!(x_vec.len(), 3);
514+
/// # // Prevent leaks for Miri
515+
/// # unsafe { MaybeUninit::assume_init_drop(&mut x); }
509516
/// ```
510517
///
511518
/// *Incorrect* usage of this method:
@@ -545,6 +552,8 @@ impl<T> MaybeUninit<T> {
545552
/// let x_vec = unsafe { &mut *x.as_mut_ptr() };
546553
/// x_vec.push(3);
547554
/// assert_eq!(x_vec.len(), 4);
555+
/// # // Prevent leaks for Miri
556+
/// # unsafe { MaybeUninit::assume_init_drop(&mut x); }
548557
/// ```
549558
///
550559
/// *Incorrect* usage of this method:
@@ -746,6 +755,8 @@ impl<T> MaybeUninit<T> {
746755
/// use std::mem::MaybeUninit;
747756
///
748757
/// let mut x = MaybeUninit::<Vec<u32>>::uninit();
758+
/// # let mut x_mu = x;
759+
/// # let mut x = &mut x_mu;
749760
/// // Initialize `x`:
750761
/// x.write(vec![1, 2, 3]);
751762
/// // Now that our `MaybeUninit<_>` is known to be initialized, it is okay to
@@ -755,6 +766,8 @@ impl<T> MaybeUninit<T> {
755766
/// x.assume_init_ref()
756767
/// };
757768
/// assert_eq!(x, &vec![1, 2, 3]);
769+
/// # // Prevent leaks for Miri
770+
/// # unsafe { MaybeUninit::assume_init_drop(&mut x_mu); }
758771
/// ```
759772
///
760773
/// ### *Incorrect* usages of this method:
@@ -1088,6 +1101,8 @@ impl<T> MaybeUninit<T> {
10881101
/// let init = MaybeUninit::clone_from_slice(&mut dst, &src);
10891102
///
10901103
/// assert_eq!(init, src);
1104+
/// # // Prevent leaks for Miri
1105+
/// # unsafe { std::ptr::drop_in_place(init); }
10911106
/// ```
10921107
///
10931108
/// ```

library/core/src/ptr/non_null.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,8 @@ impl<T> NonNull<[T]> {
16631663
/// // Note that calling `memory.as_mut()` is not allowed here as the content may be uninitialized.
16641664
/// # #[allow(unused_variables)]
16651665
/// let slice: &mut [MaybeUninit<u8>] = unsafe { memory.as_uninit_slice_mut() };
1666+
/// # // Prevent leaks for Miri.
1667+
/// # unsafe { Global.deallocate(memory.cast(), Layout::new::<[u8; 32]>()); }
16661668
/// # Ok::<_, std::alloc::AllocError>(())
16671669
/// ```
16681670
#[inline]

library/std/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ std_detect_file_io = ["std_detect/std_detect_file_io"]
8787
std_detect_dlsym_getauxval = ["std_detect/std_detect_dlsym_getauxval"]
8888
std_detect_env_override = ["std_detect/std_detect_env_override"]
8989

90+
# Enable using raw-dylib for Windows imports.
91+
# This will eventually be the default.
92+
windows_raw_dylib = []
93+
9094
[package.metadata.fortanix-sgx]
9195
# Maximum possible number of threads when testing
9296
threads = 125

0 commit comments

Comments
 (0)