Skip to content

Commit 4b0681a

Browse files
committed
Auto merge of #92587 - matthiaskrgr:rollup-qnwa8qx, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #92092 (Drop guards in slice sorting derive src pointers from &mut T, which is invalidated by interior mutation in comparison) - #92388 (Fix a minor mistake in `String::try_reserve_exact` examples) - #92442 (Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId`) - #92483 (Stabilize `result_cloned` and `result_copied`) - #92574 (Add RISC-V detection macro and more architecture instructions) - #92575 (ast: Always keep a `NodeId` in `ast::Crate`) - #92583 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b52b4c1 + 0faeade commit 4b0681a

File tree

7 files changed

+38
-27
lines changed

7 files changed

+38
-27
lines changed

alloc/src/slice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ where
892892
// performance than with the 2nd method.
893893
//
894894
// All methods were benchmarked, and the 3rd showed best results. So we chose that one.
895-
let mut tmp = mem::ManuallyDrop::new(ptr::read(&v[0]));
895+
let tmp = mem::ManuallyDrop::new(ptr::read(&v[0]));
896896

897897
// Intermediate state of the insertion process is always tracked by `hole`, which
898898
// serves two purposes:
@@ -904,7 +904,7 @@ where
904904
// If `is_less` panics at any point during the process, `hole` will get dropped and
905905
// fill the hole in `v` with `tmp`, thus ensuring that `v` still holds every object it
906906
// initially held exactly once.
907-
let mut hole = InsertionHole { src: &mut *tmp, dest: &mut v[1] };
907+
let mut hole = InsertionHole { src: &*tmp, dest: &mut v[1] };
908908
ptr::copy_nonoverlapping(&v[1], &mut v[0], 1);
909909

910910
for i in 2..v.len() {
@@ -920,7 +920,7 @@ where
920920

921921
// When dropped, copies from `src` into `dest`.
922922
struct InsertionHole<T> {
923-
src: *mut T,
923+
src: *const T,
924924
dest: *mut T,
925925
}
926926

alloc/src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ impl String {
10621062
/// let mut output = String::new();
10631063
///
10641064
/// // Pre-reserve the memory, exiting if we can't
1065-
/// output.try_reserve(data.len())?;
1065+
/// output.try_reserve_exact(data.len())?;
10661066
///
10671067
/// // Now we know this can't OOM in the middle of our complex work
10681068
/// output.push_str(data);

core/src/hint.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ pub fn spin_loop() {
123123
}
124124
}
125125

126+
// RISC-V platform spin loop hint implementation
127+
{
128+
// RISC-V RV32 and RV64 share the same PAUSE instruction, but they are located in different
129+
// modules in `core::arch`.
130+
// In this case, here we call `pause` function in each core arch module.
131+
#[cfg(target_arch = "riscv32")]
132+
{
133+
crate::arch::riscv32::pause();
134+
}
135+
#[cfg(target_arch = "riscv64")]
136+
{
137+
crate::arch::riscv64::pause();
138+
}
139+
}
140+
126141
#[cfg(any(target_arch = "aarch64", all(target_arch = "arm", target_feature = "v6")))]
127142
{
128143
#[cfg(target_arch = "aarch64")]
@@ -137,11 +152,6 @@ pub fn spin_loop() {
137152
unsafe { crate::arch::arm::__yield() };
138153
}
139154
}
140-
141-
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
142-
{
143-
crate::arch::riscv::pause();
144-
}
145155
}
146156

147157
/// An identity function that *__hints__* to the compiler to be maximally pessimistic about what

