Skip to content

Commit 0918959

Browse files
committed
Auto merge of #60986 - Centril:rollup-nhpgrfb, r=Centril
Rollup of 11 pull requests Successful merges: - #60383 (Fix position source code files toggle) - #60453 (Fall back to `/dev/urandom` on `EPERM` for `getrandom`) - #60487 (Fix search sidebar width when no crate select is present) - #60511 (Fix intra-doc link resolution failure on re-exporting libstd) - #60823 (Fix incremental compilation of cdylib emitting spurious unused_attributes lint) - #60915 (stable hashing: Remove unused field and add documentation.) - #60942 (Misc changes to rustc_metadata) - #60952 (Document BinaryHeap time complexity) - #60959 (rustc: Improve type size assertions) - #60972 (remove confusing remarks about mixed volatile and non-volatile accesses) - #60983 (Set -funwind-tables and -fno-exceptions unconditionally for LLVM's libunwind) Failed merges: r? @ghost
2 parents d35181a + 0c97800 commit 0918959

File tree

39 files changed

+441
-287
lines changed

39 files changed

+441
-287
lines changed

src/liballoc/alloc.rs

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern "Rust" {
3737
///
3838
/// Note: while this type is unstable, the functionality it provides can be
3939
/// accessed through the [free functions in `alloc`](index.html#functions).
40+
///
41+
/// [`Alloc`]: trait.Alloc.html
4042
#[unstable(feature = "allocator_api", issue = "32838")]
4143
#[derive(Copy, Clone, Default, Debug)]
4244
pub struct Global;
@@ -54,6 +56,10 @@ pub struct Global;
5456
///
5557
/// See [`GlobalAlloc::alloc`].
5658
///
59+
/// [`Global`]: struct.Global.html
60+
/// [`Alloc`]: trait.Alloc.html
61+
/// [`GlobalAlloc::alloc`]: trait.GlobalAlloc.html#tymethod.alloc
62+
///
5763
/// # Examples
5864
///
5965
/// ```
@@ -87,6 +93,10 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
8793
/// # Safety
8894
///
8995
/// See [`GlobalAlloc::dealloc`].
96+
///
97+
/// [`Global`]: struct.Global.html
98+
/// [`Alloc`]: trait.Alloc.html
99+
/// [`GlobalAlloc::dealloc`]: trait.GlobalAlloc.html#tymethod.dealloc
90100
#[stable(feature = "global_alloc", since = "1.28.0")]
91101
#[inline]
92102
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
@@ -105,6 +115,10 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
105115
/// # Safety
106116
///
107117
/// See [`GlobalAlloc::realloc`].
118+
///
119+
/// [`Global`]: struct.Global.html
120+
/// [`Alloc`]: trait.Alloc.html
121+
/// [`GlobalAlloc::realloc`]: trait.GlobalAlloc.html#method.realloc
108122
#[stable(feature = "global_alloc", since = "1.28.0")]
109123
#[inline]
110124
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
@@ -124,6 +138,10 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
124138
///
125139
/// See [`GlobalAlloc::alloc_zeroed`].
126140
///
141+
/// [`Global`]: struct.Global.html
142+
/// [`Alloc`]: trait.Alloc.html
143+
/// [`GlobalAlloc::alloc_zeroed`]: trait.GlobalAlloc.html#method.alloc_zeroed
144+
///
127145
/// # Examples
128146
///
129147
/// ```

src/liballoc/collections/binary_heap.rs

+43
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ use super::SpecExtend;
231231
/// assert_eq!(heap.pop(), Some(Reverse(5)));
232232
/// assert_eq!(heap.pop(), None);
233233
/// ```
234+
///
235+
/// # Time complexity
236+
///
237+
/// | [push] | [pop] | [peek]/[peek\_mut] |
238+
/// |--------|----------|--------------------|
239+
/// | O(1)~ | O(log n) | O(1) |
240+
///
241+
/// The value for `push` is an expected cost; the method documentation gives a
242+
/// more detailed analysis.
243+
///
244+
/// [push]: #method.push
245+
/// [pop]: #method.pop
246+
/// [peek]: #method.peek
247+
/// [peek\_mut]: #method.peek_mut
234248
#[stable(feature = "rust1", since = "1.0.0")]
235249
pub struct BinaryHeap<T> {
236250
data: Vec<T>,
@@ -384,6 +398,10 @@ impl<T: Ord> BinaryHeap<T> {
384398
/// }
385399
/// assert_eq!(heap.peek(), Some(&2));
386400
/// ```
401+
///
402+
/// # Time complexity
403+
///
404+
/// Cost is O(1) in the worst case.
387405
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
388406
pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
389407
if self.is_empty() {
@@ -411,6 +429,11 @@ impl<T: Ord> BinaryHeap<T> {
411429
/// assert_eq!(heap.pop(), Some(1));
412430
/// assert_eq!(heap.pop(), None);
413431
/// ```
432+
///
433+
/// # Time complexity
434+
///
435+
/// The worst case cost of `pop` on a heap containing *n* elements is O(log
436+
/// n).
414437
#[stable(feature = "rust1", since = "1.0.0")]
415438
pub fn pop(&mut self) -> Option<T> {
416439
self.data.pop().map(|mut item| {
@@ -438,6 +461,22 @@ impl<T: Ord> BinaryHeap<T> {
438461
/// assert_eq!(heap.len(), 3);
439462
/// assert_eq!(heap.peek(), Some(&5));
440463
/// ```
464+
///
465+
/// # Time complexity
466+
///
467+
/// The expected cost of `push`, averaged over every possible ordering of
468+
/// the elements being pushed, and over a sufficiently large number of
469+
/// pushes, is O(1). This is the most meaningful cost metric when pushing
470+
/// elements that are *not* already in any sorted pattern.
471+
///
472+
/// The time complexity degrades if elements are pushed in predominantly
473+
/// ascending order. In the worst case, elements are pushed in ascending
474+
/// sorted order and the amortized cost per push is O(log n) against a heap
475+
/// containing *n* elements.
476+
///
477+
/// The worst case cost of a *single* call to `push` is O(n). The worst case
478+
/// occurs when capacity is exhausted and needs a resize. The resize cost
479+
/// has been amortized in the previous figures.
441480
#[stable(feature = "rust1", since = "1.0.0")]
442481
pub fn push(&mut self, item: T) {
443482
let old_len = self.len();
@@ -650,6 +689,10 @@ impl<T> BinaryHeap<T> {
650689
/// assert_eq!(heap.peek(), Some(&5));
651690
///
652691
/// ```
692+
///
693+
/// # Time complexity
694+
///
695+
/// Cost is O(1) in the worst case.
653696
#[stable(feature = "rust1", since = "1.0.0")]
654697
pub fn peek(&self) -> Option<&T> {
655698
self.data.get(0)

src/libcore/ptr.rs

-6
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,6 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
810810
/// to not be elided or reordered by the compiler across other volatile
811811
/// operations.
812812
///
813-
/// Memory accessed with `read_volatile` or [`write_volatile`] should not be
814-
/// accessed with non-volatile operations.
815-
///
816813
/// [`write_volatile`]: ./fn.write_volatile.html
817814
///
818815
/// # Notes
@@ -881,9 +878,6 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
881878
/// to not be elided or reordered by the compiler across other volatile
882879
/// operations.
883880
///
884-
/// Memory accessed with [`read_volatile`] or `write_volatile` should not be
885-
/// accessed with non-volatile operations.
886-
///
887881
/// `write_volatile` does not drop the contents of `dst`. This is safe, but it
888882
/// could leak allocations or resources, so care should be taken not to overwrite
889883
/// an object that should be dropped.

src/libcore/task/wake.rs

+23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::marker::{PhantomData, Unpin};
1010
///
1111
/// It consists of a data pointer and a [virtual function pointer table (vtable)][vtable] that
1212
/// customizes the behavior of the `RawWaker`.
13+
///
14+
/// [`Waker`]: struct.Waker.html
1315
#[derive(PartialEq, Debug)]
1416
#[stable(feature = "futures_api", since = "1.36.0")]
1517
pub struct RawWaker {
@@ -55,6 +57,8 @@ impl RawWaker {
5557
/// pointer of a properly constructed [`RawWaker`] object from inside the
5658
/// [`RawWaker`] implementation. Calling one of the contained functions using
5759
/// any other `data` pointer will cause undefined behavior.
60+
///
61+
/// [`RawWaker`]: struct.RawWaker.html
5862
#[stable(feature = "futures_api", since = "1.36.0")]
5963
#[derive(PartialEq, Copy, Clone, Debug)]
6064
pub struct RawWakerVTable {
@@ -65,6 +69,9 @@ pub struct RawWakerVTable {
6569
/// required for this additional instance of a [`RawWaker`] and associated
6670
/// task. Calling `wake` on the resulting [`RawWaker`] should result in a wakeup
6771
/// of the same task that would have been awoken by the original [`RawWaker`].
72+
///
73+
/// [`Waker`]: struct.Waker.html
74+
/// [`RawWaker`]: struct.RawWaker.html
6875
clone: unsafe fn(*const ()) -> RawWaker,
6976

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

7888
/// This function will be called when `wake_by_ref` is called on the [`Waker`].
7989
/// It must wake up the task associated with this [`RawWaker`].
8090
///
8191
/// This function is similar to `wake`, but must not consume the provided data
8292
/// pointer.
93+
///
94+
/// [`Waker`]: struct.Waker.html
95+
/// [`RawWaker`]: struct.RawWaker.html
8396
wake_by_ref: unsafe fn(*const ()),
8497

8598
/// This function gets called when a [`RawWaker`] gets dropped.
8699
///
87100
/// The implementation of this function must make sure to release any
88101
/// resources that are associated with this instance of a [`RawWaker`] and
89102
/// associated task.
103+
///
104+
/// [`RawWaker`]: struct.RawWaker.html
90105
drop: unsafe fn(*const ()),
91106
}
92107

@@ -128,6 +143,9 @@ impl RawWakerVTable {
128143
/// The implementation of this function must make sure to release any
129144
/// resources that are associated with this instance of a [`RawWaker`] and
130145
/// associated task.
146+
///
147+
/// [`Waker`]: struct.Waker.html
148+
/// [`RawWaker`]: struct.RawWaker.html
131149
#[rustc_promotable]
132150
#[cfg_attr(stage0, unstable(feature = "futures_api_const_fn_ptr", issue = "50547"))]
133151
#[cfg_attr(not(stage0), stable(feature = "futures_api", since = "1.36.0"))]
@@ -201,6 +219,8 @@ impl fmt::Debug for Context<'_> {
201219
/// executor-specific wakeup behavior.
202220
///
203221
/// Implements [`Clone`], [`Send`], and [`Sync`].
222+
///
223+
/// [`RawWaker`]: struct.RawWaker.html
204224
#[repr(transparent)]
205225
#[stable(feature = "futures_api", since = "1.36.0")]
206226
pub struct Waker {
@@ -266,6 +286,9 @@ impl Waker {
266286
/// The behavior of the returned `Waker` is undefined if the contract defined
267287
/// in [`RawWaker`]'s and [`RawWakerVTable`]'s documentation is not upheld.
268288
/// Therefore this method is unsafe.
289+
///
290+
/// [`RawWaker`]: struct.RawWaker.html
291+
/// [`RawWakerVTable`]: struct.RawWakerVTable.html
269292
#[inline]
270293
#[stable(feature = "futures_api", since = "1.36.0")]
271294
pub unsafe fn from_raw(waker: RawWaker) -> Waker {

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ pub struct Expr {
13561356

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

13611361
impl Expr {
13621362
pub fn precedence(&self) -> ExprPrecedence {

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ newtype_index! {
158158
impl_stable_hash_for!(struct crate::middle::region::FirstStatementIndex { private });
159159

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

163163
impl Scope {
164164
/// Returns a item-local ID associated with this scope.

src/librustc/mir/interpret/pointer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct Pointer<Tag=(),Id=AllocId> {
7878
pub tag: Tag,
7979
}
8080

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

8383
/// Produces a `Pointer` which points to the beginning of the Allocation
8484
impl From<AllocId> for Pointer {

src/librustc/mir/interpret/value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum ConstValue<'tcx> {
5454
}
5555

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

5959
impl<'tcx> ConstValue<'tcx> {
6060
#[inline]
@@ -111,7 +111,7 @@ pub enum Scalar<Tag=(), Id=AllocId> {
111111
}
112112

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

116116
impl<Tag> fmt::Display for Scalar<Tag> {
117117
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/librustc/mir/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ pub struct Statement<'tcx> {
17381738

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

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

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

20052004
/// Alias for projections as they appear in `UserTypeProjection`, where we
20062005
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.

src/librustc/mir/tcx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub struct PlaceTy<'tcx> {
1717
pub variant_index: Option<VariantIdx>,
1818
}
1919

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

2424
impl<'a, 'gcx, 'tcx> PlaceTy<'tcx> {
2525
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ pub struct TyS<'tcx> {
510510

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

515515
impl<'tcx> Ord for TyS<'tcx> {
516516
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {

src/librustc/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub enum TyKind<'tcx> {
211211

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

216216
/// A closure can be modeled as a struct that looks like:
217217
///
@@ -2207,7 +2207,7 @@ pub struct Const<'tcx> {
22072207
}
22082208

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

22122212
impl<'tcx> Const<'tcx> {
22132213
#[inline]

src/librustc_data_structures/macros.rs

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ macro_rules! static_assert {
1010
static $name: () = [()][!($test: bool) as usize];
1111
}
1212
}
13+
14+
/// Type size assertion. The first argument is a type and the second argument is its expected size.
15+
#[macro_export]
16+
#[allow_internal_unstable(underscore_const_names)]
17+
macro_rules! static_assert_size {
18+
($ty:ty, $size:expr) => {
19+
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
20+
}
21+
}

0 commit comments

Comments
 (0)