Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #60986

Merged
merged 25 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67ca448
Improve file sidebar in source code view page on mobile
GuillaumeGomez Apr 29, 2019
87d1c17
Cleanup media queries
GuillaumeGomez Apr 29, 2019
bd8885d
Fall back to `/dev/urandom` on `EPERM` for `getrandom`
tbu- May 1, 2019
e2a2500
Fix search sidebar width when no crate select is present
GuillaumeGomez May 2, 2019
ccb9dac
Fix intra-doc link resolution failure on re-exporting libstd
taiki-e May 4, 2019
2adc6da
Fix incremental compilation of cdylib emitting spurious unused_attrib…
oli-obk May 14, 2019
e92d13e
Update ui tests
oli-obk May 14, 2019
eed1e1e
Remove unused field from StableHasher.
michaelwoerister May 17, 2019
cb0039e
Misc changes to rustc_metadata
bjorn3 May 18, 2019
ea7aa76
Document BinaryHeap time complexity
dtolnay May 19, 2019
88fa5c6
Improve type size assertions
petrochenkov May 19, 2019
b9be68c
remove confusing remarks about mixed volatile and non-volatile accesses
RalfJung May 20, 2019
a79c06a
Document requirements for HashStable implementations better.
michaelwoerister May 17, 2019
d8f764b
Set -funwind-tables and -fno-exceptions unconditionally for LLVM's li…
petrhosek May 20, 2019
daf8aca
Rollup merge of #60383 - GuillaumeGomez:fix-position-source-code-file…
Centril May 20, 2019
5a08ca3
Rollup merge of #60453 - tbu-:pr_getrandom_enoperm, r=sfackler
Centril May 20, 2019
bf54251
Rollup merge of #60487 - GuillaumeGomez:fix-search-sidebar-width-colo…
Centril May 20, 2019
a34dae3
Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPC
Centril May 20, 2019
36b5724
Rollup merge of #60823 - oli-obk:used_unused_no_mangle, r=michaelwoer…
Centril May 20, 2019
3f86fad
Rollup merge of #60915 - michaelwoerister:hashstablestuff, r=estebank
Centril May 20, 2019
65cec43
Rollup merge of #60942 - bjorn3:metadata_loader_refactor, r=michaelwo…
Centril May 20, 2019
864e7a9
Rollup merge of #60952 - dtolnay:heap, r=Amanieu
Centril May 20, 2019
581cf70
Rollup merge of #60959 - petrochenkov:sassert, r=estebank
Centril May 20, 2019
44b5d4d
Rollup merge of #60972 - RalfJung:volatile, r=alexcrichton
Centril May 20, 2019
0c97800
Rollup merge of #60983 - petrhosek:libunwind-no-exceptions, r=alexcri…
Centril May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ extern "Rust" {
///
/// Note: while this type is unstable, the functionality it provides can be
/// accessed through the [free functions in `alloc`](index.html#functions).
///
/// [`Alloc`]: trait.Alloc.html
#[unstable(feature = "allocator_api", issue = "32838")]
#[derive(Copy, Clone, Default, Debug)]
pub struct Global;
Expand All @@ -54,6 +56,10 @@ pub struct Global;
///
/// See [`GlobalAlloc::alloc`].
///
/// [`Global`]: struct.Global.html
/// [`Alloc`]: trait.Alloc.html
/// [`GlobalAlloc::alloc`]: trait.GlobalAlloc.html#tymethod.alloc
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -87,6 +93,10 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
/// # Safety
///
/// See [`GlobalAlloc::dealloc`].
///
/// [`Global`]: struct.Global.html
/// [`Alloc`]: trait.Alloc.html
/// [`GlobalAlloc::dealloc`]: trait.GlobalAlloc.html#tymethod.dealloc
#[stable(feature = "global_alloc", since = "1.28.0")]
#[inline]
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
Expand All @@ -105,6 +115,10 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
/// # Safety
///
/// See [`GlobalAlloc::realloc`].
///
/// [`Global`]: struct.Global.html
/// [`Alloc`]: trait.Alloc.html
/// [`GlobalAlloc::realloc`]: trait.GlobalAlloc.html#method.realloc
#[stable(feature = "global_alloc", since = "1.28.0")]
#[inline]
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
Expand All @@ -124,6 +138,10 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
///
/// See [`GlobalAlloc::alloc_zeroed`].
///
/// [`Global`]: struct.Global.html
/// [`Alloc`]: trait.Alloc.html
/// [`GlobalAlloc::alloc_zeroed`]: trait.GlobalAlloc.html#method.alloc_zeroed
///
/// # Examples
///
/// ```
Expand Down
43 changes: 43 additions & 0 deletions src/liballoc/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ use super::SpecExtend;
/// assert_eq!(heap.pop(), Some(Reverse(5)));
/// assert_eq!(heap.pop(), None);
/// ```
///
/// # Time complexity
///
/// | [push] | [pop] | [peek]/[peek\_mut] |
/// |--------|----------|--------------------|
/// | O(1)~ | O(log n) | O(1) |
///
/// The value for `push` is an expected cost; the method documentation gives a
/// more detailed analysis.
///
/// [push]: #method.push
/// [pop]: #method.pop
/// [peek]: #method.peek
/// [peek\_mut]: #method.peek_mut
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BinaryHeap<T> {
data: Vec<T>,
Expand Down Expand Up @@ -384,6 +398,10 @@ impl<T: Ord> BinaryHeap<T> {
/// }
/// assert_eq!(heap.peek(), Some(&2));
/// ```
///
/// # Time complexity
///
/// Cost is O(1) in the worst case.
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
if self.is_empty() {
Expand Down Expand Up @@ -411,6 +429,11 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.pop(), Some(1));
/// assert_eq!(heap.pop(), None);
/// ```
///
/// # Time complexity
///
/// The worst case cost of `pop` on a heap containing *n* elements is O(log
/// n).
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> Option<T> {
self.data.pop().map(|mut item| {
Expand Down Expand Up @@ -438,6 +461,22 @@ impl<T: Ord> BinaryHeap<T> {
/// assert_eq!(heap.len(), 3);
/// assert_eq!(heap.peek(), Some(&5));
/// ```
///
/// # Time complexity
///
/// The expected cost of `push`, averaged over every possible ordering of
/// the elements being pushed, and over a sufficiently large number of
/// pushes, is O(1). This is the most meaningful cost metric when pushing
/// elements that are *not* already in any sorted pattern.
///
/// The time complexity degrades if elements are pushed in predominantly
/// ascending order. In the worst case, elements are pushed in ascending
/// sorted order and the amortized cost per push is O(log n) against a heap
/// containing *n* elements.
///
/// The worst case cost of a *single* call to `push` is O(n). The worst case
/// occurs when capacity is exhausted and needs a resize. The resize cost
/// has been amortized in the previous figures.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push(&mut self, item: T) {
let old_len = self.len();
Expand Down Expand Up @@ -650,6 +689,10 @@ impl<T> BinaryHeap<T> {
/// assert_eq!(heap.peek(), Some(&5));
///
/// ```
///
/// # Time complexity
///
/// Cost is O(1) in the worst case.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn peek(&self) -> Option<&T> {
self.data.get(0)
Expand Down
6 changes: 0 additions & 6 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,6 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
/// to not be elided or reordered by the compiler across other volatile
/// operations.
///
/// Memory accessed with `read_volatile` or [`write_volatile`] should not be
/// accessed with non-volatile operations.
///
/// [`write_volatile`]: ./fn.write_volatile.html
///
/// # Notes
Expand Down Expand Up @@ -881,9 +878,6 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
/// to not be elided or reordered by the compiler across other volatile
/// operations.
///
/// Memory accessed with [`read_volatile`] or `write_volatile` should not be
/// accessed with non-volatile operations.
///
/// `write_volatile` does not drop the contents of `dst`. This is safe, but it
/// could leak allocations or resources, so care should be taken not to overwrite
/// an object that should be dropped.
Expand Down
23 changes: 23 additions & 0 deletions src/libcore/task/wake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::marker::{PhantomData, Unpin};
///
/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable] that
/// customizes the behavior of the `RawWaker`.
///
/// [`Waker`]: struct.Waker.html
#[derive(PartialEq, Debug)]
#[stable(feature = "futures_api", since = "1.36.0")]
pub struct RawWaker {
Expand Down Expand Up @@ -55,6 +57,8 @@ impl RawWaker {
/// pointer of a properly constructed [`RawWaker`] object from inside the
/// [`RawWaker`] implementation. Calling one of the contained functions using
/// any other `data` pointer will cause undefined behavior.
///
/// [`RawWaker`]: struct.RawWaker.html
#[stable(feature = "futures_api", since = "1.36.0")]
#[derive(PartialEq, Copy, Clone, Debug)]
pub struct RawWakerVTable {
Expand All @@ -65,6 +69,9 @@ pub struct RawWakerVTable {
/// required for this additional instance of a [`RawWaker`] and associated
/// task. Calling `wake` on the resulting [`RawWaker`] should result in a wakeup
/// of the same task that would have been awoken by the original [`RawWaker`].
///
/// [`Waker`]: struct.Waker.html
/// [`RawWaker`]: struct.RawWaker.html
clone: unsafe fn(*const ()) -> RawWaker,

/// This function will be called when `wake` is called on the [`Waker`].
Expand All @@ -73,20 +80,28 @@ pub struct RawWakerVTable {
/// The implementation of this function must make sure to release any
/// resources that are associated with this instance of a [`RawWaker`] and
/// associated task.
///
/// [`Waker`]: struct.Waker.html
/// [`RawWaker`]: struct.RawWaker.html
wake: unsafe fn(*const ()),

/// This function will be called when `wake_by_ref` is called on the [`Waker`].
/// It must wake up the task associated with this [`RawWaker`].
///
/// This function is similar to `wake`, but must not consume the provided data
/// pointer.
///
/// [`Waker`]: struct.Waker.html
/// [`RawWaker`]: struct.RawWaker.html
wake_by_ref: unsafe fn(*const ()),

/// This function gets called when a [`RawWaker`] gets dropped.
///
/// The implementation of this function must make sure to release any
/// resources that are associated with this instance of a [`RawWaker`] and
/// associated task.
///
/// [`RawWaker`]: struct.RawWaker.html
drop: unsafe fn(*const ()),
}

Expand Down Expand Up @@ -128,6 +143,9 @@ impl RawWakerVTable {
/// The implementation of this function must make sure to release any
/// resources that are associated with this instance of a [`RawWaker`] and
/// associated task.
///
/// [`Waker`]: struct.Waker.html
/// [`RawWaker`]: struct.RawWaker.html
#[rustc_promotable]
#[cfg_attr(stage0, unstable(feature = "futures_api_const_fn_ptr", issue = "50547"))]
#[cfg_attr(not(stage0), stable(feature = "futures_api", since = "1.36.0"))]
Expand Down Expand Up @@ -201,6 +219,8 @@ impl fmt::Debug for Context<'_> {
/// executor-specific wakeup behavior.
///
/// Implements [`Clone`], [`Send`], and [`Sync`].
///
/// [`RawWaker`]: struct.RawWaker.html
#[repr(transparent)]
#[stable(feature = "futures_api", since = "1.36.0")]
pub struct Waker {
Expand Down Expand Up @@ -266,6 +286,9 @@ impl Waker {
/// The behavior of the returned `Waker` is undefined if the contract defined
/// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
/// Therefore this method is unsafe.
///
/// [`RawWaker`]: struct.RawWaker.html
/// [`RawWakerVTable`]: struct.RawWakerVTable.html
#[inline]
#[stable(feature = "futures_api", since = "1.36.0")]
pub unsafe fn from_raw(waker: RawWaker) -> Waker {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ pub struct Expr {

// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert!(MEM_SIZE_OF_EXPR: std::mem::size_of::<Expr>() == 72);
static_assert_size!(Expr, 72);

impl Expr {
pub fn precedence(&self) -> ExprPrecedence {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ newtype_index! {
impl_stable_hash_for!(struct crate::middle::region::FirstStatementIndex { private });

// compilation error if size of `ScopeData` is not the same as a `u32`
static_assert!(ASSERT_SCOPE_DATA: mem::size_of::<ScopeData>() == 4);
static_assert_size!(ScopeData, 4);

impl Scope {
/// Returns a item-local ID associated with this scope.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct Pointer<Tag=(),Id=AllocId> {
pub tag: Tag,
}

static_assert!(POINTER_SIZE: ::std::mem::size_of::<Pointer>() == 16);
static_assert_size!(Pointer, 16);

/// Produces a `Pointer` which points to the beginning of the Allocation
impl From<AllocId> for Pointer {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum ConstValue<'tcx> {
}

#[cfg(target_arch = "x86_64")]
static_assert!(CONST_SIZE: ::std::mem::size_of::<ConstValue<'static>>() == 40);
static_assert_size!(ConstValue<'_>, 40);

impl<'tcx> ConstValue<'tcx> {
#[inline]
Expand Down Expand Up @@ -111,7 +111,7 @@ pub enum Scalar<Tag=(), Id=AllocId> {
}

#[cfg(target_arch = "x86_64")]
static_assert!(SCALAR_SIZE: ::std::mem::size_of::<Scalar>() == 24);
static_assert_size!(Scalar, 24);

impl<Tag> fmt::Display for Scalar<Tag> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,7 @@ pub struct Statement<'tcx> {

// `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 56);
static_assert_size!(Statement<'_>, 56);

impl<'tcx> Statement<'tcx> {
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
Expand Down Expand Up @@ -1997,10 +1997,9 @@ pub type PlaceProjection<'tcx> = Projection<Place<'tcx>, Local, Ty<'tcx>>;
/// and the index is a local.
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;

// at least on 64 bit systems, `PlaceElem` should not be larger than two pointers
static_assert!(PROJECTION_ELEM_IS_2_PTRS_LARGE:
mem::size_of::<PlaceElem<'_>>() <= 16
);
// At least on 64 bit systems, `PlaceElem` should not be larger than two pointers.
#[cfg(target_arch = "x86_64")]
static_assert_size!(PlaceElem<'_>, 16);

/// Alias for projections as they appear in `UserTypeProjection`, where we
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub struct PlaceTy<'tcx> {
pub variant_index: Option<VariantIdx>,
}

static_assert!(PLACE_TY_IS_3_PTRS_LARGE:
mem::size_of::<PlaceTy<'_>>() <= 24
);
// At least on 64 bit systems, `PlaceTy` should not be larger than two or three pointers.
#[cfg(target_arch = "x86_64")]
static_assert_size!(PlaceTy<'_>, 16);

impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ pub struct TyS<'tcx> {

// `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert!(MEM_SIZE_OF_TY_S: ::std::mem::size_of::<TyS<'_>>() == 32);
static_assert_size!(TyS<'_>, 32);

impl<'tcx> Ord for TyS<'tcx> {
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub enum TyKind<'tcx> {

// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")]
static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::<TyKind<'_>>() == 24);
static_assert_size!(TyKind<'_>, 24);

/// A closure can be modeled as a struct that looks like:
///
Expand Down Expand Up @@ -2207,7 +2207,7 @@ pub struct Const<'tcx> {
}

#[cfg(target_arch = "x86_64")]
static_assert!(CONST_SIZE: ::std::mem::size_of::<Const<'static>>() == 48);
static_assert_size!(Const<'_>, 48);

impl<'tcx> Const<'tcx> {
#[inline]
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ macro_rules! static_assert {
static $name: () = [()][!($test: bool) as usize];
}
}

/// Type size assertion. The first argument is a type and the second argument is its expected size.
#[macro_export]
#[allow_internal_unstable(underscore_const_names)]
macro_rules! static_assert_size {
($ty:ty, $size:expr) => {
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
}
}
Loading