Skip to content

Commit c34472b

Browse files
committedNov 8, 2019
Auto merge of #66208 - JohnTitor:rollup-2umgjer, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #65554 (Enhance the documentation of BufReader for potential data loss) - #65580 (Add `MaybeUninit` methods `uninit_array`, `slice_get_ref`, `slice_get_mut`) - #66049 (consistent handling of missing sysroot spans) - #66056 (rustc_metadata: Some reorganization of the module structure) - #66123 (No more hidden elements) - #66157 (Improve math log documentation examples) - #66165 (Ignore these tests ,since the called commands doesn't exist in VxWorks) - #66190 (rustc_target: inline abi::FloatTy into abi::Primitive.) Failed merges: - #66188 (`MethodSig` -> `FnSig` & Use it in `ItemKind::Fn`) r? @ghost
2 parents d257440 + 1969f41 commit c34472b

File tree

110 files changed

+459
-348
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+459
-348
lines changed
 

‎src/etc/generate-deriving-span-tests.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
os.path.join(os.path.dirname(__file__), '../test/ui/derives/'))
1515

1616
TEMPLATE = """\
17-
// ignore-x86
18-
// ^ due to stderr output differences
17+
// ignore-x86 FIXME: missing sysroot spans (#53081)
1918
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
2019
2120
{error_deriving}

‎src/libcore/mem/maybe_uninit.rs

+63
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,43 @@ impl<T> MaybeUninit<T> {
260260
MaybeUninit { uninit: () }
261261
}
262262

263+
/// Create a new array of `MaybeUninit<T>` items, in an uninitialized state.
264+
///
265+
/// Note: in a future Rust version this method may become unnecessary
266+
/// when array literal syntax allows
267+
/// [repeating const expressions](https://github.com/rust-lang/rust/issues/49147).
268+
/// The example below could then use `let mut buf = [MaybeUninit::<u8>::uninit(); 32];`.
269+
///
270+
/// # Examples
271+
///
272+
/// ```no_run
273+
/// #![feature(maybe_uninit_uninit_array, maybe_uninit_extra, maybe_uninit_slice_assume_init)]
274+
///
275+
/// use std::mem::MaybeUninit;
276+
///
277+
/// extern "C" {
278+
/// fn read_into_buffer(ptr: *mut u8, max_len: usize) -> usize;
279+
/// }
280+
///
281+
/// /// Returns a (possibly smaller) slice of data that was actually read
282+
/// fn read(buf: &mut [MaybeUninit<u8>]) -> &[u8] {
283+
/// unsafe {
284+
/// let len = read_into_buffer(buf.as_mut_ptr() as *mut u8, buf.len());
285+
/// MaybeUninit::slice_get_ref(&buf[..len])
286+
/// }
287+
/// }
288+
///
289+
/// let mut buf: [MaybeUninit<u8>; 32] = MaybeUninit::uninit_array();
290+
/// let data = read(&mut buf);
291+
/// ```
292+
#[unstable(feature = "maybe_uninit_uninit_array", issue = "0")]
293+
#[inline(always)]
294+
pub fn uninit_array<const LEN: usize>() -> [Self; LEN] {
295+
unsafe {
296+
MaybeUninit::<[MaybeUninit<T>; LEN]>::uninit().assume_init()
297+
}
298+
}
299+
263300
/// A promotable constant, equivalent to `uninit()`.
264301
#[unstable(feature = "internal_uninit_const", issue = "0",
265302
reason = "hack to work around promotability")]
@@ -692,6 +729,32 @@ impl<T> MaybeUninit<T> {
692729
&mut *self.value
693730
}
694731

732+
/// Assuming all the elements are initialized, get a slice to them.
733+
///
734+
/// # Safety
735+
///
736+
/// It is up to the caller to guarantee that the `MaybeUninit<T>` elements
737+
/// really are in an initialized state.
738+
/// Calling this when the content is not yet fully initialized causes undefined behavior.
739+
#[unstable(feature = "maybe_uninit_slice_assume_init", issue = "0")]
740+
#[inline(always)]
741+
pub unsafe fn slice_get_ref(slice: &[Self]) -> &[T] {
742+
&*(slice as *const [Self] as *const [T])
743+
}
744+
745+
/// Assuming all the elements are initialized, get a mutable slice to them.
746+
///
747+
/// # Safety
748+
///
749+
/// It is up to the caller to guarantee that the `MaybeUninit<T>` elements
750+
/// really are in an initialized state.
751+
/// Calling this when the content is not yet fully initialized causes undefined behavior.
752+
#[unstable(feature = "maybe_uninit_slice_assume_init", issue = "0")]
753+
#[inline(always)]
754+
pub unsafe fn slice_get_mut(slice: &mut [Self]) -> &mut [T] {
755+
&mut *(slice as *mut [Self] as *mut [T])
756+
}
757+
695758
/// Gets a pointer to the first element of the array.
696759
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
697760
#[inline(always)]

0 commit comments

Comments
 (0)
Please sign in to comment.