core/src/result.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,14 +1504,14 @@ impl<T, E> Result<&T, E> {
15041504
/// # Examples
15051505
///
15061506
/// ```
1507-
/// #![feature(result_copied)]
15081507
/// let val = 12;
15091508
/// let x: Result<&i32, i32> = Ok(&val);
15101509
/// assert_eq!(x, Ok(&12));
15111510
/// let copied = x.copied();
15121511
/// assert_eq!(copied, Ok(12));
15131512
/// ```
1514-
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
1513+
#[inline]
1514+
#[stable(feature = "result_copied", since = "1.59.0")]
15151515
pub fn copied(self) -> Result<T, E>
15161516
where
15171517
T: Copy,
@@ -1525,14 +1525,14 @@ impl<T, E> Result<&T, E> {
15251525
/// # Examples
15261526
///
15271527
/// ```
1528-
/// #![feature(result_cloned)]
15291528
/// let val = 12;
15301529
/// let x: Result<&i32, i32> = Ok(&val);
15311530
/// assert_eq!(x, Ok(&12));
15321531
/// let cloned = x.cloned();
15331532
/// assert_eq!(cloned, Ok(12));
15341533
/// ```
1535-
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1534+
#[inline]
1535+
#[stable(feature = "result_cloned", since = "1.59.0")]
15361536
pub fn cloned(self) -> Result<T, E>
15371537
where
15381538
T: Clone,
@@ -1548,14 +1548,14 @@ impl<T, E> Result<&mut T, E> {
15481548
/// # Examples
15491549
///
15501550
/// ```
1551-
/// #![feature(result_copied)]
15521551
/// let mut val = 12;
15531552
/// let x: Result<&mut i32, i32> = Ok(&mut val);
15541553
/// assert_eq!(x, Ok(&mut 12));
15551554
/// let copied = x.copied();
15561555
/// assert_eq!(copied, Ok(12));
15571556
/// ```
1558-
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
1557+
#[inline]
1558+
#[stable(feature = "result_copied", since = "1.59.0")]
15591559
pub fn copied(self) -> Result<T, E>
15601560
where
15611561
T: Copy,
@@ -1569,14 +1569,14 @@ impl<T, E> Result<&mut T, E> {
15691569
/// # Examples
15701570
///
15711571
/// ```
1572-
/// #![feature(result_cloned)]
15731572
/// let mut val = 12;
15741573
/// let x: Result<&mut i32, i32> = Ok(&mut val);
15751574
/// assert_eq!(x, Ok(&mut 12));
15761575
/// let cloned = x.cloned();
15771576
/// assert_eq!(cloned, Ok(12));
15781577
/// ```
1579-
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1578+
#[inline]
1579+
#[stable(feature = "result_cloned", since = "1.59.0")]
15801580
pub fn cloned(self) -> Result<T, E>
15811581
where
15821582
T: Clone,

core/src/slice/sort.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::ptr;
1212

1313
/// When dropped, copies from `src` into `dest`.
1414
struct CopyOnDrop<T> {
15-
src: *mut T,
15+
src: *const T,
1616
dest: *mut T,
1717
}
1818

@@ -54,9 +54,9 @@ where
5454
// Read the first element into a stack-allocated variable. If a following comparison
5555
// operation panics, `hole` will get dropped and automatically write the element back
5656
// into the slice.
57-
let mut tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(0)));
57+
let tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(0)));
5858
let v = v.as_mut_ptr();
59-
let mut hole = CopyOnDrop { src: &mut *tmp, dest: v.add(1) };
59+
let mut hole = CopyOnDrop { src: &*tmp, dest: v.add(1) };
6060
ptr::copy_nonoverlapping(v.add(1), v.add(0), 1);
6161

6262
for i in 2..len {
@@ -100,9 +100,9 @@ where
100100
// Read the last element into a stack-allocated variable. If a following comparison
101101
// operation panics, `hole` will get dropped and automatically write the element back
102102
// into the slice.
103-
let mut tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(len - 1)));
103+
let tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(len - 1)));
104104
let v = v.as_mut_ptr();
105-
let mut hole = CopyOnDrop { src: &mut *tmp, dest: v.add(len - 2) };
105+
let mut hole = CopyOnDrop { src: &*tmp, dest: v.add(len - 2) };
106106
ptr::copy_nonoverlapping(v.add(len - 2), v.add(len - 1), 1);
107107

108108
for i in (0..len - 2).rev() {
@@ -498,8 +498,8 @@ where
498498
// operation panics, the pivot will be automatically written back into the slice.
499499

500500
// SAFETY: `pivot` is a reference to the first element of `v`, so `ptr::read` is safe.
501-
let mut tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
502-
let _pivot_guard = CopyOnDrop { src: &mut *tmp, dest: pivot };
501+
let tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
502+
let _pivot_guard = CopyOnDrop { src: &*tmp, dest: pivot };
503503
let pivot = &*tmp;
504504

505505
// Find the first pair of out-of-order elements.
@@ -551,8 +551,8 @@ where
551551
// Read the pivot into a stack-allocated variable for efficiency. If a following comparison
552552
// operation panics, the pivot will be automatically written back into the slice.
553553
// SAFETY: The pointer here is valid because it is obtained from a reference to a slice.
554-
let mut tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
555-
let _pivot_guard = CopyOnDrop { src: &mut *tmp, dest: pivot };
554+
let tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
555+
let _pivot_guard = CopyOnDrop { src: &*tmp, dest: pivot };
556556
let pivot = &*tmp;
557557

558558
// Now partition the slice.

std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ pub use std_detect::*;
556556
pub use std_detect::{
557557
is_aarch64_feature_detected, is_arm_feature_detected, is_mips64_feature_detected,
558558
is_mips_feature_detected, is_powerpc64_feature_detected, is_powerpc_feature_detected,
559+
is_riscv_feature_detected,
559560
};
560561

561562
// Re-export macros defined in libcore.

stdarch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 0716b22e902207efabe46879cbf28d0189ab7924
1+
Subproject commit 2adc17a5442614dbe34626fdd9b32de7c07b8086

0 commit comments

Comments
 (0)