Skip to content

Commit ac287ed

Browse files
committed
Auto merge of #50546 - kennytm:rollup, r=kennytm
Rollup of 11 pull requests Successful merges: - #49988 (Mention Result<!, E> in never docs.) - #50148 (turn `ManuallyDrop::new` into a constant function) - #50456 (Update the Cargo submodule) - #50460 (Make `String::new()` const) - #50464 (Remove some transmutes) - #50505 (Added regression function match value test) - #50511 (Add some explanations for #[must_use]) - #50525 (Optimize string handling in lit_token().) - #50527 (Cleanup a `use` in a raw_vec test) - #50539 (Add more logarithm constants) - #49523 (Update RELEASES.md for 1.26.0) Failed merges:
2 parents 8ff4b42 + 99cd9a9 commit ac287ed

File tree

21 files changed

+354
-31
lines changed

21 files changed

+354
-31
lines changed

RELEASES.md

+206
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,209 @@
1+
Version 1.26.0 (2018-05-10)
2+
==========================
3+
4+
Language
5+
--------
6+
- [Closures now implement `Copy` and/or `Clone` if all captured variables
7+
implement either or both traits.][49299]
8+
- [The inclusive range syntax e.g. `for x in 0..=10` is now stable.][47813]
9+
- [Stablise `'_`. The underscore lifetime can be used anywhere where a
10+
lifetime can be elided.][49458]
11+
- [`impl Trait` is now stable allowing you to have abstract types in returns
12+
or in function parameters.][49255] e.g. `fn foo() -> impl Iterator<Item=u8>` or
13+
`fn open(path: impl AsRef<Path>)`.
14+
- [Pattern matching will now automatically apply dereferences.][49394]
15+
- [128-bit integers in the form of `u128` and `i128` are now stable.][49101]
16+
- [`main` can now return `Result<(), E: Debug>`][49162] in addition to `()`.
17+
- [A lot of operations are now available in a const context.][46882] E.g. You
18+
can now index into constant arrays, reference and dereference into constants,
19+
and use Tuple struct constructors.
20+
- [Fixed entry slice patterns are now stable.][48516] e.g.
21+
```rust
22+
let points = [1, 2, 3, 4];
23+
match points {
24+
[1, 2, 3, 4] => println!("All points were sequential."),
25+
_ => println!("Not all points were sequential."),
26+
}
27+
```
28+
29+
30+
Compiler
31+
--------
32+
- [LLD is now used as the default linker for `wasm32-unknown-unknown`.][48125]
33+
- [Fixed exponential projection complexity on nested types.][48296]
34+
This can provide up to a ~12% reduction in compile times for certain crates.
35+
- [Added the `--remap-path-prefix` option to rustc.][48359] Allowing you
36+
to remap path prefixes outputted by the compiler.
37+
- [Added `powerpc-unknown-netbsd` target.][48281]
38+
39+
Libraries
40+
---------
41+
- [Implemented `From<u16> for usize` & `From<{u8, i16}> for isize`.][49305]
42+
- [Added hexadecimal formatting for integers with fmt::Debug][48978]
43+
e.g. `assert!(format!("{:02x?}", b"Foo\0") == "[46, 6f, 6f, 00]")`
44+
- [Implemented `Default, Hash` for `cmp::Reverse`.][48628]
45+
- [Optimized `str::repeat` being 8x faster in large cases.][48657]
46+
- [`ascii::escape_default` is now available in libcore.][48735]
47+
- [Trailing commas are now supported in std and core macros.][48056]
48+
- [Implemented `Copy, Clone` for `cmp::Reverse`][47379]
49+
- [Implemented `Clone` for `char::{ToLowercase, ToUppercase}`.][48629]
50+
51+
Stabilized APIs
52+
---------------
53+
- [`*const T::add`]
54+
- [`*const T::copy_to_nonoverlapping`]
55+
- [`*const T::copy_to`]
56+
- [`*const T::read_unaligned`]
57+
- [`*const T::read_volatile`]
58+
- [`*const T::read`]
59+
- [`*const T::sub`]
60+
- [`*const T::wrapping_add`]
61+
- [`*const T::wrapping_sub`]
62+
- [`*mut T::add`]
63+
- [`*mut T::copy_to_nonoverlapping`]
64+
- [`*mut T::copy_to`]
65+
- [`*mut T::read_unaligned`]
66+
- [`*mut T::read_volatile`]
67+
- [`*mut T::read`]
68+
- [`*mut T::replace`]
69+
- [`*mut T::sub`]
70+
- [`*mut T::swap`]
71+
- [`*mut T::wrapping_add`]
72+
- [`*mut T::wrapping_sub`]
73+
- [`*mut T::write_bytes`]
74+
- [`*mut T::write_unaligned`]
75+
- [`*mut T::write_volatile`]
76+
- [`*mut T::write`]
77+
- [`Box::leak`]
78+
- [`FromUtf8Error::as_bytes`]
79+
- [`LocalKey::try_with`]
80+
- [`Option::cloned`]
81+
- [`btree_map::Entry::and_modify`]
82+
- [`fs::read_to_string`]
83+
- [`fs::read`]
84+
- [`fs::write`]
85+
- [`hash_map::Entry::and_modify`]
86+
- [`iter::FusedIterator`]
87+
- [`ops::RangeInclusive`]
88+
- [`ops::RangeToInclusive`]
89+
- [`process::id`]
90+
- [`slice::rotate_left`]
91+
- [`slice::rotate_right`]
92+
- [`String::retain`]
93+
94+
95+
Cargo
96+
-----
97+
- [Cargo will now output path to custom commands when `-v` is
98+
passed with `--list`][cargo/5041]
99+
- [The Cargo binary version is now the same as the Rust version][cargo/5083]
100+
- [`Cargo.lock` files are now included in published crates.][cargo/5093]
101+
102+
Misc
103+
----
104+
- [The second edition of "The Rust Programming Language" book is now recommended
105+
over the first.][48404]
106+
107+
Compatibility Notes
108+
-------------------
109+
110+
- [aliasing a `Fn` trait as `dyn` no longer works.][48481] E.g. the following
111+
syntax is now invalid.
112+
```
113+
use std::ops::Fn as dyn;
114+
fn g(_: Box<dyn(std::fmt::Debug)>) {}
115+
```
116+
- [The result of dereferences are no longer promoted to `'static`.][47408]
117+
e.g.
118+
```rust
119+
fn main() {
120+
const PAIR: &(i32, i32) = &(0, 1);
121+
let _reversed_pair: &'static _ = &(PAIR.1, PAIR.0); // Doesn't work
122+
}
123+
```
124+
- [Deprecate `AsciiExt` trait in favor of inherent methods.][49109]
125+
- [`".e0"` will now no longer parse as `0.0` and will instead cause
126+
an error.][48235]
127+
- [Removed hoedown from rustdoc.][48274]
128+
- [Bounds on higher-kinded lifetimes a hard error.][48326]
129+
130+
[46882]: https://github.com/rust-lang/rust/pull/46882
131+
[47379]: https://github.com/rust-lang/rust/pull/47379
132+
[47408]: https://github.com/rust-lang/rust/pull/47408
133+
[47813]: https://github.com/rust-lang/rust/pull/47813
134+
[48056]: https://github.com/rust-lang/rust/pull/48056
135+
[48125]: https://github.com/rust-lang/rust/pull/48125
136+
[48166]: https://github.com/rust-lang/rust/pull/48166
137+
[48235]: https://github.com/rust-lang/rust/pull/48235
138+
[48274]: https://github.com/rust-lang/rust/pull/48274
139+
[48281]: https://github.com/rust-lang/rust/pull/48281
140+
[48296]: https://github.com/rust-lang/rust/pull/48296
141+
[48326]: https://github.com/rust-lang/rust/pull/48326
142+
[48359]: https://github.com/rust-lang/rust/pull/48359
143+
[48404]: https://github.com/rust-lang/rust/pull/48404
144+
[48481]: https://github.com/rust-lang/rust/pull/48481
145+
[48516]: https://github.com/rust-lang/rust/pull/48516
146+
[48628]: https://github.com/rust-lang/rust/pull/48628
147+
[48629]: https://github.com/rust-lang/rust/pull/48629
148+
[48657]: https://github.com/rust-lang/rust/pull/48657
149+
[48735]: https://github.com/rust-lang/rust/pull/48735
150+
[48978]: https://github.com/rust-lang/rust/pull/48978
151+
[49101]: https://github.com/rust-lang/rust/pull/49101
152+
[49109]: https://github.com/rust-lang/rust/pull/49109
153+
[49121]: https://github.com/rust-lang/rust/pull/49121
154+
[49162]: https://github.com/rust-lang/rust/pull/49162
155+
[49184]: https://github.com/rust-lang/rust/pull/49184
156+
[49234]: https://github.com/rust-lang/rust/pull/49234
157+
[49255]: https://github.com/rust-lang/rust/pull/49255
158+
[49299]: https://github.com/rust-lang/rust/pull/49299
159+
[49305]: https://github.com/rust-lang/rust/pull/49305
160+
[49394]: https://github.com/rust-lang/rust/pull/49394
161+
[49458]: https://github.com/rust-lang/rust/pull/49458
162+
[`*const T::add`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.add
163+
[`*const T::copy_to_nonoverlapping`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.copy_to_nonoverlapping
164+
[`*const T::copy_to`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.copy_to
165+
[`*const T::read_unaligned`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.read_unaligned
166+
[`*const T::read_volatile`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.read_volatile
167+
[`*const T::read`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.read
168+
[`*const T::sub`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.sub
169+
[`*const T::wrapping_add`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_add
170+
[`*const T::wrapping_sub`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_sub
171+
[`*mut T::add`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.add-1
172+
[`*mut T::copy_to_nonoverlapping`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.copy_to_nonoverlapping-1
173+
[`*mut T::copy_to`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.copy_to-1
174+
[`*mut T::read_unaligned`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.read_unaligned-1
175+
[`*mut T::read_volatile`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.read_volatile-1
176+
[`*mut T::read`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.read-1
177+
[`*mut T::replace`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.replace
178+
[`*mut T::sub`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.sub-1
179+
[`*mut T::swap`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.swap
180+
[`*mut T::wrapping_add`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_add-1
181+
[`*mut T::wrapping_sub`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_sub-1
182+
[`*mut T::write_bytes`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.write_bytes
183+
[`*mut T::write_unaligned`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.write_unaligned
184+
[`*mut T::write_volatile`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.write_volatile
185+
[`*mut T::write`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.write
186+
[`Box::leak`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.leak
187+
[`FromUtf8Error::as_bytes`]: https://doc.rust-lang.org/std/string/struct.FromUtf8Error.html#method.as_bytes
188+
[`LocalKey::try_with`]: https://doc.rust-lang.org/std/thread/struct.LocalKey.html#method.try_with
189+
[`Option::cloned`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.cloned
190+
[`btree_map::Entry::and_modify`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.and_modify
191+
[`fs::read_to_string`]: https://doc.rust-lang.org/std/fs/fn.read_to_string.html
192+
[`fs::read`]: https://doc.rust-lang.org/std/fs/fn.read.html
193+
[`fs::write`]: https://doc.rust-lang.org/std/fs/fn.write.html
194+
[`hash_map::Entry::and_modify`]: https://doc.rust-lang.org/std/collections/hash_map/enum.Entry.html#method.and_modify
195+
[`iter::FusedIterator`]: https://doc.rust-lang.org/std/iter/trait.FusedIterator.html
196+
[`ops::RangeInclusive`]: https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html
197+
[`ops::RangeToInclusive`]: https://doc.rust-lang.org/std/ops/struct.RangeToInclusive.html
198+
[`process::id`]: https://doc.rust-lang.org/std/process/fn.id.html
199+
[`slice::rotate_left`]: https://doc.rust-lang.org/std/primitive.slice.html#method.rotate_left
200+
[`slice::rotate_right`]: https://doc.rust-lang.org/std/primitive.slice.html#method.rotate_right
201+
[`String::retain`]: https://doc.rust-lang.org/std/string/struct.String.html#method.retain
202+
[cargo/5041]: https://github.com/rust-lang/cargo/pull/5041
203+
[cargo/5083]: https://github.com/rust-lang/cargo/pull/5083
204+
[cargo/5093]: https://github.com/rust-lang/cargo/pull/5093
205+
206+
1207
Version 1.25.0 (2018-03-29)
2208
==========================
3209

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
#![feature(inclusive_range_methods)]
126126
#![cfg_attr(stage0, feature(generic_param_attrs))]
127127
#![feature(rustc_const_unstable)]
128+
#![feature(const_vec_new)]
128129

129130
#![cfg_attr(not(test), feature(fn_traits, i128))]
130131
#![cfg_attr(test, feature(test))]

src/liballoc/raw_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ mod tests {
748748

749749
#[test]
750750
fn allocator_param() {
751-
use allocator::{Alloc, AllocErr};
751+
use alloc::AllocErr;
752752

753753
// Writing a test of integration between third-party
754754
// allocators and RawVec is a little tricky because the RawVec

src/liballoc/str.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ impl str {
207207
/// let s = "this is old";
208208
/// assert_eq!(s, s.replace("cookie monster", "little lamb"));
209209
/// ```
210-
#[must_use]
210+
#[must_use = "this returns the replaced string as a new allocation, \
211+
without modifying the original"]
211212
#[stable(feature = "rust1", since = "1.0.0")]
212213
#[inline]
213214
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
@@ -247,7 +248,8 @@ impl str {
247248
/// let s = "this is old";
248249
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
249250
/// ```
250-
#[must_use]
251+
#[must_use = "this returns the replaced string as a new allocation, \
252+
without modifying the original"]
251253
#[stable(feature = "str_replacen", since = "1.16.0")]
252254
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
253255
// Hope to reduce the times of re-allocation

src/liballoc/string.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ impl String {
380380
/// ```
381381
#[inline]
382382
#[stable(feature = "rust1", since = "1.0.0")]
383-
pub fn new() -> String {
383+
#[rustc_const_unstable(feature = "const_string_new")]
384+
pub const fn new() -> String {
384385
String { vec: Vec::new() }
385386
}
386387

src/libcore/fmt/builders.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a> fmt::Write for PadAdapter<'a> {
8484
/// // prints "Foo { bar: 10, baz: "Hello World" }"
8585
/// println!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() });
8686
/// ```
87-
#[must_use]
87+
#[must_use = "must eventually call `finish()` on Debug builders"]
8888
#[allow(missing_debug_implementations)]
8989
#[stable(feature = "debug_builders", since = "1.2.0")]
9090
pub struct DebugStruct<'a, 'b: 'a> {
@@ -181,7 +181,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
181181
/// // prints "Foo(10, "Hello World")"
182182
/// println!("{:?}", Foo(10, "Hello World".to_string()));
183183
/// ```
184-
#[must_use]
184+
#[must_use = "must eventually call `finish()` on Debug builders"]
185185
#[allow(missing_debug_implementations)]
186186
#[stable(feature = "debug_builders", since = "1.2.0")]
187187
pub struct DebugTuple<'a, 'b: 'a> {
@@ -319,7 +319,7 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
319319
/// // prints "{10, 11}"
320320
/// println!("{:?}", Foo(vec![10, 11]));
321321
/// ```
322-
#[must_use]
322+
#[must_use = "must eventually call `finish()` on Debug builders"]
323323
#[allow(missing_debug_implementations)]
324324
#[stable(feature = "debug_builders", since = "1.2.0")]
325325
pub struct DebugSet<'a, 'b: 'a> {
@@ -390,7 +390,7 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {
390390
/// // prints "[10, 11]"
391391
/// println!("{:?}", Foo(vec![10, 11]));
392392
/// ```
393-
#[must_use]
393+
#[must_use = "must eventually call `finish()` on Debug builders"]
394394
#[allow(missing_debug_implementations)]
395395
#[stable(feature = "debug_builders", since = "1.2.0")]
396396
pub struct DebugList<'a, 'b: 'a> {
@@ -461,7 +461,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
461461
/// // prints "{"A": 10, "B": 11}"
462462
/// println!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)]));
463463
/// ```
464-
#[must_use]
464+
#[must_use = "must eventually call `finish()` on Debug builders"]
465465
#[allow(missing_debug_implementations)]
466466
#[stable(feature = "debug_builders", since = "1.2.0")]
467467
pub struct DebugMap<'a, 'b: 'a> {

src/libcore/mem.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,9 @@ impl<T> ManuallyDrop<T> {
959959
/// ManuallyDrop::new(Box::new(()));
960960
/// ```
961961
#[stable(feature = "manually_drop", since = "1.20.0")]
962+
#[rustc_const_unstable(feature = "const_manually_drop_new")]
962963
#[inline]
963-
pub fn new(value: T) -> ManuallyDrop<T> {
964+
pub const fn new(value: T) -> ManuallyDrop<T> {
964965
ManuallyDrop { value: value }
965966
}
966967

src/libcore/num/f32.rs

+8
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,18 @@ pub mod consts {
128128
#[stable(feature = "rust1", since = "1.0.0")]
129129
pub const LOG2_E: f32 = 1.44269504088896340735992468100189214_f32;
130130

131+
/// log<sub>2</sub>(10)
132+
#[unstable(feature = "extra_log_consts", issue = "50540")]
133+
pub const LOG2_10: f32 = 3.32192809488736234787031942948939018_f32;
134+
131135
/// log<sub>10</sub>(e)
132136
#[stable(feature = "rust1", since = "1.0.0")]
133137
pub const LOG10_E: f32 = 0.434294481903251827651128918916605082_f32;
134138

139+
/// log<sub>10</sub>(2)
140+
#[unstable(feature = "extra_log_consts", issue = "50540")]
141+
pub const LOG10_2: f32 = 0.301029995663981195213738894724493027_f32;
142+
135143
/// ln(2)
136144
#[stable(feature = "rust1", since = "1.0.0")]
137145
pub const LN_2: f32 = 0.693147180559945309417232121458176568_f32;

src/libcore/num/f64.rs

+8
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,18 @@ pub mod consts {
124124
#[stable(feature = "rust1", since = "1.0.0")]
125125
pub const E: f64 = 2.71828182845904523536028747135266250_f64;
126126

127+
/// log<sub>2</sub>(10)
128+
#[unstable(feature = "extra_log_consts", issue = "50540")]
129+
pub const LOG2_10: f64 = 3.32192809488736234787031942948939018_f64;
130+
127131
/// log<sub>2</sub>(e)
128132
#[stable(feature = "rust1", since = "1.0.0")]
129133
pub const LOG2_E: f64 = 1.44269504088896340735992468100189214_f64;
130134

135+
/// log<sub>10</sub>(2)
136+
#[unstable(feature = "extra_log_consts", issue = "50540")]
137+
pub const LOG10_2: f64 = 0.301029995663981195213738894724493027_f64;
138+
131139
/// log<sub>10</sub>(e)
132140
#[stable(feature = "rust1", since = "1.0.0")]
133141
pub const LOG10_E: f64 = 0.434294481903251827651128918916605082_f64;

src/libcore/result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ use ops;
251251
/// [`Ok`]: enum.Result.html#variant.Ok
252252
/// [`Err`]: enum.Result.html#variant.Err
253253
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
254-
#[must_use]
254+
#[must_use = "this `Result` may be an `Err` variant, which should be handled"]
255255
#[stable(feature = "rust1", since = "1.0.0")]
256256
pub enum Result<T, E> {
257257
/// Contains the success value

src/libcore/tests/num/flt2dec/random.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![cfg(not(target_arch = "wasm32"))]
1212

1313
use std::i16;
14-
use std::mem;
1514
use std::str;
1615

1716
use core::num::flt2dec::MAX_SIG_DIGITS;
@@ -75,8 +74,7 @@ pub fn f32_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
7574
let mut rng: XorShiftRng = Rand::rand(&mut rand::thread_rng());
7675
let f32_range = Range::new(0x0000_0001u32, 0x7f80_0000);
7776
iterate("f32_random_equivalence_test", k, n, f, g, |_| {
78-
let i: u32 = f32_range.ind_sample(&mut rng);
79-
let x: f32 = unsafe {mem::transmute(i)};
77+
let x = f32::from_bits(f32_range.ind_sample(&mut rng));
8078
decode_finite(x)
8179
});
8280
}
@@ -87,8 +85,7 @@ pub fn f64_random_equivalence_test<F, G>(f: F, g: G, k: usize, n: usize)
8785
let mut rng: XorShiftRng = Rand::rand(&mut rand::thread_rng());
8886
let f64_range = Range::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
8987
iterate("f64_random_equivalence_test", k, n, f, g, |_| {
90-
let i: u64 = f64_range.ind_sample(&mut rng);
91-
let x: f64 = unsafe {mem::transmute(i)};
88+
let x = f64::from_bits(f64_range.ind_sample(&mut rng));
9289
decode_finite(x)
9390
});
9491
}
@@ -105,7 +102,8 @@ pub fn f32_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
105102
// iterate from 0x0000_0001 to 0x7f7f_ffff, i.e. all finite ranges
106103
let (npassed, nignored) = iterate("f32_exhaustive_equivalence_test",
107104
k, 0x7f7f_ffff, f, g, |i: usize| {
108-
let x: f32 = unsafe {mem::transmute(i as u32 + 1)};
105+
106+
let x = f32::from_bits(i as u32 + 1);
109107
decode_finite(x)
110108
});
111109
assert_eq!((npassed, nignored), (2121451881, 17643158));

0 commit comments

Comments
 (0)