Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a4ce91c

Browse files
committedApr 12, 2025·
Auto merge of rust-lang#139717 - ChrisDenton:rollup-2233f1d, r=ChrisDenton
Rollup of 9 pull requests Successful merges: - rust-lang#137494 (libstd: init(): dup() subsequent /dev/nulls instead of opening them again) - rust-lang#138881 (Use the chaining methods on PartialOrd for slices too) - rust-lang#138972 (std: Fix build for NuttX targets) - rust-lang#139107 (std: make `cmath` functions safe) - rust-lang#139607 (Add regression test for rust-lang#127424) - rust-lang#139691 (Document that `opt-dist` requires metrics to be enabled) - rust-lang#139707 (Fix comment in bootstrap) - rust-lang#139708 (Fix name of field in doc comment) - rust-lang#139709 (bootstrap: fix typo in doc string) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9ffde4b + 7e59cc5 commit a4ce91c

File tree

18 files changed

+463
-187
lines changed

18 files changed

+463
-187
lines changed
 

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ pub enum PatKind<'hir> {
17561756
Never,
17571757

17581758
/// A tuple pattern (e.g., `(a, b)`).
1759-
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
1759+
/// If the `..` pattern fragment is present, then `DotDotPos` denotes its position.
17601760
/// `0 <= position <= subpats.len()`
17611761
Tuple(&'hir [Pat<'hir>], DotDotPos),
17621762

‎library/core/src/cmp.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,22 @@ mod impls {
20532053
fn ge(&self, other: &&B) -> bool {
20542054
PartialOrd::ge(*self, *other)
20552055
}
2056+
#[inline]
2057+
fn __chaining_lt(&self, other: &&B) -> ControlFlow<bool> {
2058+
PartialOrd::__chaining_lt(*self, *other)
2059+
}
2060+
#[inline]
2061+
fn __chaining_le(&self, other: &&B) -> ControlFlow<bool> {
2062+
PartialOrd::__chaining_le(*self, *other)
2063+
}
2064+
#[inline]
2065+
fn __chaining_gt(&self, other: &&B) -> ControlFlow<bool> {
2066+
PartialOrd::__chaining_gt(*self, *other)
2067+
}
2068+
#[inline]
2069+
fn __chaining_ge(&self, other: &&B) -> ControlFlow<bool> {
2070+
PartialOrd::__chaining_ge(*self, *other)
2071+
}
20562072
}
20572073
#[stable(feature = "rust1", since = "1.0.0")]
20582074
impl<A: ?Sized> Ord for &A
@@ -2108,6 +2124,22 @@ mod impls {
21082124
fn ge(&self, other: &&mut B) -> bool {
21092125
PartialOrd::ge(*self, *other)
21102126
}
2127+
#[inline]
2128+
fn __chaining_lt(&self, other: &&mut B) -> ControlFlow<bool> {
2129+
PartialOrd::__chaining_lt(*self, *other)
2130+
}
2131+
#[inline]
2132+
fn __chaining_le(&self, other: &&mut B) -> ControlFlow<bool> {
2133+
PartialOrd::__chaining_le(*self, *other)
2134+
}
2135+
#[inline]
2136+
fn __chaining_gt(&self, other: &&mut B) -> ControlFlow<bool> {
2137+
PartialOrd::__chaining_gt(*self, *other)
2138+
}
2139+
#[inline]
2140+
fn __chaining_ge(&self, other: &&mut B) -> ControlFlow<bool> {
2141+
PartialOrd::__chaining_ge(*self, *other)
2142+
}
21112143
}
21122144
#[stable(feature = "rust1", since = "1.0.0")]
21132145
impl<A: ?Sized> Ord for &mut A

‎library/core/src/slice/cmp.rs‎

Lines changed: 145 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::ascii;
55
use crate::cmp::{self, BytewiseEq, Ordering};
66
use crate::intrinsics::compare_bytes;
77
use crate::num::NonZero;
8+
use crate::ops::ControlFlow;
89

910
#[stable(feature = "rust1", since = "1.0.0")]
1011
impl<T, U> PartialEq<[U]> for [T]
@@ -31,12 +32,64 @@ impl<T: Ord> Ord for [T] {
3132
}
3233
}
3334

35+
#[inline]
36+
fn as_underlying(x: ControlFlow<bool>) -> u8 {
37+
// SAFETY: This will only compile if `bool` and `ControlFlow<bool>` have the same
38+
// size (which isn't guaranteed but this is libcore). Because they have the same
39+
// size, it's a niched implementation, which in one byte means there can't be
40+
// any uninitialized memory. The callers then only check for `0` or `1` from this,
41+
// which must necessarily match the `Break` variant, and we're fine no matter
42+
// what ends up getting picked as the value representing `Continue(())`.
43+
unsafe { crate::mem::transmute(x) }
44+
}
45+
3446
/// Implements comparison of slices [lexicographically](Ord#lexicographical-comparison).
3547
#[stable(feature = "rust1", since = "1.0.0")]
3648
impl<T: PartialOrd> PartialOrd for [T] {
49+
#[inline]
3750
fn partial_cmp(&self, other: &[T]) -> Option<Ordering> {
3851
SlicePartialOrd::partial_compare(self, other)
3952
}
53+
#[inline]
54+
fn lt(&self, other: &Self) -> bool {
55+
// This is certainly not the obvious way to implement these methods.
56+
// Unfortunately, using anything that looks at the discriminant means that
57+
// LLVM sees a check for `2` (aka `ControlFlow<bool>::Continue(())`) and
58+
// gets very distracted by that, ending up generating extraneous code.
59+
// This should be changed to something simpler once either LLVM is smarter,
60+
// see <https://github.com/llvm/llvm-project/issues/132678>, or we generate
61+
// niche discriminant checks in a way that doesn't trigger it.
62+
63+
as_underlying(self.__chaining_lt(other)) == 1
64+
}
65+
#[inline]
66+
fn le(&self, other: &Self) -> bool {
67+
as_underlying(self.__chaining_le(other)) != 0
68+
}
69+
#[inline]
70+
fn gt(&self, other: &Self) -> bool {
71+
as_underlying(self.__chaining_gt(other)) == 1
72+
}
73+
#[inline]
74+
fn ge(&self, other: &Self) -> bool {
75+
as_underlying(self.__chaining_ge(other)) != 0
76+
}
77+
#[inline]
78+
fn __chaining_lt(&self, other: &Self) -> ControlFlow<bool> {
79+
SliceChain::chaining_lt(self, other)
80+
}
81+
#[inline]
82+
fn __chaining_le(&self, other: &Self) -> ControlFlow<bool> {
83+
SliceChain::chaining_le(self, other)
84+
}
85+
#[inline]
86+
fn __chaining_gt(&self, other: &Self) -> ControlFlow<bool> {
87+
SliceChain::chaining_gt(self, other)
88+
}
89+
#[inline]
90+
fn __chaining_ge(&self, other: &Self) -> ControlFlow<bool> {
91+
SliceChain::chaining_ge(self, other)
92+
}
4093
}
4194

4295
#[doc(hidden)]
@@ -99,24 +152,63 @@ trait SlicePartialOrd: Sized {
99152
fn partial_compare(left: &[Self], right: &[Self]) -> Option<Ordering>;
100153
}
101154

