Skip to content

Commit

Permalink
Auto merge of #74330 - Manishearth:rollup-mrc09pb, r=Manishearth
Browse files Browse the repository at this point in the history
Rollup of 15 pull requests

Successful merges:

 - #71237 (Add Ayu theme to rustdoc)
 - #73720 (Clean up E0704 error explanation)
 - #73866 (Obviate #[allow(improper_ctypes_definitions)])
 - #73965 (typeck: check for infer before type impls trait)
 - #73986 (add (unchecked) indexing methods to raw (and NonNull) slices)
 - #74173 (Detect tuple struct incorrectly used as struct pat)
 - #74220 (Refactor Windows `parse_prefix`)
 - #74227 (Remove an unwrap in layout computation)
 - #74239 (Update llvm-project to latest origin/rustc/10.0-2020-05-05 commit )
 - #74257 (don't mark linux kernel module targets as a unix environment)
 - #74270 (typeck: report placeholder type error w/out span)
 - #74296 (Clarify the description for rfind)
 - #74310 (Use `ArrayVec` in `SparseBitSet`.)
 - #74316 (Remove unnecessary type hints from Wake internals)
 - #74324 (Update Clippy)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jul 14, 2020
2 parents c724b67 + 5414eae commit 2002eba
Show file tree
Hide file tree
Showing 186 changed files with 5,650 additions and 1,466 deletions.
13 changes: 10 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ dependencies = [
"nodrop",
]

[[package]]
name = "arrayvec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"

[[package]]
name = "atty"
version = "0.2.14"
Expand Down Expand Up @@ -164,7 +170,7 @@ version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400"
dependencies = [
"arrayvec",
"arrayvec 0.4.7",
"constant_time_eq",
]

