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 13 pull requests #120271

Closed
wants to merge 30 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2d1b2a9
Add more weirdness to weird-exprs.rs
oberien Dec 16, 2023
c7a77b2
Split assembly tests for ELF and MachO
nikic Jan 19, 2024
3ed96e3
Suggest arry::from_fn for array initialization
chenyukang Jan 5, 2024
98f5981
Rename function in weird-exprs.rs for clarity
oberien Jan 21, 2024
df3ec4c
aho-corasick 0.7.20 -> aho-corasick 1.0.2
michaelciraci Jan 20, 2024
56bc552
Bump `object` version
clubby789 Jan 21, 2024
b50b333
Bump `uniq-langid` version
clubby789 Jan 21, 2024
527f903
Bump `ctrlc` version
clubby789 Jan 21, 2024
c751720
Bump `openssl` version
clubby789 Jan 21, 2024
41dcba8
coverage: Don't instrument `#[automatically_derived]` functions
Zalathar Jan 21, 2024
7a17508
correct my mailmap entry
emberian Jan 22, 2024
dec4740
compiler: update freebsd and netbsd base specs.
devnexen Jan 21, 2024
a77cc2c
Use `Self` in `NonZero*` implementations.
reitermarkus Jan 22, 2024
ce11b70
Re-add estebank to review rotation
estebank Jan 22, 2024
ed4b99a
fixing build for the BSD
devnexen Jan 22, 2024
c6088f7
`RawTy` to `LoweredTy`
lcnr Jan 22, 2024
5fc39e0
Random type checker changes
compiler-errors Jan 23, 2024
7f3c43b
Rollup merge of #119028 - oberien:patch-1, r=cjgillot
fmease Jan 23, 2024
50552ed
Rollup merge of #119805 - chenyukang:yukang-fix-119530, r=davidtwco
fmease Jan 23, 2024
ab099a3
Rollup merge of #120124 - nikic:fix-assembly-test, r=davidtwco
fmease Jan 23, 2024
6df9b9d
Rollup merge of #120177 - michaelciraci:merge-deps-2, r=Nilstrieb
fmease Jan 23, 2024
8b069cc
Rollup merge of #120185 - Zalathar:auto-derived, r=wesleywiser
fmease Jan 23, 2024
9c28877
Rollup merge of #120188 - devnexen:update_bsd_compiler_base_specs, r=…
fmease Jan 23, 2024
3b21e5a
Rollup merge of #120201 - clubby789:dep-update, r=dtolnay
fmease Jan 23, 2024
db91b88
Rollup merge of #120215 - clubby789:dep-updates, r=Nilstrieb
fmease Jan 23, 2024
3e94cc7
Rollup merge of #120244 - reitermarkus:nonzero-self, r=dtolnay
fmease Jan 23, 2024
6182fbd
Rollup merge of #120246 - estebank:revert_breathing_room, r=estebank
fmease Jan 23, 2024
ae1e70a
Rollup merge of #120252 - lcnr:rename-astconv-ty, r=compiler-errors
fmease Jan 23, 2024
9db841e
Rollup merge of #120255 - emberian:patch-1, r=Nilstrieb
fmease Jan 23, 2024
9ff82a8
Rollup merge of #120270 - compiler-errors:randos, r=lcnr
fmease Jan 23, 2024
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
91 changes: 48 additions & 43 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
@@ -317,7 +317,7 @@ macro_rules! nonzero_integer {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_mul(self, other: $Ty) -> Option<$Ty> {
pub const fn checked_mul(self, other: Self) -> Option<Self> {
if let Some(result) = self.get().checked_mul(other.get()) {
// SAFETY:
// - `checked_mul` returns `None` on overflow
@@ -326,7 +326,7 @@ macro_rules! nonzero_integer {
// of the sides to be zero
//
// So the result cannot be zero.
Some(unsafe { $Ty::new_unchecked(result) })
Some(unsafe { Self::new_unchecked(result) })
} else {
None
}
@@ -356,7 +356,7 @@ macro_rules! nonzero_integer {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn saturating_mul(self, other: $Ty) -> $Ty {
pub const fn saturating_mul(self, other: Self) -> Self {
// SAFETY:
// - `saturating_mul` returns `u*::MAX`/`i*::MAX`/`i*::MIN` on overflow/underflow,
// all of which are non-zero
@@ -365,7 +365,7 @@ macro_rules! nonzero_integer {
// of the sides to be zero
//
// So the result cannot be zero.
unsafe { $Ty::new_unchecked(self.get().saturating_mul(other.get())) }
unsafe { Self::new_unchecked(self.get().saturating_mul(other.get())) }
}

/// Multiplies two non-zero integers together,
@@ -403,9 +403,9 @@ macro_rules! nonzero_integer {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_mul(self, other: $Ty) -> $Ty {
pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
// SAFETY: The caller ensures there is no overflow.
unsafe { $Ty::new_unchecked(self.get().unchecked_mul(other.get())) }
unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
}

/// Raises non-zero value to an integer power.
@@ -433,7 +433,7 @@ macro_rules! nonzero_integer {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_pow(self, other: u32) -> Option<$Ty> {
pub const fn checked_pow(self, other: u32) -> Option<Self> {
if let Some(result) = self.get().checked_pow(other) {
// SAFETY:
// - `checked_pow` returns `None` on overflow/underflow
@@ -442,7 +442,7 @@ macro_rules! nonzero_integer {
// for base to be zero
//
// So the result cannot be zero.
Some(unsafe { $Ty::new_unchecked(result) })
Some(unsafe { Self::new_unchecked(result) })
} else {
None
}
@@ -481,7 +481,7 @@ macro_rules! nonzero_integer {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn saturating_pow(self, other: u32) -> $Ty {
pub const fn saturating_pow(self, other: u32) -> Self {
// SAFETY:
// - `saturating_pow` returns `u*::MAX`/`i*::MAX`/`i*::MIN` on overflow/underflow,
// all of which are non-zero
@@ -490,7 +490,7 @@ macro_rules! nonzero_integer {
// for base to be zero
//
// So the result cannot be zero.
unsafe { $Ty::new_unchecked(self.get().saturating_pow(other)) }
unsafe { Self::new_unchecked(self.get().saturating_pow(other)) }
}
}

@@ -508,29 +508,32 @@ macro_rules! nonzero_integer {
#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOr for $Ty {
type Output = Self;

#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
// SAFETY: since `self` and `rhs` are both nonzero, the
// result of the bitwise-or will be nonzero.
unsafe { $Ty::new_unchecked(self.get() | rhs.get()) }
unsafe { Self::new_unchecked(self.get() | rhs.get()) }
}
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOr<$Int> for $Ty {
type Output = Self;

#[inline]
fn bitor(self, rhs: $Int) -> Self::Output {
// SAFETY: since `self` is nonzero, the result of the
// bitwise-or will be nonzero regardless of the value of
// `rhs`.
unsafe { $Ty::new_unchecked(self.get() | rhs) }
unsafe { Self::new_unchecked(self.get() | rhs) }
}
}

#[stable(feature = "nonzero_bitor", since = "1.45.0")]
impl BitOr<$Ty> for $Int {
type Output = $Ty;

#[inline]
fn bitor(self, rhs: $Ty) -> Self::Output {
// SAFETY: since `rhs` is nonzero, the result of the
@@ -603,6 +606,7 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
#[stable(feature = "nonzero_div", since = "1.51.0")]
impl Div<$Ty> for $Int {
type Output = $Int;

/// This operation rounds towards zero,
/// truncating any fractional part of the exact result, and cannot panic.
#[inline]
@@ -616,6 +620,7 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
#[stable(feature = "nonzero_div", since = "1.51.0")]
impl Rem<$Ty> for $Int {
type Output = $Int;

/// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic.
#[inline]
fn rem(self, other: $Ty) -> $Int {
@@ -630,12 +635,12 @@ macro_rules! nonzero_integer_signedness_dependent_impls {
($Ty:ident signed $Int:ty) => {
#[stable(feature = "signed_nonzero_neg", since = "1.71.0")]
impl Neg for $Ty {
type Output = $Ty;
type Output = Self;

#[inline]
fn neg(self) -> $Ty {
fn neg(self) -> Self {
// SAFETY: negation of nonzero cannot yield zero values.
unsafe { $Ty::new_unchecked(self.get().neg()) }
unsafe { Self::new_unchecked(self.get().neg()) }
}
}

@@ -703,7 +708,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_add(self, other: $Int) -> Option<$Ty> {
pub const fn checked_add(self, other: $Int) -> Option<Self> {
if let Some(result) = self.get().checked_add(other) {
// SAFETY:
// - `checked_add` returns `None` on overflow
@@ -712,7 +717,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
// sides to be zero
//
// So the result cannot be zero.
Some(unsafe { $Ty::new_unchecked(result) })
Some(unsafe { Self::new_unchecked(result) })
} else {
None
}
@@ -742,15 +747,15 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn saturating_add(self, other: $Int) -> $Ty {
pub const fn saturating_add(self, other: $Int) -> Self {
// SAFETY:
// - `saturating_add` returns `u*::MAX` on overflow, which is non-zero
// - `self` is non-zero
// - the only way to get zero from an addition without overflow is for both
// sides to be zero
//
// So the result cannot be zero.
unsafe { $Ty::new_unchecked(self.get().saturating_add(other)) }
unsafe { Self::new_unchecked(self.get().saturating_add(other)) }
}

/// Adds an unsigned integer to a non-zero value,
@@ -779,9 +784,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_add(self, other: $Int) -> $Ty {
pub const unsafe fn unchecked_add(self, other: $Int) -> Self {
// SAFETY: The caller ensures there is no overflow.
unsafe { $Ty::new_unchecked(self.get().unchecked_add(other)) }
unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
}

/// Returns the smallest power of two greater than or equal to n.
@@ -812,11 +817,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_next_power_of_two(self) -> Option<$Ty> {
pub const fn checked_next_power_of_two(self) -> Option<Self> {
if let Some(nz) = self.get().checked_next_power_of_two() {
// SAFETY: The next power of two is positive
// and overflow is checked.
Some(unsafe { $Ty::new_unchecked(nz) })
Some(unsafe { Self::new_unchecked(nz) })
} else {
None
}
@@ -902,9 +907,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
pub const fn midpoint(self, rhs: Self) -> Self {
// SAFETY: The only way to get `0` with midpoint is to have two opposite or
// near opposite numbers: (-5, 5), (0, 1), (0, 0) which is impossible because
// of the unsignedness of this number and also because $Ty is guaranteed to
// of the unsignedness of this number and also because `Self` is guaranteed to
// never being 0.
unsafe { $Ty::new_unchecked(self.get().midpoint(rhs.get())) }
unsafe { Self::new_unchecked(self.get().midpoint(rhs.get())) }
}

/// Returns `true` if and only if `self == (1 << k)` for some `k`.
@@ -1000,9 +1005,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn abs(self) -> $Ty {
pub const fn abs(self) -> Self {
// SAFETY: This cannot overflow to zero.
unsafe { $Ty::new_unchecked(self.get().abs()) }
unsafe { Self::new_unchecked(self.get().abs()) }
}

/// Checked absolute value.
@@ -1031,10 +1036,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn checked_abs(self) -> Option<$Ty> {
pub const fn checked_abs(self) -> Option<Self> {
if let Some(nz) = self.get().checked_abs() {
// SAFETY: absolute value of nonzero cannot yield zero values.
Some(unsafe { $Ty::new_unchecked(nz) })
Some(unsafe { Self::new_unchecked(nz) })
} else {
None
}
@@ -1066,11 +1071,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn overflowing_abs(self) -> ($Ty, bool) {
pub const fn overflowing_abs(self) -> (Self, bool) {
let (nz, flag) = self.get().overflowing_abs();
(
// SAFETY: absolute value of nonzero cannot yield zero values.
unsafe { $Ty::new_unchecked(nz) },
unsafe { Self::new_unchecked(nz) },
flag,
)
}
@@ -1105,9 +1110,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn saturating_abs(self) -> $Ty {
pub const fn saturating_abs(self) -> Self {
// SAFETY: absolute value of nonzero cannot yield zero values.
unsafe { $Ty::new_unchecked(self.get().saturating_abs()) }
unsafe { Self::new_unchecked(self.get().saturating_abs()) }
}

/// Wrapping absolute value, see
@@ -1138,9 +1143,9 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn wrapping_abs(self) -> $Ty {
pub const fn wrapping_abs(self) -> Self {
// SAFETY: absolute value of nonzero cannot yield zero values.
unsafe { $Ty::new_unchecked(self.get().wrapping_abs()) }
unsafe { Self::new_unchecked(self.get().wrapping_abs()) }
}

/// Computes the absolute value of self
@@ -1250,10 +1255,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[inline]
#[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
#[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
pub const fn checked_neg(self) -> Option<$Ty> {
pub const fn checked_neg(self) -> Option<Self> {
if let Some(result) = self.get().checked_neg() {
// SAFETY: negation of nonzero cannot yield zero values.
return Some(unsafe { $Ty::new_unchecked(result) });
return Some(unsafe { Self::new_unchecked(result) });
}
None
}
@@ -1282,10 +1287,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[inline]
#[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
#[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
pub const fn overflowing_neg(self) -> ($Ty, bool) {
pub const fn overflowing_neg(self) -> (Self, bool) {
let (result, overflow) = self.get().overflowing_neg();
// SAFETY: negation of nonzero cannot yield zero values.
((unsafe { $Ty::new_unchecked(result) }), overflow)
((unsafe { Self::new_unchecked(result) }), overflow)
}

/// Saturating negation. Computes `-self`,
@@ -1317,11 +1322,11 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[inline]
#[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
#[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
pub const fn saturating_neg(self) -> $Ty {
pub const fn saturating_neg(self) -> Self {
if let Some(result) = self.checked_neg() {
return result;
}
$Ty::MAX
Self::MAX
}

/// Wrapping (modular) negation. Computes `-self`, wrapping around at the boundary
@@ -1349,10 +1354,10 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
#[inline]
#[stable(feature = "nonzero_negation_ops", since = "1.71.0")]
#[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")]
pub const fn wrapping_neg(self) -> $Ty {
pub const fn wrapping_neg(self) -> Self {
let result = self.get().wrapping_neg();
// SAFETY: negation of nonzero cannot yield zero values.
unsafe { $Ty::new_unchecked(result) }
unsafe { Self::new_unchecked(result) }
}
};
}