Skip to content

Commit dd155df

Browse files
committed
Auto merge of #69879 - Centril:rollup-ryea91j, r=Centril
Rollup of 10 pull requests Successful merges: - #69475 (Remove the `no_force` query attribute) - #69514 (Remove spotlight) - #69677 (rustc_metadata: Give decoder access to whole crate store) - #69714 (Make PlaceRef take just one lifetime) - #69799 (Allow ZSTs in `AllocRef`) - #69817 (test(patterns): add patterns feature tests to borrowck test suite) - #69836 (Check if output is immediate value) - #69847 (clean up E0393 explanation) - #69861 (Add note about localization to std::fmt docs) - #69877 (Vec::new is const stable in 1.39 not 1.32) Failed merges: r? @ghost
2 parents 3dbade6 + 3e9efbd commit dd155df

Some content is hidden

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

60 files changed

+925
-886
lines changed

src/doc/rustdoc/src/unstable-features.md

-21
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,6 @@ Book][unstable-doc-cfg] and [its tracking issue][issue-doc-cfg].
138138
[unstable-doc-cfg]: ../unstable-book/language-features/doc-cfg.html
139139
[issue-doc-cfg]: https://github.com/rust-lang/rust/issues/43781
140140

141-
### Adding your trait to the "Important Traits" dialog
142-
143-
Rustdoc keeps a list of a few traits that are believed to be "fundamental" to a given type when
144-
implemented on it. These traits are intended to be the primary interface for their types, and are
145-
often the only thing available to be documented on their types. For this reason, Rustdoc will track
146-
when a given type implements one of these traits and call special attention to it when a function
147-
returns one of these types. This is the "Important Traits" dialog, visible as a circle-i button next
148-
to the function, which, when clicked, shows the dialog.
149-
150-
In the standard library, the traits that qualify for inclusion are `Iterator`, `io::Read`, and
151-
`io::Write`. However, rather than being implemented as a hard-coded list, these traits have a
152-
special marker attribute on them: `#[doc(spotlight)]`. This means that you could apply this
153-
attribute to your own trait to include it in the "Important Traits" dialog in documentation.
154-
155-
The `#[doc(spotlight)]` attribute currently requires the `#![feature(doc_spotlight)]` feature gate.
156-
For more information, see [its chapter in the Unstable Book][unstable-spotlight] and [its tracking
157-
issue][issue-spotlight].
158-
159-
[unstable-spotlight]: ../unstable-book/language-features/doc-spotlight.html
160-
[issue-spotlight]: https://github.com/rust-lang/rust/issues/45040
161-
162141
### Exclude certain dependencies from documentation
163142

164143
The standard library uses several dependencies which, in turn, use several types and traits from the

src/doc/unstable-book/src/language-features/doc-spotlight.md

-30
This file was deleted.

src/liballoc/alloc.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,19 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
165165
#[unstable(feature = "allocator_api", issue = "32838")]
166166
unsafe impl AllocRef for Global {
167167
#[inline]
168-
unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
169-
NonNull::new(alloc(layout)).ok_or(AllocErr).map(|p| (p, layout.size()))
168+
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
169+
if layout.size() == 0 {
170+
Ok((layout.dangling(), 0))
171+
} else {
172+
unsafe { NonNull::new(alloc(layout)).ok_or(AllocErr).map(|p| (p, layout.size())) }
173+
}
170174
}
171175

172176
#[inline]
173177
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
174-
dealloc(ptr.as_ptr(), layout)
178+
if layout.size() != 0 {
179+
dealloc(ptr.as_ptr(), layout)
180+
}
175181
}
176182