Expand Down Expand Up @@ -714,7 +720,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
dependencies = [
"arrayvec",
"arrayvec 0.4.7",
"cfg-if",
"crossbeam-utils 0.6.5",
"lazy_static",
Expand Down Expand Up @@ -3494,8 +3500,8 @@ dependencies = [
name = "rustc_index"
version = "0.0.0"
dependencies = [
"arrayvec 0.5.1",
"rustc_serialize",
"smallvec 1.4.0",
]

[[package]]
Expand Down Expand Up @@ -3996,6 +4002,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_hir",
"rustc_hir_pretty",
"rustc_index",
"rustc_infer",
"rustc_middle",
Expand Down
5 changes: 2 additions & 3 deletions src/liballoc/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {

// Wake by value, moving the Arc into the Wake::wake function
unsafe fn wake<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: Arc<W> = unsafe { Arc::from_raw(waker as *const W) };
let waker = unsafe { Arc::from_raw(waker as *const W) };
<W as Wake>::wake(waker);
}

// Wake by reference, wrap the waker in ManuallyDrop to avoid dropping it
unsafe fn wake_by_ref<W: Wake + Send + Sync + 'static>(waker: *const ()) {
let waker: ManuallyDrop<Arc<W>> =
unsafe { ManuallyDrop::new(Arc::from_raw(waker as *const W)) };
let waker = unsafe { ManuallyDrop::new(Arc::from_raw(waker as *const W)) };
<W as Wake>::wake_by_ref(&waker);
}

Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
#![feature(associated_type_bounds)]
#![feature(const_type_id)]
#![feature(const_caller_location)]
#![feature(slice_ptr_get)]
#![feature(no_niche)] // rust-lang/rust#68303
#![feature(unsafe_block_in_unsafe_fn)]
#![deny(unsafe_op_in_unsafe_fn)]
Expand Down
50 changes: 50 additions & 0 deletions src/libcore/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
use crate::cmp::Ordering::{self, Equal, Greater, Less};
use crate::intrinsics;
use crate::mem;
use crate::slice::SliceIndex;

#[lang = "const_ptr"]
impl<T: ?Sized> *const T {
Expand Down Expand Up @@ -826,6 +827,55 @@ impl<T> *const [T] {
// Only `std` can make this guarantee.
unsafe { Repr { rust: self }.raw }.len
}

/// Returns a raw pointer to the slice's buffer.
///
/// This is equivalent to casting `self` to `*const T`, but more type-safe.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get)]
/// use std::ptr;
///
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
/// assert_eq!(slice.as_ptr(), 0 as *const i8);
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_ptr(self) -> *const T {
self as *const T
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
/// Calling this method with an out-of-bounds index or when `self` is not dereferencable
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
///
/// # Examples
///
/// ```
/// #![feature(slice_ptr_get)]
///
/// let x = &[1, 2, 4] as *const [i32];
///
/// unsafe {
/// assert_eq!(x.get_unchecked(1), x.as_ptr().add(1));
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[inline]
pub unsafe fn get_unchecked<I>(self, index: I) -> *const I::Output
where
I: SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferencable and `index` in-bounds.
unsafe { index.get_unchecked(self) }
}
}

// Equality for pointers
Expand Down
51 changes: 50 additions & 1 deletion src/libcore/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;
use crate::cmp::Ordering::{self, Equal, Greater, Less};
use crate::intrinsics;
use crate::slice::SliceIndex;

#[lang = "mut_ptr"]
impl<T: ?Sized> *mut T {
Expand Down Expand Up @@ -1014,7 +1015,6 @@ impl<T> *mut [T] {
///
/// ```rust
/// #![feature(slice_ptr_len)]
///
/// use std::ptr;
///
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
Expand All @@ -1028,6 +1028,55 @@ impl<T> *mut [T] {
// Only `std` can make this guarantee.
unsafe { Repr { rust_mut: self }.raw }.len
}

/// Returns a raw pointer to the slice's buffer.
///
/// This is equivalent to casting `self` to `*mut T`, but more type-safe.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get)]
/// use std::ptr;
///
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
/// assert_eq!(slice.as_mut_ptr(), 0 as *mut i8);
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_mut_ptr(self) -> *mut T {
self as *mut T
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
/// Calling this method with an out-of-bounds index or when `self` is not dereferencable
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
///
/// # Examples
///
/// ```
/// #![feature(slice_ptr_get)]
///
/// let x = &mut [1, 2, 4] as *mut [i32];
///
/// unsafe {
/// assert_eq!(x.get_unchecked_mut(1), x.as_mut_ptr().add(1));
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[inline]
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> *mut I::Output
where
I: SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferencable and `index` in-bounds.
unsafe { index.get_unchecked_mut(self) }
}
}

// Equality for pointers
Expand Down
53 changes: 52 additions & 1 deletion src/libcore/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::marker::Unsize;
use crate::mem;
use crate::ops::{CoerceUnsized, DispatchFromDyn};
use crate::ptr::Unique;
use crate::slice::SliceIndex;

/// `*mut T` but non-zero and covariant.
///
Expand Down Expand Up @@ -192,7 +193,6 @@ impl<T> NonNull<[T]> {
///
/// ```rust
/// #![feature(slice_ptr_len, nonnull_slice_from_raw_parts)]
///
/// use std::ptr::NonNull;
///
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
Expand All @@ -204,6 +204,57 @@ impl<T> NonNull<[T]> {
pub const fn len(self) -> usize {
self.as_ptr().len()
}

/// Returns a non-null pointer to the slice's buffer.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)]
/// use std::ptr::NonNull;
///
/// let slice: NonNull<[i8]> = NonNull::slice_from_raw_parts(NonNull::dangling(), 3);
/// assert_eq!(slice.as_non_null_ptr(), NonNull::new(1 as *mut i8).unwrap());
/// ```
#[inline]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_non_null_ptr(self) -> NonNull<T> {
// SAFETY: We know `self` is non-null.
unsafe { NonNull::new_unchecked(self.as_ptr().as_mut_ptr()) }
}

/// Returns a raw pointer to an element or subslice, without doing bounds
/// checking.
///
/// Calling this method with an out-of-bounds index or when `self` is not dereferencable
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
///
/// # Examples
///
/// ```
/// #![feature(slice_ptr_get, nonnull_slice_from_raw_parts)]
/// use std::ptr::NonNull;
///
/// let x = &mut [1, 2, 4];
/// let x = NonNull::slice_from_raw_parts(NonNull::new(x.as_mut_ptr()).unwrap(), x.len());
///
/// unsafe {
/// assert_eq!(x.get_unchecked_mut(1).as_ptr(), x.as_non_null_ptr().as_ptr().add(1));
/// }
/// ```
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[inline]
pub unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
where
I: SliceIndex<[T]>,
{
// SAFETY: the caller ensures that `self` is dereferencable and `index` in-bounds.
// As a consequence, the resulting pointer cannot be NULL.
unsafe { NonNull::new_unchecked(self.as_ptr().get_unchecked_mut(index)) }
}
}

#[stable(feature = "nonnull", since = "1.25.0")]
Expand Down
Loading

0 comments on commit 2002eba

Please sign in to comment.