155+
#[doc(hidden)]
156+
// intermediate trait for specialization of slice's PartialOrd chaining methods
157+
trait SliceChain: Sized {
158+
fn chaining_lt(left: &[Self], right: &[Self]) -> ControlFlow<bool>;
159+
fn chaining_le(left: &[Self], right: &[Self]) -> ControlFlow<bool>;
160+
fn chaining_gt(left: &[Self], right: &[Self]) -> ControlFlow<bool>;
161+
fn chaining_ge(left: &[Self], right: &[Self]) -> ControlFlow<bool>;
162+
}
163+
164+
type AlwaysBreak<B> = ControlFlow<B, crate::convert::Infallible>;
165+
102166
impl<A: PartialOrd> SlicePartialOrd for A {
103167
default fn partial_compare(left: &[A], right: &[A]) -> Option<Ordering> {
104-
let l = cmp::min(left.len(), right.len());
105-
106-
// Slice to the loop iteration range to enable bound check
107-
// elimination in the compiler
108-
let lhs = &left[..l];
109-
let rhs = &right[..l];
168+
let elem_chain = |a, b| match PartialOrd::partial_cmp(a, b) {
169+
Some(Ordering::Equal) => ControlFlow::Continue(()),
170+
non_eq => ControlFlow::Break(non_eq),
171+
};
172+
let len_chain = |a: &_, b: &_| ControlFlow::Break(usize::partial_cmp(a, b));
173+
let AlwaysBreak::Break(b) = chaining_impl(left, right, elem_chain, len_chain);
174+
b
175+
}
176+
}
110177

111-
for i in 0..l {
112-
match lhs[i].partial_cmp(&rhs[i]) {
113-
Some(Ordering::Equal) => (),
114-
non_eq => return non_eq,
115-
}
116-
}
178+
impl<A: PartialOrd> SliceChain for A {
179+
default fn chaining_lt(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
180+
chaining_impl(left, right, PartialOrd::__chaining_lt, usize::__chaining_lt)
181+
}
182+
default fn chaining_le(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
183+
chaining_impl(left, right, PartialOrd::__chaining_le, usize::__chaining_le)
184+
}
185+
default fn chaining_gt(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
186+
chaining_impl(left, right, PartialOrd::__chaining_gt, usize::__chaining_gt)
187+
}
188+
default fn chaining_ge(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
189+
chaining_impl(left, right, PartialOrd::__chaining_ge, usize::__chaining_ge)
190+
}
191+
}
117192

118-
left.len().partial_cmp(&right.len())
193+
#[inline]
194+
fn chaining_impl<'l, 'r, A: PartialOrd, B, C>(
195+
left: &'l [A],
196+
right: &'r [A],
197+
elem_chain: impl Fn(&'l A, &'r A) -> ControlFlow<B>,
198+
len_chain: impl for<'a> FnOnce(&'a usize, &'a usize) -> ControlFlow<B, C>,
199+
) -> ControlFlow<B, C> {
200+
let l = cmp::min(left.len(), right.len());
201+
202+
// Slice to the loop iteration range to enable bound check
203+
// elimination in the compiler
204+
let lhs = &left[..l];
205+
let rhs = &right[..l];
206+
207+
for i in 0..l {
208+
elem_chain(&lhs[i], &rhs[i])?;
119209
}
210+
211+
len_chain(&left.len(), &right.len())
120212
}
121213