177183
#[inline]
@@ -181,12 +187,28 @@ unsafe impl AllocRef for Global {
181187
layout: Layout,
182188
new_size: usize,
183189
) -> Result<(NonNull<u8>, usize), AllocErr> {
184-
NonNull::new(realloc(ptr.as_ptr(), layout, new_size)).ok_or(AllocErr).map(|p| (p, new_size))
190+
match (layout.size(), new_size) {
191+
(0, 0) => Ok((layout.dangling(), 0)),
192+
(0, _) => self.alloc(Layout::from_size_align_unchecked(new_size, layout.align())),
193+
(_, 0) => {
194+
self.dealloc(ptr, layout);
195+
Ok((layout.dangling(), 0))
196+
}
197+
(_, _) => NonNull::new(realloc(ptr.as_ptr(), layout, new_size))
198+
.ok_or(AllocErr)
199+
.map(|p| (p, new_size)),
200+
}
185201
}
186202

187203
#[inline]
188-
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
189-
NonNull::new(alloc_zeroed(layout)).ok_or(AllocErr).map(|p| (p, layout.size()))
204+
fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
205+
if layout.size() == 0 {
206+
Ok((layout.dangling(), 0))
207+
} else {
208+
unsafe {
209+
NonNull::new(alloc_zeroed(layout)).ok_or(AllocErr).map(|p| (p, layout.size()))
210+
}
211+
}
190212
}
191213
}
192214

src/liballoc/fmt.rs

+15
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@
247247
//! Hello, ` 123` has 3 right-aligned characters
248248
//! ```
249249
//!
250+
//! ## Localization
251+
//!
252+
//! In some programming languages, the behavior of string formatting functions
253+
//! depends on the operating system's locale setting. The format functions
254+
//! provided by Rust's standard library do not have any concept of locale, and
255+
//! will produce the same results on all systems regardless of user
256+
//! configuration.
257+
//!
258+
//! For example, the following code will always print `1.5` even if the system
259+
//! locale uses a decimal separator other than a dot.
260+
//!
261+
//! ```
262+
//! println!("The value is {}", 1.5);
263+
//! ```
264+
//!
250265
//! # Escaping
251266
//!
252267
//! The literal characters `{` and `}` may be included in a string by preceding

src/liballoc/raw_vec.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,28 @@ impl<T, A: AllocRef> RawVec<T, A> {
7373
}
7474

7575
fn allocate_in(mut capacity: usize, zeroed: bool, mut a: A) -> Self {
76-
unsafe {
77-
let elem_size = mem::size_of::<T>();
76+
let elem_size = mem::size_of::<T>();
7877

79-
let alloc_size = capacity.checked_mul(elem_size).unwrap_or_else(|| capacity_overflow());
80-
alloc_guard(alloc_size).unwrap_or_else(|_| capacity_overflow());
78+
let alloc_size = capacity.checked_mul(elem_size).unwrap_or_else(|| capacity_overflow());
79+
alloc_guard(alloc_size).unwrap_or_else(|_| capacity_overflow());
8180

82-
// Handles ZSTs and `capacity == 0` alike.
83-
let ptr = if alloc_size == 0 {
84-
NonNull::<T>::dangling()
85-
} else {
86-
let align = mem::align_of::<T>();
87-
let layout = Layout::from_size_align(alloc_size, align).unwrap();
88-
let result = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
89-
match result {
90-
Ok((ptr, size)) => {
91-
capacity = size / elem_size;
92-
ptr.cast()
93-
}
94-
Err(_) => handle_alloc_error(layout),
81+
// Handles ZSTs and `capacity == 0` alike.
82+
let ptr = if alloc_size == 0 {
83+
NonNull::<T>::dangling()
84+
} else {
85+
let align = mem::align_of::<T>();
86+
let layout = Layout::from_size_align(alloc_size, align).unwrap();
87+
let result = if zeroed { a.alloc_zeroed(layout) } else { a.alloc(layout) };
88+
match result {
89+
Ok((ptr, size)) => {
90+
capacity = size / elem_size;
91+
ptr.cast()
9592
}
96-
};
93+
Err(_) => handle_alloc_error(layout),
94+
}
95+
};
9796

98-
RawVec { ptr: ptr.into(), cap: capacity, a }
99-
}
97+
RawVec { ptr: ptr.into(), cap: capacity, a }
10098
}
10199
}
102100

