Skip to content

Commit 588c1bc

Browse files
committed
Merge branch '⬆️-nightly-2022-06-26' into 🦆
2 parents be3773c + 363a19e commit 588c1bc

File tree

11 files changed

+102
-51
lines changed

11 files changed

+102
-51
lines changed

doc/toolchain_limitations.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,15 @@ const _: () = assert!(matches!((2..4).next(), Some(2)));
513513
```
514514

515515

516-
### `[tag:iterator_const_default]` `Iterator`'s methods lack `#[default_method_body_is_const]`
516+
### `[tag:iterator_const_default]` `Iterator` lack `#[const_trait]`
517517

518518
Implementing `const Iterator` requires you to implement all of its methods, which is impossible to do correctly.
519519

520-
```rust,compile_fail
520+
```rust
521521
#![feature(const_trait_impl)]
522522
#![feature(const_mut_refs)]
523+
// FIXME: `compile-fail` temporarily removed due to
524+
// [ref:const_impl_of_non_const_trait]
523525

524526
struct MyIterator;
525527

@@ -546,6 +548,36 @@ impl const Iterator for MyIterator {
546548
```
547549

548550

551+
### `[tag:const_impl_of_non_const_trait]` `impl const Trait` doesn't require `#[const_trait]`
552+
553+
A `const` implementation of a non-`#[const_trait]` trait that uses at least one default method implementation doesn't result in a compile error. Instead, an error occurs when the non-`const` default method implementations are actually called in a constant context. This behavior deviates from Rust's design principles, so it's likely a bug.
554+
555+
```rust
556+
#![feature(const_trait_impl)]
557+
trait Tr {
558+
fn foo() {}
559+
}
560+
561+
// expected error: const trait implementations may not use non-const default
562+
// functions / note: `foo` not implemented
563+
impl const Tr for () {}
564+
```
565+
566+
```rust
567+
#![feature(const_trait_impl)]
568+
#![feature(lint_reasons)]
569+
trait Tr {
570+
fn foo() {}
571+
}
572+
573+
impl const Tr for () {}
574+
575+
const fn f<T: ~const Tr>() { T::foo() }
576+
#[expect(const_err)] // error: calling non-const function `<() as Tr>::foo`
577+
const _: () = f::<()>();
578+
```
579+
580+
549581
### `[tag:int_const_ord]` `<integer>: !const Ord`
550582

551583
The standard library doesn't provide `const` trait implementations of `Ord` for the built-in integer types.
@@ -627,6 +659,25 @@ const _: () = tokenlock::with_branded_token(|token| {
627659
```
628660

629661

662+
### `[tag:rust_99793_tait]` False-positive "cycle detected" in `const fn` with TAIT
663+
664+
*Upstream issue:* [rust-lang/rust#99793](https://github.com/rust-lang/rust/issues/99793) (possibly related)
665+
666+
```rust
667+
#![feature(type_alias_impl_trait)]
668+
type Unit<T> = impl Copy;
669+
fn unit<T>(x: T) -> Unit<T> { core::mem::forget(x) }
670+
```
671+
672+
```rust,compile_fail,E0391
673+
#![feature(type_alias_impl_trait)]
674+
type Unit<T> = impl Copy;
675+
// error[E0391]: cycle detected when computing type of
676+
// `main::_doctest_main_lib_rs_647_0::Unit::{opaque#0}
677+
const fn unit<T>(x: T) -> Unit<T> { core::mem::forget(x) }
678+
```
679+
680+
630681
## Unsized types
631682

632683
### `[tag:unsized_maybe_uninit]` `MaybeUninit<T>` requires `T: Sized`

rust-toolchain

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

src/r3_core/src/bag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
use core::mem::transmute;
33

44
/// A heterogeneous collection to store property values.
5+
#[const_trait]
56
pub trait Bag: private::Sealed + Copy {
67
/// Insert an item and return a new `impl Bag`.
78
///
89
/// For `const fn`-ness, this method can't have a provided implementation.
910
#[inline]
10-
#[default_method_body_is_const]
1111
fn insert<T: 'static>(self, head: T) -> List<T, Self> {
1212
assert!(self.get::<T>().is_none(), "duplicate entry");
1313
(head, self)

src/r3_core/src/bind.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,10 +1196,7 @@ macro_rules! impl_fn_bind {
11961196
{
11971197
type Output = Output;
11981198

1199-
// This opaque type must be defined outside this trait to
1200-
// prevent the unintended capturing of `$BinderI`.
1201-
// [ref:opaque_type_extraneous_capture]
1202-
type BoundFn = BoundFn<T, Output, $( $RuntimeBinderI, )*>;
1199+
type BoundFn = BoundFn<T, $( $RuntimeBinderI, )*>;
12031200

12041201
fn bind(
12051202
self,
@@ -1209,42 +1206,50 @@ macro_rules! impl_fn_bind {
12091206
Binder::register_dependency(&binder, ctx);
12101207

12111208
let intermediate = Binder::into_runtime_binder(binder);
1212-
bind_inner(self, intermediate)
1209+
BoundFn {
1210+
func: self,
1211+
runtime_binders: intermediate,
1212+
}
12131213
}
12141214
}
12151215

1216-
type BoundFn<T, Output, $( $RuntimeBinderI, )*>
1217-
where
1218-
$( $RuntimeBinderI: RuntimeBinder, )*
1219-
T: for<'call> FnOnce($( $RuntimeBinderI::Target<'call>, )*)
1220-
-> Output + Copy + Send + 'static,
1221-
= impl FnOnce() -> Output + Copy + Send + 'static;
1222-
1223-
const fn bind_inner<
1224-
T,
1225-
Output,
1226-
$( $RuntimeBinderI, )*
1227-
>(
1216+
// This opaque type must be defined outside the above `impl` to
1217+
// prevent the unintended capturing of `$BinderI`.
1218+
// [ref:opaque_type_extraneous_capture]
1219+
// type BoundFn<T, Output, $( $RuntimeBinderI, )*>
1220+
// where
1221+
// $( $RuntimeBinderI: RuntimeBinder, )*
1222+
// T: for<'call> FnOnce($( $RuntimeBinderI::Target<'call>, )*)
1223+
// -> Output + Copy + Send + 'static,
1224+
// = impl FnOnce() -> Output + Copy + Send + 'static;
1225+
1226+
// FIXME: This is supposed to be a TAIT like the one above, but
1227+
// [ref:rust_99793_tait] prevents that
1228+
#[derive(Copy, Clone)]
1229+
pub struct BoundFn<T, $( $RuntimeBinderI, )*> {
12281230
func: T,
1229-
runtime_binders: ( $( $RuntimeBinderI, )* ),
1230-
) -> BoundFn<T, Output, $( $RuntimeBinderI, )*>
1231+
runtime_binders: ($( $RuntimeBinderI, )*),
1232+
}
1233+
1234+
impl<T, Output, $( $RuntimeBinderI, )*> FnOnce<()> for BoundFn<T, $( $RuntimeBinderI, )*>
12311235
where
12321236
$( $RuntimeBinderI: RuntimeBinder, )*
1233-
T: for<'call> FnOnce($( $RuntimeBinderI::Target<'call>, )*)
1234-
-> Output + Copy + Send + 'static,
1237+
T: for<'call> FnOnce($( $RuntimeBinderI::Target<'call>, )*) -> Output,
12351238
{
1239+
type Output = Output;
1240+
12361241
#[inline]
1237-
move || {
1242+
extern "rust-call" fn call_once(self, (): ()) -> Output {
12381243
// Safety: `runtime_binders` was created by the corresponding
12391244
// type's `into_runtime_binder` method.
12401245
// `CfgBindRegistry::finalize` checks that the borrowing
12411246
// rules regarding the materialization output are observed.
12421247
// If the check fails, so does the compilation, and this
12431248
// runtime code will never be executed.
12441249
let ($( $fieldI, )*) = unsafe {
1245-
<( $( $RuntimeBinderI, )* ) as RuntimeBinder>::materialize(runtime_binders)
1250+
<( $( $RuntimeBinderI, )* ) as RuntimeBinder>::materialize(self.runtime_binders)
12461251
};
1247-
func($( $fieldI, )*)
1252+
(self.func)($( $fieldI, )*)
12481253
}
12491254
}
12501255
}; // const _

src/r3_core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#![feature(const_cell_into_inner)]
2020
#![feature(const_ptr_offset_from)]
2121
#![feature(type_alias_impl_trait)]
22-
#![feature(const_intrinsic_copy)]
2322
#![feature(const_slice_ptr_len)]
2423
#![feature(exhaustive_patterns)] // `let Ok(()) = Ok::<(), !>(())`
2524
#![feature(generic_const_exprs)]
@@ -28,6 +27,7 @@
2827
#![feature(const_nonnull_new)]
2928
#![feature(const_result_drop)]
3029
#![feature(const_slice_index)]
30+
#![feature(unboxed_closures)] // `impl FnOnce`
3131
#![feature(const_option_ext)]
3232
#![feature(const_trait_impl)]
3333
#![feature(const_ptr_write)]
@@ -49,6 +49,7 @@
4949
#![feature(decl_macro)]
5050
#![feature(never_type)] // `!`
5151
#![feature(const_try)]
52+
#![feature(fn_traits)] // `impl FnOnce`
5253
#![feature(let_else)]
5354
#![feature(doc_cfg)] // `#[doc(cfg(...))]`
5455
#![cfg_attr(test, feature(is_sorted))]

src/r3_core/src/utils/alloc.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ pub struct AllocError;
225225
/// This trait is subject to [the kernel-side API stability guarantee][1].
226226
///
227227
/// [1]: crate#stability
228+
#[const_trait]
228229
pub unsafe trait Allocator {
229230
/// Attempts to allocate a block of memory.
230231
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>;
231232

232233
/// Behaves like `allocate`, but also ensures that the returned memory is
233234
/// zero-initialized.
234-
#[default_method_body_is_const]
235235
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
236236
let ptr = const_try_result!(self.allocate(layout));
237237
// SAFETY: `alloc` returns a valid memory block
@@ -251,7 +251,6 @@ pub unsafe trait Allocator {
251251
/// # Safety
252252
///
253253
/// See [`core::alloc::Allocator::grow`]'s documentation.
254-
#[default_method_body_is_const]
255254
unsafe fn grow(
256255
&self,
257256
ptr: NonNull<u8>,
@@ -284,7 +283,6 @@ pub unsafe trait Allocator {
284283
/// # Safety
285284
///
286285
/// See [`core::alloc::Allocator::grow_zeroed`]'s documentation.
287-
#[default_method_body_is_const]
288286
unsafe fn grow_zeroed(
289287
&self,
290288
ptr: NonNull<u8>,
@@ -316,7 +314,6 @@ pub unsafe trait Allocator {
316314
/// # Safety
317315
///
318316
/// See [`core::alloc::Allocator::shrink`]'s documentation.
319-
#[default_method_body_is_const]
320317
unsafe fn shrink(
321318
&self,
322319
ptr: NonNull<u8>,
@@ -344,7 +341,6 @@ pub unsafe trait Allocator {
344341
}
345342

346343
/// Creates a “by reference” adapter for this instance of `Allocator`.
347-
#[default_method_body_is_const]
348344
fn by_ref(&self) -> &Self
349345
where
350346
Self: Sized,

src/r3_core/src/utils/binary_heap/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ mod veclike;
1111
pub use self::veclike::*;
1212

1313
/// Context type for [`BinaryHeap`]'s operations.
14+
#[const_trait]
1415
pub trait BinaryHeapCtx<Element> {
1516
/// Return `true` iff `x < y`.
1617
fn lt(&mut self, x: &Element, y: &Element) -> bool;
1718

1819
/// Called when the element `e` is moved to the new position `new_index`.
19-
#[default_method_body_is_const]
2020
fn on_move(&mut self, e: &mut Element, new_index: usize) {
2121
let _ = (e, new_index);
2222
}

src/r3_kernel/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![feature(const_precise_live_drops)]
88
#![feature(const_raw_ptr_comparison)]
99
#![feature(cfg_target_has_atomic)] // `#[cfg(target_has_atomic_load_store)]`
10-
#![feature(const_intrinsic_copy)]
1110
#![feature(exhaustive_patterns)] // `let Ok(()) = Ok::<(), !>(())`
1211
#![feature(generic_const_exprs)]
1312
#![feature(const_refs_to_cell)]

src/r3_port_std/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use r3_kernel::{KernelTraits, Port, PortToKernel, System, TaskCb, UTicks};
2222
use spin::Mutex as SpinMutex;
2323
use std::{
2424
cell::Cell,
25-
lazy::SyncOnceCell,
26-
sync::mpsc,
25+
sync::{mpsc, OnceLock},
2726
time::{Duration, Instant},
2827
};
2928

@@ -97,7 +96,7 @@ pub unsafe trait PortInstance:
9796
/// the corresponding trait methods of `Port*`.
9897
#[doc(hidden)]
9998
pub struct State {
100-
thread_group: SyncOnceCell<ums::ThreadGroup<sched::SchedState>>,
99+
thread_group: OnceLock<ums::ThreadGroup<sched::SchedState>>,
101100
timer_cmd_send: SpinMutex<Option<mpsc::Sender<TimerCmd>>>,
102101
origin: AtomicRef<'static, Instant>,
103102
}
@@ -206,7 +205,7 @@ impl TaskState {
206205
impl State {
207206
pub const fn new() -> Self {
208207
Self {
209-
thread_group: SyncOnceCell::new(),
208+
thread_group: OnceLock::new(),
210209
timer_cmd_send: SpinMutex::new(None),
211210
origin: AtomicRef::new(None),
212211
}

src/r3_port_std/src/ums.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Utterly inefficient cross-platform preemptive user-mode scheduling
22
use slab::Slab;
33
use std::{
4-
lazy::SyncOnceCell,
54
panic::{catch_unwind, AssertUnwindSafe},
5+
sync::OnceLock,
66
sync::{mpsc, Arc},
77
thread::Result,
88
};
@@ -75,7 +75,7 @@ struct WorkerThread {
7575
}
7676

7777
thread_local! {
78-
static TLB: SyncOnceCell<ThreadLocalBlock> = SyncOnceCell::new();
78+
static TLB: OnceLock<ThreadLocalBlock> = OnceLock::new();
7979
}
8080

8181
struct ThreadLocalBlock {

0 commit comments

Comments
 (0)