Skip to content

Commit 93637f3

Browse files
committed
Auto merge of #155583 - jhpratt:rollup-HPCle0C, r=jhpratt
Rollup of 5 pull requests Successful merges: - #155532 (Fix redundant boolean comparison in `Mutex::try_lock`) - #155558 (Clarify that isqrt returns the principal (non-negative) square root) - #155559 (add safety doc (section header) to two unsafe methods in `NonZero`) - #155564 (Implement const Default for &CStr) - #155565 (constify `Vec` comparisons)
2 parents 9ab01ae + b4bab32 commit 93637f3

6 files changed

Lines changed: 40 additions & 19 deletions

File tree

library/alloc/src/vec/partial_eq.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use crate::alloc::Allocator;
44
use crate::borrow::Cow;
55

66
macro_rules! __impl_slice_eq1 {
7-
([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => {
8-
#[$stability]
9-
impl<T, U, $($vars)*> PartialEq<$rhs> for $lhs
7+
($($const:ident, )? [$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, $(#[$stability:meta])+ ) => {
8+
$(#[$stability])+
9+
impl<T, U, $($vars)*> $($const)? PartialEq<$rhs> for $lhs
1010
where
11-
T: PartialEq<U>,
11+
T: $([$const])? PartialEq<U>,
1212
$($ty: $bound)?
1313
{
1414
#[inline]
@@ -19,21 +19,21 @@ macro_rules! __impl_slice_eq1 {
1919
}
2020
}
2121

22-
__impl_slice_eq1! { [A1: Allocator, A2: Allocator] Vec<T, A1>, Vec<U, A2>, #[stable(feature = "rust1", since = "1.0.0")] }
23-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &[U], #[stable(feature = "rust1", since = "1.0.0")] }
24-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] }
25-
__impl_slice_eq1! { [A: Allocator] &[T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
26-
__impl_slice_eq1! { [A: Allocator] &mut [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
27-
__impl_slice_eq1! { [A: Allocator] Vec<T, A>, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
28-
__impl_slice_eq1! { [A: Allocator] [T], Vec<U, A>, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
22+
__impl_slice_eq1! { const, [A1: Allocator, A2: Allocator] Vec<T, A1>, Vec<U, A2>, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] }
23+
__impl_slice_eq1! { const, [A: Allocator] Vec<T, A>, &[U], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] }
24+
__impl_slice_eq1! { const, [A: Allocator] Vec<T, A>, &mut [U], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] }
25+
__impl_slice_eq1! { const, [A: Allocator] &[T], Vec<U, A>, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
26+
__impl_slice_eq1! { const, [A: Allocator] &mut [T], Vec<U, A>, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] }
27+
__impl_slice_eq1! { const, [A: Allocator] Vec<T, A>, [U], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
28+
__impl_slice_eq1! { const, [A: Allocator] [T], Vec<U, A>, #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] }
2929
#[cfg(not(no_global_oom_handling))]
3030
__impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec<U, A> where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
3131
#[cfg(not(no_global_oom_handling))]
3232
__impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
3333
#[cfg(not(no_global_oom_handling))]
3434
__impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] }
35-
__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, [U; N], #[stable(feature = "rust1", since = "1.0.0")] }
36-
__impl_slice_eq1! { [A: Allocator, const N: usize] Vec<T, A>, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] }
35+
__impl_slice_eq1! { const, [A: Allocator, const N: usize] Vec<T, A>, [U; N], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] }
36+
__impl_slice_eq1! { const, [A: Allocator, const N: usize] Vec<T, A>, &[U; N], #[rustc_const_unstable(feature = "const_cmp", issue = "143800")] #[stable(feature = "rust1", since = "1.0.0")] }
3737

3838
// NOTE: some less important impls are omitted to reduce code bloat
3939
// FIXME(Centril): Reconsider this?

library/core/src/ffi/c_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl fmt::Debug for CStr {
176176
}
177177

178178
#[stable(feature = "cstr_default", since = "1.10.0")]
179-
impl Default for &CStr {
179+
#[rustc_const_unstable(feature = "const_default", issue = "143894")]
180+
impl const Default for &CStr {
180181
#[inline]
181182
fn default() -> Self {
182183
c""

library/core/src/num/int_macros.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,11 @@ macro_rules! int_impl {
19111911
}
19121912
}
19131913

1914-
/// Returns the square root of the number, rounded down.
1914+
/// Returns the integer square root of the number, rounded down.
1915+
///
1916+
/// This function returns the **principal (non-negative) square root**.
1917+
/// For a given number `n`, although both `x` and `-x` satisfy x<sup>2</sup> = n,
1918+
/// this function always returns the non-negative value.
19151919
///
19161920
/// Returns `None` if `self` is negative.
19171921
///
@@ -3206,7 +3210,11 @@ macro_rules! int_impl {
32063210
}
32073211
}
32083212

3209-
/// Returns the square root of the number, rounded down.
3213+
/// Returns the integer square root of the number, rounded down.
3214+
///
3215+
/// This function returns the **principal (non-negative) square root**.
3216+
/// For a given number `n`, although both `x` and `-x` satisfy x<sup>2</sup> = n,
3217+
/// this function always returns the non-negative value.
32103218
///
32113219
/// # Panics
32123220
///

library/core/src/num/nonzero.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,10 @@ macro_rules! nonzero_integer {
11181118
/// assuming overflow cannot occur.
11191119
/// Overflow is unchecked, and it is undefined behavior to overflow
11201120
/// *even if the result would wrap to a non-zero value*.
1121-
/// The behavior is undefined as soon as
1121+
///
1122+
/// # Safety
1123+
///
1124+
/// This results in undefined behavior when
11221125
#[doc = sign_dependent_expr!{
11231126
$signedness ?
11241127
if signed {
@@ -1695,7 +1698,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
16951698
/// assuming overflow cannot occur.
16961699
/// Overflow is unchecked, and it is undefined behavior to overflow
16971700
/// *even if the result would wrap to a non-zero value*.
1698-
/// The behavior is undefined as soon as
1701+
///
1702+
/// # Safety
1703+
///
1704+
/// This results in undefined behavior when
16991705
#[doc = concat!("`self + rhs > ", stringify!($Int), "::MAX`.")]
17001706
///
17011707
/// # Examples

library/coretests/tests/ffi/cstr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
use core::ffi::CStr;
22

3+
#[test]
4+
fn const_default() {
5+
const S: &CStr = <_>::default();
6+
assert_eq!(S, c"");
7+
}
8+
39
#[test]
410
fn compares_as_u8s() {
511
let a: &CStr = c"Hello!"; // Starts with ascii

library/std/src/sys/sync/mutex/no_threads.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ impl Mutex {
2626

2727
#[inline]
2828
pub fn try_lock(&self) -> bool {
29-
self.locked.replace(true) == false
29+
!self.locked.replace(true)
3030
}
3131
}

0 commit comments

Comments
 (0)