src/liballoc/raw_vec/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn allocator_param() {
2020
fuel: usize,
2121
}
2222
unsafe impl AllocRef for BoundedAlloc {
23-
unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
23+
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
2424
let size = layout.size();
2525
if size > self.fuel {
2626
return Err(AllocErr);

src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl<T> Vec<T> {
317317
/// let mut vec: Vec<i32> = Vec::new();
318318
/// ```
319319
#[inline]
320-
#[rustc_const_stable(feature = "const_vec_new", since = "1.32.0")]
320+
#[rustc_const_stable(feature = "const_vec_new", since = "1.39.0")]
321321
#[stable(feature = "rust1", since = "1.0.0")]
322322
pub const fn new() -> Vec<T> {
323323
Vec { buf: RawVec::NEW, len: 0 }

src/libcore/alloc.rs

+13-43
Original file line numberDiff line numberDiff line change
@@ -606,20 +606,11 @@ pub unsafe trait GlobalAlloc {
606606
/// method (`dealloc`) or by being passed to a reallocation method
607607
/// (see above) that returns `Ok`.
608608
///
609-
/// A note regarding zero-sized types and zero-sized layouts: many
610-
/// methods in the `AllocRef` trait state that allocation requests
611-
/// must be non-zero size, or else undefined behavior can result.
612-
///
613-
/// * If an `AllocRef` implementation chooses to return `Ok` in this
614-
/// case (i.e., the pointer denotes a zero-sized inaccessible block)
615-
/// then that returned pointer must be considered "currently
616-
/// allocated". On such an allocator, *all* methods that take
617-
/// currently-allocated pointers as inputs must accept these
618-
/// zero-sized pointers, *without* causing undefined behavior.
619-
///
620-
/// * In other words, if a zero-sized pointer can flow out of an
621-
/// allocator, then that allocator must likewise accept that pointer
622-
/// flowing back into its deallocation and reallocation methods.
609+
/// Unlike [`GlobalAlloc`], zero-sized allocations are allowed in
610+
/// `AllocRef`. If an underlying allocator does not support this (like
611+
/// jemalloc) or return a null pointer (such as `libc::malloc`), this case
612+
/// must be caught. In this case [`Layout::dangling()`] can be used to
613+
/// create a dangling, but aligned `NonNull<u8>`.
623614
///
624615
/// Some of the methods require that a layout *fit* a memory block.
625616
/// What it means for a layout to "fit" a memory block means (or
@@ -649,6 +640,9 @@ pub unsafe trait GlobalAlloc {
649640
/// * if an allocator does not support overallocating, it is fine to
650641
/// simply return `layout.size()` as the allocated size.
651642
///
643+
/// [`GlobalAlloc`]: self::GlobalAlloc
644+
/// [`Layout::dangling()`]: self::Layout::dangling
645+
///
652646
/// # Safety
653647
///
654648
/// The `AllocRef` trait is an `unsafe` trait for a number of reasons, and
@@ -669,14 +663,6 @@ pub unsafe trait GlobalAlloc {
669663
/// the future.
670664
#[unstable(feature = "allocator_api", issue = "32838")]
671665
pub unsafe trait AllocRef {
672-
// (Note: some existing allocators have unspecified but well-defined
673-
// behavior in response to a zero size allocation request ;
674-
// e.g., in C, `malloc` of 0 will either return a null pointer or a
675-
// unique pointer, but will not have arbitrary undefined
676-
// behavior.
677-
// However in jemalloc for example,
678-
// `mallocx(0)` is documented as undefined behavior.)
679-
680666
/// On success, returns a pointer meeting the size and alignment
681667
/// guarantees of `layout` and the actual size of the allocated block,
682668
/// which must be greater than or equal to `layout.size()`.
@@ -690,15 +676,6 @@ pub unsafe trait AllocRef {
690676
/// behavior, e.g., to ensure initialization to particular sets of
691677
/// bit patterns.)
692678
///
693-
/// # Safety
694-
///
695-
/// This function is unsafe because undefined behavior can result
696-
/// if the caller does not ensure that `layout` has non-zero size.
697-
///
698-
/// (Extension subtraits might provide more specific bounds on
699-
/// behavior, e.g., guarantee a sentinel address or a null pointer
700-
/// in response to a zero-size allocation request.)
701-
///
702679
/// # Errors
703680
///
704681
/// Returning `Err` indicates that either memory is exhausted or
@@ -716,7 +693,7 @@ pub unsafe trait AllocRef {
716693
/// rather than directly invoking `panic!` or similar.
717694
///
718695
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
719-
unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr>;
696+
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr>;
720697

721698
/// Deallocate the memory referenced by `ptr`.
722699
///
@@ -738,10 +715,6 @@ pub unsafe trait AllocRef {
738715
/// Behaves like `alloc`, but also ensures that the contents
739716
/// are set to zero before being returned.
740717
///
741-
/// # Safety
742-
///
743-
/// This function is unsafe for the same reasons that `alloc` is.
744-
///
745718
/// # Errors
746719
///
747720
/// Returning `Err` indicates that either memory is exhausted or
@@ -753,17 +726,17 @@ pub unsafe trait AllocRef {
753726
/// rather than directly invoking `panic!` or similar.
754727
///
755728
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
756-
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
729+
fn alloc_zeroed(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
757730
let size = layout.size();
758731
let result = self.alloc(layout);
759732
if let Ok((p, _)) = result {
760-
ptr::write_bytes(p.as_ptr(), 0, size);
733+
unsafe { ptr::write_bytes(p.as_ptr(), 0, size) }
761734
}
762735
result
763736
}
764737

765738
// == METHODS FOR MEMORY REUSE ==
766-
// realloc. alloc_excess, realloc_excess
739+
// realloc, realloc_zeroed, grow_in_place, grow_in_place_zeroed, shrink_in_place
767740

768741
/// Returns a pointer suitable for holding data described by
769742
/// a new layout with `layout`’s alignment and a size given
@@ -793,8 +766,6 @@ pub unsafe trait AllocRef {
793766
/// * `layout` must *fit* the `ptr` (see above). (The `new_size`
794767
/// argument need not fit it.)
795768
///
796-
/// * `new_size` must be greater than zero.
797-
///
798769
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`,
799770
/// must not overflow (i.e., the rounded value must be less than `usize::MAX`).
800771
///
@@ -1009,8 +980,7 @@ pub unsafe trait AllocRef {
1009980
/// * `layout` must *fit* the `ptr` (see above); note the
1010981
/// `new_size` argument need not fit it,
1011982
///
1012-
/// * `new_size` must not be greater than `layout.size()`
1013-
/// (and must be greater than zero),
983+
/// * `new_size` must not be greater than `layout.size()`,
1014984
///
1015985
/// # Errors
1016986
///

src/libcore/future/future.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::task::{Context, Poll};
2424
/// `.await` the value.
2525
///
2626
/// [`Waker`]: ../task/struct.Waker.html
27-
#[doc(spotlight)]
2827
#[must_use = "futures do nothing unless you `.await` or poll them"]
2928
#[stable(feature = "futures_api", since = "1.36.0")]
3029
#[lang = "future_trait"]

src/libcore/iter/traits/iterator.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
9292
label = "`{Self}` is not an iterator",
9393
message = "`{Self}` is not an iterator"
9494
)]
95-
#[doc(spotlight)]
9695
#[must_use = "iterators are lazy and do nothing unless consumed"]
9796
pub trait Iterator {
9897
/// The type of the elements being iterated over.

src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
#![feature(custom_inner_attributes)]
9191
#![feature(decl_macro)]
9292
#![feature(doc_cfg)]
93-
#![feature(doc_spotlight)]
9493
#![feature(extern_types)]
9594
#![feature(fundamental)]
9695
#![feature(intrinsics)]

0 commit comments

Comments
 (0)