Skip to content

Commit 0393784

Browse files
committed
Merge branch '⬆️-nightly-2022-05-20' into 🦆
2 parents 46f460a + 61a5f28 commit 0393784

File tree

17 files changed

+35
-63
lines changed

17 files changed

+35
-63
lines changed

doc/toolchain_limitations.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -366,28 +366,6 @@ const _: () = { b"".iter(); };
366366
```
367367

368368

369-
### `[tag:const_array_assume_init]` `MaybeUninit::array_assume_init` is not `const fn`
370-
371-
```rust
372-
#![feature(maybe_uninit_array_assume_init)]
373-
use core::mem::MaybeUninit;
374-
assert!(matches!(
375-
unsafe { MaybeUninit::array_assume_init([MaybeUninit::new(42)]) },
376-
[42]
377-
));
378-
```
379-
380-
```rust,compile_fail,E0015
381-
#![feature(maybe_uninit_array_assume_init)]
382-
use core::mem::MaybeUninit;
383-
const _: () = assert!(matches!(
384-
// error[E0015]: cannot call non-const fn `MaybeUninit::<i32>::
385-
// array_assume_init::<1_usize>` in constants
386-
unsafe { MaybeUninit::array_assume_init([MaybeUninit::new(42)]) },
387-
[42]
388-
));
389-
```
390-
391369
### `[tag:const_uninit_array]` `MaybeUninit::uninit_array` is unstable
392370

393371
```rust,compile_fail,E0658

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2022-03-30
1+
nightly-2022-05-20

src/r3_core/src/bind.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,8 @@ macro_rules! impl_fn_bind {
12161216
type BoundFn<T, Output, $( $RuntimeBinderI, )*>
12171217
where
12181218
$( $RuntimeBinderI: RuntimeBinder, )*
1219-
T: Copy + Send + 'static,
1219+
T: for<'call> FnOnce($( $RuntimeBinderI::Target<'call>, )*)
1220+
-> Output + Copy + Send + 'static,
12201221
= impl FnOnce() -> Output + Copy + Send + 'static;
12211222

12221223
const fn bind_inner<
@@ -1345,8 +1346,8 @@ where
13451346

13461347
type MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
13471348
where
1348-
InnerBoundFn: Copy + Send + 'static,
1349-
Mapper: Copy + Send + 'static,
1349+
InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
1350+
Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
13501351
= impl FnOnce() -> NewOutput + Copy + Send + 'static;
13511352

13521353
const fn map_bind_inner<InnerBoundFn, Output, Mapper, NewOutput>(

src/r3_core/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#![feature(const_maybe_uninit_array_assume_init)]
12
#![feature(const_fn_floating_point_arithmetic)]
23
#![feature(const_nonnull_slice_from_raw_parts)]
4+
#![feature(const_maybe_uninit_uninit_array)]
35
#![feature(const_maybe_uninit_assume_init)]
6+
#![feature(maybe_uninit_array_assume_init)]
47
#![feature(const_maybe_uninit_as_mut_ptr)]
58
#![feature(nonnull_slice_from_raw_parts)]
69
#![feature(arbitrary_enum_discriminant)]

src/r3_core/src/time/duration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl TryFrom<Duration> for core::time::Duration {
222222

223223
impl fmt::Debug for Duration {
224224
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
225-
let abs_dur = core::time::Duration::from_micros((self.micros as i64).abs() as u64);
225+
let abs_dur = core::time::Duration::from_micros(self.micros.unsigned_abs().into());
226226
if self.micros < 0 {
227227
write!(f, "-")?;
228228
}

src/r3_core/src/utils/for_times.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,8 @@ macro_rules! const_array_from_fn {
232232
))
233233
}
234234

235-
// `MaybeUninit::array_assume_init` is not `const fn` yet
236-
// [ref:const_array_assume_init]
237-
const unsafe fn __assume_init<
238-
$($iter_gparam $($iter_gparam_bounds)*,)*
239-
const LEN: usize
240-
>(array: [MaybeUninit<$ty>; LEN]) -> [$ty; LEN] {
241-
// Safety: This is equivalent to `transmute_copy(&array)`. The
242-
// memory layout of `[MaybeUninit<T>; $len]` is identical to `[T; $len]`.
243-
// We initialized all elements in `array[0..$len]`, so it's safe to
244-
// reinterpret that range as `[T; $len]`.
245-
unsafe { *(array.as_ptr() as *const _ as *const [$ty; LEN]) }
246-
}
247-
248-
// Safety: See the body of `__assume_init`.
249-
unsafe { __assume_init::<$($ctx_t,)* {$len_value}>(array) }
235+
// Safety: All elements of `array` are initialized
236+
unsafe { MaybeUninit::array_assume_init(array) }
250237
}};
251238
}
252239

src/r3_core/src/utils/init.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ impl<T: Init, const LEN: usize> Init for [T; LEN] {
4444
i += 1;
4545
}
4646

47-
// `MaybeUninit::array_assume_init` is not `const fn` yet
48-
// [ref:const_array_assume_init]
49-
// Safety: The memory layout of `[MaybeUninit<T>; LEN]` is
50-
// identical to `[T; LEN]`. We initialized all elements, so it's
51-
// safe to reinterpret that range as `[T; LEN]`.
52-
unsafe { super::mem::transmute(array) }
47+
// Safety: `array`'s elements are fully initialized
48+
unsafe { mem::MaybeUninit::array_assume_init(array) }
5349
};
5450
}
5551

src/r3_core/src/utils/mem.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ mod tests {
4444
MaybeUninit::new(2),
4545
MaybeUninit::new(3),
4646
];
47-
// `MaybeUninit::array_assume_init` is not `const fn`
48-
// [ref:const_array_assume_init]
49-
unsafe { transmute(array) }
47+
unsafe { MaybeUninit::array_assume_init(array) }
5048
};
5149
assert_eq!(ARRAY1, [1, 2, 3]);
5250
}

src/r3_kernel/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#![feature(const_maybe_uninit_array_assume_init)]
2+
#![feature(const_maybe_uninit_uninit_array)]
13
#![feature(const_maybe_uninit_assume_init)]
4+
#![feature(maybe_uninit_array_assume_init)]
25
#![feature(const_slice_from_raw_parts)]
36
#![feature(maybe_uninit_uninit_array)]
47
#![feature(const_precise_live_drops)]

src/r3_port_riscv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Changed
1111

1212
- **Breaking (semver-exempt):** Change the target compiler version to `nightly-2022-03-30`
13+
- **Breaking:** `use_rt!` is now gated behind `riscv-rt` Cargo feature.
1314

1415
### Fixed
1516

0 commit comments

Comments
 (0)