122214
// This is the impl that we would like to have. Unfortunately it's not sound.
@@ -165,21 +257,13 @@ trait SliceOrd: Sized {
165257

166258
impl<A: Ord> SliceOrd for A {
167259
default fn compare(left: &[Self], right: &[Self]) -> Ordering {
168-
let l = cmp::min(left.len(), right.len());
169-
170-
// Slice to the loop iteration range to enable bound check
171-
// elimination in the compiler
172-
let lhs = &left[..l];
173-
let rhs = &right[..l];
174-
175-
for i in 0..l {
176-
match lhs[i].cmp(&rhs[i]) {
177-
Ordering::Equal => (),
178-
non_eq => return non_eq,
179-
}
180-
}
181-
182-
left.len().cmp(&right.len())
260+
let elem_chain = |a, b| match Ord::cmp(a, b) {
261+
Ordering::Equal => ControlFlow::Continue(()),
262+
non_eq => ControlFlow::Break(non_eq),
263+
};
264+
let len_chain = |a: &_, b: &_| ControlFlow::Break(usize::cmp(a, b));
265+
let AlwaysBreak::Break(b) = chaining_impl(left, right, elem_chain, len_chain);
266+
b
183267
}
184268
}
185269

@@ -191,7 +275,7 @@ impl<A: Ord> SliceOrd for A {
191275
/// * For every `x` and `y` of this type, `Ord(x, y)` must return the same
192276
/// value as `Ord::cmp(transmute::<_, u8>(x), transmute::<_, u8>(y))`.
193277
#[rustc_specialization_trait]
194-
unsafe trait UnsignedBytewiseOrd {}
278+
unsafe trait UnsignedBytewiseOrd: Ord {}
195279

196280
unsafe impl UnsignedBytewiseOrd for bool {}
197281
unsafe impl UnsignedBytewiseOrd for u8 {}
@@ -225,6 +309,38 @@ impl<A: Ord + UnsignedBytewiseOrd> SliceOrd for A {
225309
}
226310
}
227311

312+
// Don't generate our own chaining loops for `memcmp`-able things either.
313+
impl<A: PartialOrd + UnsignedBytewiseOrd> SliceChain for A {
314+
#[inline]
315+
fn chaining_lt(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
316+
match SliceOrd::compare(left, right) {
317+
Ordering::Equal => ControlFlow::Continue(()),
318+
ne => ControlFlow::Break(ne.is_lt()),
319+
}
320+
}
321+
#[inline]
322+
fn chaining_le(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
323+
match SliceOrd::compare(left, right) {
324+
Ordering::Equal => ControlFlow::Continue(()),
325+
ne => ControlFlow::Break(ne.is_le()),
326+
}
327+
}
328+
#[inline]
329+
fn chaining_gt(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
330+
match SliceOrd::compare(left, right) {
331+
Ordering::Equal => ControlFlow::Continue(()),
332+
ne => ControlFlow::Break(ne.is_gt()),
333+
}
334+
}
335+
#[inline]
336+
fn chaining_ge(left: &[Self], right: &[Self]) -> ControlFlow<bool> {
337+
match SliceOrd::compare(left, right) {
338+
Ordering::Equal => ControlFlow::Continue(()),
339+
ne => ControlFlow::Break(ne.is_ge()),
340+
}
341+
}
342+
}
343+
228344
pub(super) trait SliceContains: Sized {
229345
fn slice_contains(&self, x: &[Self]) -> bool;
230346
}

‎library/core/src/tuple.rs‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use crate::cmp::Ordering::{self, *};
44
use crate::marker::{ConstParamTy_, StructuralPartialEq, UnsizedConstParamTy};
5-
use crate::ops::ControlFlow::{Break, Continue};
5+
use crate::ops::ControlFlow::{self, Break, Continue};
66

77
// Recursive macro for implementing n-ary tuple functions and operations
88
//
@@ -95,6 +95,22 @@ macro_rules! tuple_impls {
9595
fn gt(&self, other: &($($T,)+)) -> bool {
9696
lexical_ord!(gt, __chaining_gt, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
9797
}
98+
#[inline]
99+
fn __chaining_lt(&self, other: &($($T,)+)) -> ControlFlow<bool> {
100+
lexical_chain!(__chaining_lt, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
101+
}
102+
#[inline]
103+
fn __chaining_le(&self, other: &($($T,)+)) -> ControlFlow<bool> {
104+
lexical_chain!(__chaining_le, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
105+
}
106+
#[inline]
107+
fn __chaining_gt(&self, other: &($($T,)+)) -> ControlFlow<bool> {
108+
lexical_chain!(__chaining_gt, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
109+
}
110+
#[inline]
111+
fn __chaining_ge(&self, other: &($($T,)+)) -> ControlFlow<bool> {
112+
lexical_chain!(__chaining_ge, $( ${ignore($T)} self.${index()}, other.${index()} ),+)
113+
}
98114
}
99115
}
100116

@@ -187,6 +203,17 @@ macro_rules! lexical_ord {
187203
};
188204
}
189205

206+
// Same parameter interleaving as `lexical_ord` above
207+
macro_rules! lexical_chain {
208+
($chain_rel: ident, $a:expr, $b:expr $(,$rest_a:expr, $rest_b:expr)*) => {{
209+
PartialOrd::$chain_rel(&$a, &$b)?;
210+
lexical_chain!($chain_rel $(,$rest_a, $rest_b)*)
211+
}};
212+
($chain_rel: ident) => {
213+
Continue(())
214+
};
215+
}
216+
190217
macro_rules! lexical_partial_cmp {
191218
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
192219
match ($a).partial_cmp(&$b) {

‎library/std/src/f128.rs‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl f128 {
666666
#[unstable(feature = "f128", issue = "116909")]
667667
#[must_use = "method returns a new number and does not mutate the original value"]
668668
pub fn cbrt(self) -> f128 {
669-
unsafe { cmath::cbrtf128(self) }
669+
cmath::cbrtf128(self)
670670
}
671671

672672
/// Compute the distance between the origin and a point (`x`, `y`) on the
@@ -703,7 +703,7 @@ impl f128 {
703703
#[unstable(feature = "f128", issue = "116909")]
704704
#[must_use = "method returns a new number and does not mutate the original value"]
705705
pub fn hypot(self, other: f128) -> f128 {
706-
unsafe { cmath::hypotf128(self, other) }
706+
cmath::hypotf128(self, other)
707707
}
708708

709709
/// Computes the sine of a number (in radians).
@@ -789,7 +789,7 @@ impl f128 {
789789
#[unstable(feature = "f128", issue = "116909")]
790790
#[must_use = "method returns a new number and does not mutate the original value"]
791791
pub fn tan(self) -> f128 {
792-
unsafe { cmath::tanf128(self) }
792+
cmath::tanf128(self)
793793
}
794794

795795
/// Computes the arcsine of a number. Return value is in radians in
@@ -824,7 +824,7 @@ impl f128 {
824824
#[unstable(feature = "f128", issue = "116909")]
825825
#[must_use = "method returns a new number and does not mutate the original value"]
826826
pub fn asin(self) -> f128 {
827-
unsafe { cmath::asinf128(self) }
827+
cmath::asinf128(self)
828828
}
829829

830830
/// Computes the arccosine of a number. Return value is in radians in
@@ -859,7 +859,7 @@ impl f128 {
859859
#[unstable(feature = "f128", issue = "116909")]
860860
#[must_use = "method returns a new number and does not mutate the original value"]
861861
pub fn acos(self) -> f128 {
862-
unsafe { cmath::acosf128(self) }
862+
cmath::acosf128(self)
863863
}
864864

865865
/// Computes the arctangent of a number. Return value is in radians in the
@@ -893,7 +893,7 @@ impl f128 {
893893
#[unstable(feature = "f128", issue = "116909")]
894894
#[must_use = "method returns a new number and does not mutate the original value"]
895895
pub fn atan(self) -> f128 {
896-
unsafe { cmath::atanf128(self) }
896+
cmath::atanf128(self)
897897
}
898898

899899
/// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
@@ -939,7 +939,7 @@ impl f128 {
939939
#[unstable(feature = "f128", issue = "116909")]
940940
#[must_use = "method returns a new number and does not mutate the original value"]
941941
pub fn atan2(self, other: f128) -> f128 {
942-
unsafe { cmath::atan2f128(self, other) }
942+
cmath::atan2f128(self, other)
943943
}
944944

945945
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
@@ -1008,7 +1008,7 @@ impl f128 {
10081008
#[unstable(feature = "f128", issue = "116909")]
10091009
#[must_use = "method returns a new number and does not mutate the original value"]
10101010
pub fn exp_m1(self) -> f128 {
1011-
unsafe { cmath::expm1f128(self) }
1011+
cmath::expm1f128(self)
10121012
}
10131013

10141014
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
@@ -1055,7 +1055,7 @@ impl f128 {
10551055
#[rustc_allow_incoherent_impl]
10561056
#[unstable(feature = "f128", issue = "116909")]
10571057
pub fn ln_1p(self) -> f128 {
1058-
unsafe { cmath::log1pf128(self) }
1058+
cmath::log1pf128(self)
10591059
}
10601060

10611061
/// Hyperbolic sine function.
@@ -1090,7 +1090,7 @@ impl f128 {
10901090
#[unstable(feature = "f128", issue = "116909")]
10911091
#[must_use = "method returns a new number and does not mutate the original value"]
10921092
pub fn sinh(self) -> f128 {
1093-
unsafe { cmath::sinhf128(self) }
1093+
cmath::sinhf128(self)
10941094
}
10951095

10961096
/// Hyperbolic cosine function.
@@ -1125,7 +1125,7 @@ impl f128 {
11251125
#[unstable(feature = "f128", issue = "116909")]
11261126
#[must_use = "method returns a new number and does not mutate the original value"]
11271127
pub fn cosh(self) -> f128 {
1128-
unsafe { cmath::coshf128(self) }
1128+
cmath::coshf128(self)
11291129
}
11301130

11311131
/// Hyperbolic tangent function.
@@ -1160,7 +1160,7 @@ impl f128 {
11601160
#[unstable(feature = "f128", issue = "116909")]
11611161
#[must_use = "method returns a new number and does not mutate the original value"]
11621162
pub fn tanh(self) -> f128 {
1163-
unsafe { cmath::tanhf128(self) }
1163+
cmath::tanhf128(self)
11641164
}
11651165

11661166
/// Inverse hyperbolic sine function.
@@ -1289,7 +1289,7 @@ impl f128 {
12891289
// #[unstable(feature = "float_gamma", issue = "99842")]
12901290
#[must_use = "method returns a new number and does not mutate the original value"]
12911291
pub fn gamma(self) -> f128 {
1292-
unsafe { cmath::tgammaf128(self) }
1292+
cmath::tgammaf128(self)
12931293
}
12941294

12951295
/// Natural logarithm of the absolute value of the gamma function
@@ -1325,7 +1325,7 @@ impl f128 {
13251325
#[must_use = "method returns a new number and does not mutate the original value"]
13261326
pub fn ln_gamma(self) -> (f128, i32) {
13271327
let mut signgamp: i32 = 0;
1328-
let x = unsafe { cmath::lgammaf128_r(self, &mut signgamp) };
1328+
let x = cmath::lgammaf128_r(self, &mut signgamp);
13291329
(x, signgamp)
13301330
}
13311331

@@ -1365,7 +1365,7 @@ impl f128 {
13651365
// #[unstable(feature = "float_erf", issue = "136321")]
13661366
#[inline]
13671367
pub fn erf(self) -> f128 {
1368-
unsafe { cmath::erff128(self) }
1368+
cmath::erff128(self)
13691369
}
13701370

13711371
/// Complementary error function.
@@ -1398,6 +1398,6 @@ impl f128 {
13981398
// #[unstable(feature = "float_erf", issue = "136321")]
13991399
#[inline]
14001400
pub fn erfc(self) -> f128 {
1401-
unsafe { cmath::erfcf128(self) }
1401+
cmath::erfcf128(self)
14021402
}
14031403
}

‎library/std/src/f16.rs‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl f16 {
665665
#[unstable(feature = "f16", issue = "116909")]
666666
#[must_use = "method returns a new number and does not mutate the original value"]
667667
pub fn cbrt(self) -> f16 {
668-
(unsafe { cmath::cbrtf(self as f32) }) as f16
668+
cmath::cbrtf(self as f32) as f16
669669
}
670670

671671
/// Compute the distance between the origin and a point (`x`, `y`) on the
@@ -701,7 +701,7 @@ impl f16 {
701701
#[unstable(feature = "f16", issue = "116909")]
702702
#[must_use = "method returns a new number and does not mutate the original value"]
703703
pub fn hypot(self, other: f16) -> f16 {
704-
(unsafe { cmath::hypotf(self as f32, other as f32) }) as f16
704+
cmath::hypotf(self as f32, other as f32) as f16
705705
}
706706

707707
/// Computes the sine of a number (in radians).
@@ -787,7 +787,7 @@ impl f16 {
787787
#[unstable(feature = "f16", issue = "116909")]
788788
#[must_use = "method returns a new number and does not mutate the original value"]
789789
pub fn tan(self) -> f16 {
790-
(unsafe { cmath::tanf(self as f32) }) as f16
790+
cmath::tanf(self as f32) as f16
791791
}
792792

793793
/// Computes the arcsine of a number. Return value is in radians in
@@ -822,7 +822,7 @@ impl f16 {
822822
#[unstable(feature = "f16", issue = "116909")]
823823
#[must_use = "method returns a new number and does not mutate the original value"]
824824
pub fn asin(self) -> f16 {
825-
(unsafe { cmath::asinf(self as f32) }) as f16
825+
cmath::asinf(self as f32) as f16
826826
}
827827

828828
/// Computes the arccosine of a number. Return value is in radians in
@@ -857,7 +857,7 @@ impl f16 {
857857
#[unstable(feature = "f16", issue = "116909")]
858858
#[must_use = "method returns a new number and does not mutate the original value"]
859859
pub fn acos(self) -> f16 {
860-
(unsafe { cmath::acosf(self as f32) }) as f16
860+
cmath::acosf(self as f32) as f16
861861
}
862862

863863
/// Computes the arctangent of a number. Return value is in radians in the
@@ -891,7 +891,7 @@ impl f16 {
891891
#[unstable(feature = "f16", issue = "116909")]
892892
#[must_use = "method returns a new number and does not mutate the original value"]
893893
pub fn atan(self) -> f16 {
894-
(unsafe { cmath::atanf(self as f32) }) as f16
894+
cmath::atanf(self as f32) as f16
895895
}
896896

897897
/// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
@@ -937,7 +937,7 @@ impl f16 {
937937
#[unstable(feature = "f16", issue = "116909")]
938938
#[must_use = "method returns a new number and does not mutate the original value"]
939939
pub fn atan2(self, other: f16) -> f16 {
940-
(unsafe { cmath::atan2f(self as f32, other as f32) }) as f16
940+
cmath::atan2f(self as f32, other as f32) as f16
941941
}
942942

943943
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
@@ -1006,7 +1006,7 @@ impl f16 {
10061006
#[unstable(feature = "f16", issue = "116909")]
10071007
#[must_use = "method returns a new number and does not mutate the original value"]
10081008
pub fn exp_m1(self) -> f16 {
1009-
(unsafe { cmath::expm1f(self as f32) }) as f16
1009+
cmath::expm1f(self as f32) as f16
10101010
}
10111011

10121012
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
@@ -1053,7 +1053,7 @@ impl f16 {
10531053
#[unstable(feature = "f16", issue = "116909")]
10541054
#[must_use = "method returns a new number and does not mutate the original value"]
10551055
pub fn ln_1p(self) -> f16 {
1056-
(unsafe { cmath::log1pf(self as f32) }) as f16
1056+
cmath::log1pf(self as f32) as f16
10571057
}
10581058

10591059
/// Hyperbolic sine function.
@@ -1088,7 +1088,7 @@ impl f16 {
10881088
#[unstable(feature = "f16", issue = "116909")]
10891089
#[must_use = "method returns a new number and does not mutate the original value"]
10901090
pub fn sinh(self) -> f16 {
1091-
(unsafe { cmath::sinhf(self as f32) }) as f16
1091+
cmath::sinhf(self as f32) as f16
10921092
}
10931093

10941094
/// Hyperbolic cosine function.
@@ -1123,7 +1123,7 @@ impl f16 {
11231123
#[unstable(feature = "f16", issue = "116909")]
11241124
#[must_use = "method returns a new number and does not mutate the original value"]
11251125
pub fn cosh(self) -> f16 {
1126-
(unsafe { cmath::coshf(self as f32) }) as f16
1126+
cmath::coshf(self as f32) as f16
11271127
}
11281128

11291129
/// Hyperbolic tangent function.
@@ -1158,7 +1158,7 @@ impl f16 {
11581158
#[unstable(feature = "f16", issue = "116909")]
11591159
#[must_use = "method returns a new number and does not mutate the original value"]
11601160
pub fn tanh(self) -> f16 {
1161-
(unsafe { cmath::tanhf(self as f32) }) as f16
1161+
cmath::tanhf(self as f32) as f16
11621162
}
11631163

11641164
/// Inverse hyperbolic sine function.
@@ -1287,7 +1287,7 @@ impl f16 {
12871287
// #[unstable(feature = "float_gamma", issue = "99842")]
12881288
#[must_use = "method returns a new number and does not mutate the original value"]
12891289
pub fn gamma(self) -> f16 {
1290-
(unsafe { cmath::tgammaf(self as f32) }) as f16
1290+
cmath::tgammaf(self as f32) as f16
12911291
}
12921292

12931293
/// Natural logarithm of the absolute value of the gamma function
@@ -1323,7 +1323,7 @@ impl f16 {
13231323
#[must_use = "method returns a new number and does not mutate the original value"]
13241324
pub fn ln_gamma(self) -> (f16, i32) {
13251325
let mut signgamp: i32 = 0;
1326-
let x = (unsafe { cmath::lgammaf_r(self as f32, &mut signgamp) }) as f16;
1326+
let x = cmath::lgammaf_r(self as f32, &mut signgamp) as f16;
13271327
(x, signgamp)
13281328
}
13291329

@@ -1363,7 +1363,7 @@ impl f16 {
13631363
// #[unstable(feature = "float_erf", issue = "136321")]
13641364
#[inline]
13651365
pub fn erf(self) -> f16 {
1366-
(unsafe { cmath::erff(self as f32) }) as f16
1366+
cmath::erff(self as f32) as f16
13671367
}
13681368

13691369
/// Complementary error function.
@@ -1396,6 +1396,6 @@ impl f16 {
13961396
// #[unstable(feature = "float_erf", issue = "136321")]
13971397
#[inline]
13981398
pub fn erfc(self) -> f16 {
1399-
(unsafe { cmath::erfcf(self as f32) }) as f16
1399+
cmath::erfcf(self as f32) as f16
14001400
}
14011401
}

‎library/std/src/f32.rs‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl f32 {
599599
filing an issue describing your use-case too)."
600600
)]
601601
pub fn abs_sub(self, other: f32) -> f32 {
602-
unsafe { cmath::fdimf(self, other) }
602+
cmath::fdimf(self, other)
603603
}
604604

605605
/// Returns the cube root of a number.
@@ -626,7 +626,7 @@ impl f32 {
626626
#[stable(feature = "rust1", since = "1.0.0")]
627627
#[inline]
628628
pub fn cbrt(self) -> f32 {
629-
unsafe { cmath::cbrtf(self) }
629+
cmath::cbrtf(self)
630630
}
631631

632632
/// Compute the distance between the origin and a point (`x`, `y`) on the
@@ -657,7 +657,7 @@ impl f32 {
657657
#[stable(feature = "rust1", since = "1.0.0")]
658658
#[inline]
659659
pub fn hypot(self, other: f32) -> f32 {
660-
unsafe { cmath::hypotf(self, other) }
660+
cmath::hypotf(self, other)
661661
}
662662

663663
/// Computes the sine of a number (in radians).
@@ -730,7 +730,7 @@ impl f32 {
730730
#[stable(feature = "rust1", since = "1.0.0")]
731731
#[inline]
732732
pub fn tan(self) -> f32 {
733-
unsafe { cmath::tanf(self) }
733+
cmath::tanf(self)
734734
}
735735

736736
/// Computes the arcsine of a number. Return value is in radians in
@@ -760,7 +760,7 @@ impl f32 {
760760
#[stable(feature = "rust1", since = "1.0.0")]
761761
#[inline]
762762
pub fn asin(self) -> f32 {
763-
unsafe { cmath::asinf(self) }
763+
cmath::asinf(self)
764764
}
765765

766766
/// Computes the arccosine of a number. Return value is in radians in
@@ -790,7 +790,7 @@ impl f32 {
790790
#[stable(feature = "rust1", since = "1.0.0")]
791791
#[inline]
792792
pub fn acos(self) -> f32 {
793-
unsafe { cmath::acosf(self) }
793+
cmath::acosf(self)
794794
}
795795

796796
/// Computes the arctangent of a number. Return value is in radians in the
@@ -819,7 +819,7 @@ impl f32 {
819819
#[stable(feature = "rust1", since = "1.0.0")]
820820
#[inline]
821821
pub fn atan(self) -> f32 {
822-
unsafe { cmath::atanf(self) }
822+
cmath::atanf(self)
823823
}
824824

825825
/// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
@@ -860,7 +860,7 @@ impl f32 {
860860
#[stable(feature = "rust1", since = "1.0.0")]
861861
#[inline]
862862
pub fn atan2(self, other: f32) -> f32 {
863-
unsafe { cmath::atan2f(self, other) }
863+
cmath::atan2f(self, other)
864864
}
865865

866866
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
@@ -919,7 +919,7 @@ impl f32 {
919919
#[stable(feature = "rust1", since = "1.0.0")]
920920
#[inline]
921921
pub fn exp_m1(self) -> f32 {
922-
unsafe { cmath::expm1f(self) }
922+
cmath::expm1f(self)
923923
}
924924

925925
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
@@ -957,7 +957,7 @@ impl f32 {
957957
#[stable(feature = "rust1", since = "1.0.0")]
958958
#[inline]
959959
pub fn ln_1p(self) -> f32 {
960-
unsafe { cmath::log1pf(self) }
960+
cmath::log1pf(self)
961961
}
962962

963963
/// Hyperbolic sine function.
@@ -987,7 +987,7 @@ impl f32 {
987987
#[stable(feature = "rust1", since = "1.0.0")]
988988
#[inline]
989989
pub fn sinh(self) -> f32 {
990-
unsafe { cmath::sinhf(self) }
990+
cmath::sinhf(self)
991991
}
992992

993993
/// Hyperbolic cosine function.
@@ -1017,7 +1017,7 @@ impl f32 {
10171017
#[stable(feature = "rust1", since = "1.0.0")]
10181018
#[inline]
10191019
pub fn cosh(self) -> f32 {
1020-
unsafe { cmath::coshf(self) }
1020+
cmath::coshf(self)
10211021
}
10221022

10231023
/// Hyperbolic tangent function.
@@ -1047,7 +1047,7 @@ impl f32 {
10471047
#[stable(feature = "rust1", since = "1.0.0")]
10481048
#[inline]
10491049
pub fn tanh(self) -> f32 {
1050-
unsafe { cmath::tanhf(self) }
1050+
cmath::tanhf(self)
10511051
}
10521052

10531053
/// Inverse hyperbolic sine function.
@@ -1158,7 +1158,7 @@ impl f32 {
11581158
#[unstable(feature = "float_gamma", issue = "99842")]
11591159
#[inline]
11601160
pub fn gamma(self) -> f32 {
1161-
unsafe { cmath::tgammaf(self) }
1161+
cmath::tgammaf(self)
11621162
}
11631163

11641164
/// Natural logarithm of the absolute value of the gamma function
@@ -1188,7 +1188,7 @@ impl f32 {
11881188
#[inline]
11891189
pub fn ln_gamma(self) -> (f32, i32) {
11901190
let mut signgamp: i32 = 0;
1191-
let x = unsafe { cmath::lgammaf_r(self, &mut signgamp) };
1191+
let x = cmath::lgammaf_r(self, &mut signgamp);
11921192
(x, signgamp)
11931193
}
11941194

@@ -1224,7 +1224,7 @@ impl f32 {
12241224
#[unstable(feature = "float_erf", issue = "136321")]
12251225
#[inline]
12261226
pub fn erf(self) -> f32 {
1227-
unsafe { cmath::erff(self) }
1227+
cmath::erff(self)
12281228
}
12291229

12301230
/// Complementary error function.
@@ -1253,6 +1253,6 @@ impl f32 {
12531253
#[unstable(feature = "float_erf", issue = "136321")]
12541254
#[inline]
12551255
pub fn erfc(self) -> f32 {
1256-
unsafe { cmath::erfcf(self) }
1256+
cmath::erfcf(self)
12571257
}
12581258
}

‎library/std/src/f64.rs‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl f64 {
599599
filing an issue describing your use-case too)."
600600
)]
601601
pub fn abs_sub(self, other: f64) -> f64 {
602-
unsafe { cmath::fdim(self, other) }
602+
cmath::fdim(self, other)
603603
}
604604

605605
/// Returns the cube root of a number.
@@ -626,7 +626,7 @@ impl f64 {
626626
#[stable(feature = "rust1", since = "1.0.0")]
627627
#[inline]
628628
pub fn cbrt(self) -> f64 {
629-
unsafe { cmath::cbrt(self) }
629+
cmath::cbrt(self)
630630
}
631631

632632
/// Compute the distance between the origin and a point (`x`, `y`) on the
@@ -657,7 +657,7 @@ impl f64 {
657657
#[stable(feature = "rust1", since = "1.0.0")]
658658
#[inline]
659659
pub fn hypot(self, other: f64) -> f64 {
660-
unsafe { cmath::hypot(self, other) }
660+
cmath::hypot(self, other)
661661
}
662662

663663
/// Computes the sine of a number (in radians).
@@ -730,7 +730,7 @@ impl f64 {
730730
#[stable(feature = "rust1", since = "1.0.0")]
731731
#[inline]
732732
pub fn tan(self) -> f64 {
733-
unsafe { cmath::tan(self) }
733+
cmath::tan(self)
734734
}
735735

736736
/// Computes the arcsine of a number. Return value is in radians in
@@ -760,7 +760,7 @@ impl f64 {
760760
#[stable(feature = "rust1", since = "1.0.0")]
761761
#[inline]
762762
pub fn asin(self) -> f64 {
763-
unsafe { cmath::asin(self) }
763+
cmath::asin(self)
764764
}
765765

766766
/// Computes the arccosine of a number. Return value is in radians in
@@ -790,7 +790,7 @@ impl f64 {
790790
#[stable(feature = "rust1", since = "1.0.0")]
791791
#[inline]
792792
pub fn acos(self) -> f64 {
793-
unsafe { cmath::acos(self) }
793+
cmath::acos(self)
794794
}
795795

796796
/// Computes the arctangent of a number. Return value is in radians in the
@@ -819,7 +819,7 @@ impl f64 {
819819
#[stable(feature = "rust1", since = "1.0.0")]
820820
#[inline]
821821
pub fn atan(self) -> f64 {
822-
unsafe { cmath::atan(self) }
822+
cmath::atan(self)
823823
}
824824

825825
/// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`) in radians.
@@ -860,7 +860,7 @@ impl f64 {
860860
#[stable(feature = "rust1", since = "1.0.0")]
861861
#[inline]
862862
pub fn atan2(self, other: f64) -> f64 {
863-
unsafe { cmath::atan2(self, other) }
863+
cmath::atan2(self, other)
864864
}
865865

866866
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
@@ -919,7 +919,7 @@ impl f64 {
919919
#[stable(feature = "rust1", since = "1.0.0")]
920920
#[inline]
921921
pub fn exp_m1(self) -> f64 {
922-
unsafe { cmath::expm1(self) }
922+
cmath::expm1(self)
923923
}
924924

925925
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
@@ -957,7 +957,7 @@ impl f64 {
957957
#[stable(feature = "rust1", since = "1.0.0")]
958958
#[inline]
959959
pub fn ln_1p(self) -> f64 {
960-
unsafe { cmath::log1p(self) }
960+
cmath::log1p(self)
961961
}
962962

963963
/// Hyperbolic sine function.
@@ -987,7 +987,7 @@ impl f64 {
987987
#[stable(feature = "rust1", since = "1.0.0")]
988988
#[inline]
989989
pub fn sinh(self) -> f64 {
990-
unsafe { cmath::sinh(self) }
990+
cmath::sinh(self)
991991
}
992992

993993
/// Hyperbolic cosine function.
@@ -1017,7 +1017,7 @@ impl f64 {
10171017
#[stable(feature = "rust1", since = "1.0.0")]
10181018
#[inline]
10191019
pub fn cosh(self) -> f64 {
1020-
unsafe { cmath::cosh(self) }
1020+
cmath::cosh(self)
10211021
}
10221022

10231023
/// Hyperbolic tangent function.
@@ -1047,7 +1047,7 @@ impl f64 {
10471047
#[stable(feature = "rust1", since = "1.0.0")]
10481048
#[inline]
10491049
pub fn tanh(self) -> f64 {
1050-
unsafe { cmath::tanh(self) }
1050+
cmath::tanh(self)
10511051
}
10521052

10531053
/// Inverse hyperbolic sine function.
@@ -1158,7 +1158,7 @@ impl f64 {
11581158
#[unstable(feature = "float_gamma", issue = "99842")]
11591159
#[inline]
11601160
pub fn gamma(self) -> f64 {
1161-
unsafe { cmath::tgamma(self) }
1161+
cmath::tgamma(self)
11621162
}
11631163

11641164
/// Natural logarithm of the absolute value of the gamma function
@@ -1188,7 +1188,7 @@ impl f64 {
11881188
#[inline]
11891189
pub fn ln_gamma(self) -> (f64, i32) {
11901190
let mut signgamp: i32 = 0;
1191-
let x = unsafe { cmath::lgamma_r(self, &mut signgamp) };
1191+
let x = cmath::lgamma_r(self, &mut signgamp);
11921192
(x, signgamp)
11931193
}
11941194

@@ -1224,7 +1224,7 @@ impl f64 {
12241224
#[unstable(feature = "float_erf", issue = "136321")]
12251225
#[inline]
12261226
pub fn erf(self) -> f64 {
1227-
unsafe { cmath::erf(self) }
1227+
cmath::erf(self)
12281228
}
12291229

12301230
/// Complementary error function.
@@ -1253,6 +1253,6 @@ impl f64 {
12531253
#[unstable(feature = "float_erf", issue = "136321")]
12541254
#[inline]
12551255
pub fn erfc(self) -> f64 {
1256-
unsafe { cmath::erfc(self) }
1256+
cmath::erfc(self)
12571257
}
12581258
}

‎library/std/src/sys/cmath.rs‎

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,70 @@
33
// These symbols are all defined by `libm`,
44
// or by `compiler-builtins` on unsupported platforms.
55
unsafe extern "C" {
6-
pub fn acos(n: f64) -> f64;
7-
pub fn asin(n: f64) -> f64;
8-
pub fn atan(n: f64) -> f64;
9-
pub fn atan2(a: f64, b: f64) -> f64;
10-
pub fn cbrt(n: f64) -> f64;
11-
pub fn cbrtf(n: f32) -> f32;
12-
pub fn cosh(n: f64) -> f64;
13-
pub fn expm1(n: f64) -> f64;
14-
pub fn expm1f(n: f32) -> f32;
15-
pub fn fdim(a: f64, b: f64) -> f64;
16-
pub fn fdimf(a: f32, b: f32) -> f32;
6+
pub safe fn acos(n: f64) -> f64;
7+
pub safe fn asin(n: f64) -> f64;
8+
pub safe fn atan(n: f64) -> f64;
9+
pub safe fn atan2(a: f64, b: f64) -> f64;
10+
pub safe fn cbrt(n: f64) -> f64;
11+
pub safe fn cbrtf(n: f32) -> f32;
12+
pub safe fn cosh(n: f64) -> f64;
13+
pub safe fn expm1(n: f64) -> f64;
14+
pub safe fn expm1f(n: f32) -> f32;
15+
pub safe fn fdim(a: f64, b: f64) -> f64;
16+
pub safe fn fdimf(a: f32, b: f32) -> f32;
1717
#[cfg_attr(target_env = "msvc", link_name = "_hypot")]
18-
pub fn hypot(x: f64, y: f64) -> f64;
18+
pub safe fn hypot(x: f64, y: f64) -> f64;
1919
#[cfg_attr(target_env = "msvc", link_name = "_hypotf")]
20-
pub fn hypotf(x: f32, y: f32) -> f32;
21-
pub fn log1p(n: f64) -> f64;
22-
pub fn log1pf(n: f32) -> f32;
23-
pub fn sinh(n: f64) -> f64;
24-
pub fn tan(n: f64) -> f64;
25-
pub fn tanh(n: f64) -> f64;
26-
pub fn tgamma(n: f64) -> f64;
27-
pub fn tgammaf(n: f32) -> f32;
28-
pub fn lgamma_r(n: f64, s: &mut i32) -> f64;
20+
pub safe fn hypotf(x: f32, y: f32) -> f32;
21+
pub safe fn log1p(n: f64) -> f64;
22+
pub safe fn log1pf(n: f32) -> f32;
23+
pub safe fn sinh(n: f64) -> f64;
24+
pub safe fn tan(n: f64) -> f64;
25+
pub safe fn tanh(n: f64) -> f64;
26+
pub safe fn tgamma(n: f64) -> f64;
27+
pub safe fn tgammaf(n: f32) -> f32;
28+
pub safe fn lgamma_r(n: f64, s: &mut i32) -> f64;
2929
#[cfg(not(target_os = "aix"))]
30-
pub fn lgammaf_r(n: f32, s: &mut i32) -> f32;
31-
pub fn erf(n: f64) -> f64;
32-
pub fn erff(n: f32) -> f32;
33-
pub fn erfc(n: f64) -> f64;
34-
pub fn erfcf(n: f32) -> f32;
30+
pub safe fn lgammaf_r(n: f32, s: &mut i32) -> f32;
31+
pub safe fn erf(n: f64) -> f64;
32+
pub safe fn erff(n: f32) -> f32;
33+
pub safe fn erfc(n: f64) -> f64;
34+
pub safe fn erfcf(n: f32) -> f32;
3535

36-
pub fn acosf128(n: f128) -> f128;
37-
pub fn asinf128(n: f128) -> f128;
38-
pub fn atanf128(n: f128) -> f128;
39-
pub fn atan2f128(a: f128, b: f128) -> f128;
40-
pub fn cbrtf128(n: f128) -> f128;
41-
pub fn coshf128(n: f128) -> f128;
42-
pub fn expm1f128(n: f128) -> f128;
43-
pub fn hypotf128(x: f128, y: f128) -> f128;
44-
pub fn log1pf128(n: f128) -> f128;
45-
pub fn sinhf128(n: f128) -> f128;
46-
pub fn tanf128(n: f128) -> f128;
47-
pub fn tanhf128(n: f128) -> f128;
48-
pub fn tgammaf128(n: f128) -> f128;
49-
pub fn lgammaf128_r(n: f128, s: &mut i32) -> f128;
50-
pub fn erff128(n: f128) -> f128;
51-
pub fn erfcf128(n: f128) -> f128;
36+
pub safe fn acosf128(n: f128) -> f128;
37+
pub safe fn asinf128(n: f128) -> f128;
38+
pub safe fn atanf128(n: f128) -> f128;
39+
pub safe fn atan2f128(a: f128, b: f128) -> f128;
40+
pub safe fn cbrtf128(n: f128) -> f128;
41+
pub safe fn coshf128(n: f128) -> f128;
42+
pub safe fn expm1f128(n: f128) -> f128;
43+
pub safe fn hypotf128(x: f128, y: f128) -> f128;
44+
pub safe fn log1pf128(n: f128) -> f128;
45+
pub safe fn sinhf128(n: f128) -> f128;
46+
pub safe fn tanf128(n: f128) -> f128;
47+
pub safe fn tanhf128(n: f128) -> f128;
48+
pub safe fn tgammaf128(n: f128) -> f128;
49+
pub safe fn lgammaf128_r(n: f128, s: &mut i32) -> f128;
50+
pub safe fn erff128(n: f128) -> f128;
51+
pub safe fn erfcf128(n: f128) -> f128;
5252

5353
cfg_if::cfg_if! {
5454
if #[cfg(not(all(target_os = "windows", target_env = "msvc", target_arch = "x86")))] {
55-
pub fn acosf(n: f32) -> f32;
56-
pub fn asinf(n: f32) -> f32;
57-
pub fn atan2f(a: f32, b: f32) -> f32;
58-
pub fn atanf(n: f32) -> f32;
59-
pub fn coshf(n: f32) -> f32;
60-
pub fn sinhf(n: f32) -> f32;
61-
pub fn tanf(n: f32) -> f32;
62-
pub fn tanhf(n: f32) -> f32;
55+
pub safe fn acosf(n: f32) -> f32;
56+
pub safe fn asinf(n: f32) -> f32;
57+
pub safe fn atan2f(a: f32, b: f32) -> f32;
58+
pub safe fn atanf(n: f32) -> f32;
59+
pub safe fn coshf(n: f32) -> f32;
60+
pub safe fn sinhf(n: f32) -> f32;
61+
pub safe fn tanf(n: f32) -> f32;
62+
pub safe fn tanhf(n: f32) -> f32;
6363
}}
6464
}
6565

6666
// On AIX, we don't have lgammaf_r only the f64 version, so we can
6767
// use the f64 version lgamma_r
6868
#[cfg(target_os = "aix")]
69-
pub unsafe fn lgammaf_r(n: f32, s: &mut i32) -> f32 {
69+
pub fn lgammaf_r(n: f32, s: &mut i32) -> f32 {
7070
lgamma_r(n.into(), s) as f32
7171
}
7272

@@ -76,42 +76,42 @@ pub unsafe fn lgammaf_r(n: f32, s: &mut i32) -> f32 {
7676
cfg_if::cfg_if! {
7777
if #[cfg(all(target_os = "windows", target_env = "msvc", target_arch = "x86"))] {
7878
#[inline]
79-
pub unsafe fn acosf(n: f32) -> f32 {
79+
pub fn acosf(n: f32) -> f32 {
8080
f64::acos(n as f64) as f32
8181
}
8282

8383
#[inline]
84-
pub unsafe fn asinf(n: f32) -> f32 {
84+
pub fn asinf(n: f32) -> f32 {
8585
f64::asin(n as f64) as f32
8686
}
8787

8888
#[inline]
89-
pub unsafe fn atan2f(n: f32, b: f32) -> f32 {
89+
pub fn atan2f(n: f32, b: f32) -> f32 {
9090
f64::atan2(n as f64, b as f64) as f32
9191
}
9292

9393
#[inline]
94-
pub unsafe fn atanf(n: f32) -> f32 {
94+
pub fn atanf(n: f32) -> f32 {
9595
f64::atan(n as f64) as f32
9696
}
9797

9898
#[inline]
99-
pub unsafe fn coshf(n: f32) -> f32 {
99+
pub fn coshf(n: f32) -> f32 {
100100
f64::cosh(n as f64) as f32
101101
}
102102

103103
#[inline]
104-
pub unsafe fn sinhf(n: f32) -> f32 {
104+
pub fn sinhf(n: f32) -> f32 {
105105
f64::sinh(n as f64) as f32
106106
}
107107

108108
#[inline]
109-
pub unsafe fn tanf(n: f32) -> f32 {
109+
pub fn tanf(n: f32) -> f32 {
110110
f64::tan(n as f64) as f32
111111
}
112112

113113
#[inline]
114-
pub unsafe fn tanhf(n: f32) -> f32 {
114+
pub fn tanhf(n: f32) -> f32 {
115115
f64::tanh(n as f64) as f32
116116
}
117117
}}

‎library/std/src/sys/fd/unix.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ const fn max_iov() -> usize {
7171
target_os = "android",
7272
target_os = "dragonfly",
7373
target_os = "emscripten",
74+
target_os = "espidf",
7475
target_os = "freebsd",
7576
target_os = "linux",
7677
target_os = "netbsd",
78+
target_os = "nuttx",
7779
target_os = "nto",
7880
target_os = "openbsd",
7981
target_os = "horizon",

‎library/std/src/sys/net/connection/socket/unix.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use libc::{MSG_PEEK, c_int, c_void, size_t, sockaddr, socklen_t};
22

3+
#[cfg(not(any(target_os = "espidf", target_os = "nuttx")))]
34
use crate::ffi::CStr;
45
use crate::io::{self, BorrowedBuf, BorrowedCursor, IoSlice, IoSliceMut};
56
use crate::net::{Shutdown, SocketAddr};

‎library/std/src/sys/pal/unix/mod.rs‎

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
5959
}
6060

6161
unsafe fn sanitize_standard_fds() {
62+
#[allow(dead_code)]
63+
let mut opened_devnull = -1;
64+
#[allow(dead_code)]
65+
let mut open_devnull = || {
66+
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
67+
use libc::open;
68+
#[cfg(all(target_os = "linux", target_env = "gnu"))]
69+
use libc::open64 as open;
70+
71+
if opened_devnull != -1 {
72+
if libc::dup(opened_devnull) != -1 {
73+
return;
74+
}
75+
}
76+
opened_devnull = open(c"/dev/null".as_ptr(), libc::O_RDWR, 0);
77+
if opened_devnull == -1 {
78+
// If the stream is closed but we failed to reopen it, abort the
79+
// process. Otherwise we wouldn't preserve the safety of
80+
// operations on the corresponding Rust object Stdin, Stdout, or
81+
// Stderr.
82+
libc::abort();
83+
}
84+
};
85+
6286
// fast path with a single syscall for systems with poll()
6387
#[cfg(not(any(
6488
miri,
@@ -74,11 +98,6 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
7498
target_vendor = "apple",
7599
)))]
76100
'poll: {
77-
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
78-
use libc::open as open64;
79-
#[cfg(all(target_os = "linux", target_env = "gnu"))]
80-
use libc::open64;
81-
82101
use crate::sys::os::errno;
83102
let pfds: &mut [_] = &mut [
84103
libc::pollfd { fd: 0, events: 0, revents: 0 },
@@ -106,13 +125,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
106125
if pfd.revents & libc::POLLNVAL == 0 {
107126
continue;
108127
}
109-
if open64(c"/dev/null".as_ptr(), libc::O_RDWR, 0) == -1 {
110-
// If the stream is closed but we failed to reopen it, abort the
111-
// process. Otherwise we wouldn't preserve the safety of
112-
// operations on the corresponding Rust object Stdin, Stdout, or
113-
// Stderr.
114-
libc::abort();
115-
}
128+
open_devnull();
116129
}
117130
return;
118131
}
@@ -129,21 +142,10 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
129142
target_os = "vita",
130143
)))]
131144
{
132-
#[cfg(not(all(target_os = "linux", target_env = "gnu")))]
133-
use libc::open as open64;
134-
#[cfg(all(target_os = "linux", target_env = "gnu"))]
135-
use libc::open64;
136-
137145
use crate::sys::os::errno;
138146
for fd in 0..3 {
139147
if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
140-
if open64(c"/dev/null".as_ptr(), libc::O_RDWR, 0) == -1 {
141-
// If the stream is closed but we failed to reopen it, abort the
142-
// process. Otherwise we wouldn't preserve the safety of
143-
// operations on the corresponding Rust object Stdin, Stdout, or
144-
// Stderr.
145-
libc::abort();
146-
}
148+
open_devnull();
147149
}
148150
}
149151
}

‎src/bootstrap/src/core/build_steps/tool.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ impl Step for ToolBuild {
150150

151151
// Rustc tools (miri, clippy, cargo, rustfmt, rust-analyzer)
152152
// could use the additional optimizations.
153-
if self.mode == Mode::ToolRustc &&
154-
// rustdoc is performance sensitive, so apply LTO to it.
155-
is_lto_stage(&self.compiler)
156-
{
153+
if self.mode == Mode::ToolRustc && is_lto_stage(&self.compiler) {
157154
let lto = match builder.config.rust_lto {
158155
RustcLto::Off => Some("off"),
159156
RustcLto::Thin => Some("thin"),

‎src/bootstrap/src/core/download.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ enum DownloadSource {
417417
Dist,
418418
}
419419

420-
/// Functions that are only ever called once, but named for clarify and to avoid thousand-line functions.
420+
/// Functions that are only ever called once, but named for clarity and to avoid thousand-line functions.
421421
impl Config {
422422
pub(crate) fn download_clippy(&self) -> PathBuf {
423423
self.verbose(|| println!("downloading stage0 clippy artifacts"));

‎src/doc/rustc-dev-guide/src/building/optimized-build.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ like Python or LLVM.
109109

110110
Here is an example of how can `opt-dist` be used locally (outside of CI):
111111

112-
1. Build the tool with the following command:
112+
1. Enable metrics in your `bootstrap.toml` file, because `opt-dist` expects it to be enabled:
113+
```toml
114+
[build]
115+
metrics = true
116+
```
117+
2. Build the tool with the following command:
113118
```bash
114119
./x build tools/opt-dist
115120
```
116-
2. Run the tool with the `local` mode and provide necessary parameters:
121+
3. Run the tool with the `local` mode and provide necessary parameters:
117122
```bash
118123
./build/host/stage0-tools-bin/opt-dist local \
119124
--target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu"

‎tests/codegen/array-cmp.rs‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Ensure the asm for array comparisons is properly optimized.
22

33
//@ compile-flags: -C opt-level=2
4+
//@ needs-deterministic-layouts (checks depend on tuple layout)
45

56
#![crate_type = "lib"]
67

@@ -17,3 +18,57 @@ pub fn compare() -> bool {
1718
[0x00, 0x00, 0x48, 0x41]
1819
}
1920
}
21+
22+
// CHECK-LABEL: @array_of_tuple_le
23+
#[no_mangle]
24+
pub fn array_of_tuple_le(a: &[(i16, u16); 2], b: &[(i16, u16); 2]) -> bool {
25+
// Ensure that, after all the optimizations have run, the happy path just checks
26+
// `eq` on each corresponding pair and moves onto the next one if it is.
27+
// Then there's a dedup'd comparison for the place that's different.
28+
// (As opposed to, say, running a full `[su]cmp` as part of checking equality.)
29+
30+
// This is written quite specifically because different library code was triggering
31+
// <https://github.com/llvm/llvm-project/issues/132678> along the way, so this
32+
// has enough checks to make sure that's not happening. It doesn't need to be
33+
// *exactly* this IR, but be careful if you ever need to update these checks.
34+
35+
// CHECK: start:
36+
// CHECK: %[[A00:.+]] = load i16, ptr %a
37+
// CHECK: %[[B00:.+]] = load i16, ptr %b
38+
// CHECK-NOT: cmp
39+
// CHECK: %[[EQ00:.+]] = icmp eq i16 %[[A00]], %[[B00]]
40+
// CHECK-NEXT: br i1 %[[EQ00]], label %[[L01:.+]], label %[[EXIT_S:.+]]
41+
42+
// CHECK: [[L01]]:
43+
// CHECK: %[[PA01:.+]] = getelementptr{{.+}}i8, ptr %a, i64 2
44+
// CHECK: %[[PB01:.+]] = getelementptr{{.+}}i8, ptr %b, i64 2
45+
// CHECK: %[[A01:.+]] = load i16, ptr %[[PA01]]
46+
// CHECK: %[[B01:.+]] = load i16, ptr %[[PB01]]
47+
// CHECK-NOT: cmp
48+
// CHECK: %[[EQ01:.+]] = icmp eq i16 %[[A01]], %[[B01]]
49+
// CHECK-NEXT: br i1 %[[EQ01]], label %[[L10:.+]], label %[[EXIT_U:.+]]
50+
51+
// CHECK: [[L10]]:
52+
// CHECK: %[[PA10:.+]] = getelementptr{{.+}}i8, ptr %a, i64 4
53+
// CHECK: %[[PB10:.+]] = getelementptr{{.+}}i8, ptr %b, i64 4
54+
// CHECK: %[[A10:.+]] = load i16, ptr %[[PA10]]
55+
// CHECK: %[[B10:.+]] = load i16, ptr %[[PB10]]
56+
// CHECK-NOT: cmp
57+
// CHECK: %[[EQ10:.+]] = icmp eq i16 %[[A10]], %[[B10]]
58+
// CHECK-NEXT: br i1 %[[EQ10]], label %[[L11:.+]], label %[[EXIT_S]]
59+
60+
// CHECK: [[L11]]:
61+
// CHECK: %[[PA11:.+]] = getelementptr{{.+}}i8, ptr %a, i64 6
62+
// CHECK: %[[PB11:.+]] = getelementptr{{.+}}i8, ptr %b, i64 6
63+
// CHECK: %[[A11:.+]] = load i16, ptr %[[PA11]]
64+
// CHECK: %[[B11:.+]] = load i16, ptr %[[PB11]]
65+
// CHECK-NOT: cmp
66+
// CHECK: %[[EQ11:.+]] = icmp eq i16 %[[A11]], %[[B11]]
67+
// CHECK-NEXT: br i1 %[[EQ11]], label %[[DONE:.+]], label %[[EXIT_U]]
68+
69+
// CHECK: [[DONE]]:
70+
// CHECK: %[[RET:.+]] = phi i1 [ %{{.+}}, %[[EXIT_S]] ], [ %{{.+}}, %[[EXIT_U]] ], [ true, %[[L11]] ]
71+
// CHECK: ret i1 %[[RET]]
72+
73+
a <= b
74+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for issue #127424
2+
3+
fn bar() -> impl Into<
4+
[u8; {
5+
//~^ ERROR mismatched types [E0308]
6+
let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { *x };
7+
//~^ ERROR `for<...>` binders for closures are experimental [E0658]
8+
}],
9+
> {
10+
[89]
11+
}
12+
13+
fn main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0658]: `for<...>` binders for closures are experimental
2+
--> $DIR/const-generics-closure.rs:6:17
3+
|
4+
LL | let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { *x };
5+
| ^^^^^^^^^^^
6+
|
7+
= note: see issue #97362 <https://github.com/rust-lang/rust/issues/97362> for more information
8+
= help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= help: consider removing `for<...>`
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/const-generics-closure.rs:4:10
14+
|
15+
LL | [u8; {
16+
| __________^
17+
LL | |
18+
LL | | let _ = for<'a, 'b> |x: &'a &'a Vec<&'b u32>, b: bool| -> &'a Vec<&'b u32> { *x };
19+
LL | |
20+
LL | | }],
21+
| |_____^ expected `usize`, found `()`
22+
23+
error: aborting due to 2 previous errors
24+
25+
Some errors have detailed explanations: E0308, E0658.
26+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)
This repository has been archived.