Skip to content

Commit a760712

Browse files
committed
Auto merge of rust-lang#149132 - matthiaskrgr:rollup-8khp9s2, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#146925 (Add doc for va_list APIs) - rust-lang#147035 (alloc: fix `Debug` implementation of `ExtractIf`) - rust-lang#147173 (Add support for hexagon-unknown-qurt target) - rust-lang#148261 (rustc_public: Make Id types !Send / !Sync) - rust-lang#149041 (ignore unsized types in mips64 and sparc64 callconvs) - rust-lang#149056 (fix the fragment_in_dst_padding_gets_overwritten test on s390x) - rust-lang#149071 (Add test scaffolding for the `remote-test-client`) - rust-lang#149095 (rustc-dev-guide subtree update) - rust-lang#149108 ([AIX][ppc64le-linux-gnu] Add Amy Kwan to target maintainers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a5cfec7 + 5a42b29 commit a760712

4 files changed

Lines changed: 51 additions & 7 deletions

File tree

alloc/src/vec/extract_if.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,20 @@ where
130130
A: Allocator,
131131
{
132132
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133-
let peek = if self.idx < self.end { self.vec.get(self.idx) } else { None };
133+
let peek = if self.idx < self.end {
134+
// This has to use pointer arithmetic as `self.vec[self.idx]` or
135+
// `self.vec.get_unchecked(self.idx)` wouldn't work since we
136+
// temporarily set the length of `self.vec` to zero.
137+
//
138+
// SAFETY:
139+
// Since `self.idx` is smaller than `self.end` and `self.end` is
140+
// smaller than `self.old_len`, `idx` is valid for indexing the
141+
// buffer. Also, per the invariant of `self.idx`, this element
142+
// has not been inspected/moved out yet.
143+
Some(unsafe { &*self.vec.as_ptr().add(self.idx) })
144+
} else {
145+
None
146+
};
134147
f.debug_struct("ExtractIf").field("peek", &peek).finish_non_exhaustive()
135148
}
136149
}

alloctests/tests/vec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,17 @@ fn extract_if_unconsumed() {
16501650
assert_eq!(vec, [1, 2, 3, 4]);
16511651
}
16521652

1653+
#[test]
1654+
fn extract_if_debug() {
1655+
let mut vec = vec![1, 2];
1656+
let mut drain = vec.extract_if(.., |&mut x| x % 2 != 0);
1657+
assert!(format!("{drain:?}").contains("Some(1)"));
1658+
drain.next();
1659+
assert!(format!("{drain:?}").contains("Some(2)"));
1660+
drain.next();
1661+
assert!(format!("{drain:?}").contains("None"));
1662+
}
1663+
16531664
#[test]
16541665
fn test_reserve_exact() {
16551666
// This is all the same as test_reserve

core/src/ffi/va_list.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ impl<'f> VaListImpl<'f> {
243243
///
244244
/// # Safety
245245
///
246-
/// This function is only sound to call when the next variable argument:
246+
/// This function is only sound to call when:
247247
///
248-
/// - has a type that is ABI-compatible with the type `T`
249-
/// - has a value that is a properly initialized value of type `T`
248+
/// - there is a next variable argument available.
249+
/// - the next argument's type must be ABI-compatible with the type `T`.
250+
/// - the next argument must have a properly initialized value of type `T`.
250251
///
251252
/// Calling this function with an incompatible type, an invalid value, or when there
252253
/// are no more variable arguments, is unsound.

core/src/intrinsics/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,22 +3350,41 @@ pub(crate) const fn miri_promise_symbolic_alignment(ptr: *const (), align: usize
33503350

33513351
/// Copies the current location of arglist `src` to the arglist `dst`.
33523352
///
3353-
/// FIXME: document safety requirements
3353+
/// # Safety
3354+
///
3355+
/// You must check the following invariants before you call this function:
3356+
///
3357+
/// - `dest` must be non-null and point to valid, writable memory.
3358+
/// - `dest` must not alias `src`.
3359+
///
33543360
#[rustc_intrinsic]
33553361
#[rustc_nounwind]
33563362
pub unsafe fn va_copy<'f>(dest: *mut VaListImpl<'f>, src: &VaListImpl<'f>);
33573363

33583364
/// Loads an argument of type `T` from the `va_list` `ap` and increment the
33593365
/// argument `ap` points to.
33603366
///
3361-
/// FIXME: document safety requirements
3367+
/// # Safety
3368+
///
3369+
/// This function is only sound to call when:
3370+
///
3371+
/// - there is a next variable argument available.
3372+
/// - the next argument's type must be ABI-compatible with the type `T`.
3373+
/// - the next argument must have a properly initialized value of type `T`.
3374+
///
3375+
/// Calling this function with an incompatible type, an invalid value, or when there
3376+
/// are no more variable arguments, is unsound.
3377+
///
33623378
#[rustc_intrinsic]
33633379
#[rustc_nounwind]
33643380
pub unsafe fn va_arg<T: VaArgSafe>(ap: &mut VaListImpl<'_>) -> T;
33653381

33663382
/// Destroy the arglist `ap` after initialization with `va_start` or `va_copy`.
33673383
///
3368-
/// FIXME: document safety requirements
3384+
/// # Safety
3385+
///
3386+
/// `ap` must not be used to access variable arguments after this call.
3387+
///
33693388
#[rustc_intrinsic]
33703389
#[rustc_nounwind]
33713390
pub unsafe fn va_end(ap: &mut VaListImpl<'_>);

0 commit comments

Comments
 (0)