Skip to content

Commit

Permalink
feat(core): use #![feature(associated_type_bounds)]
Browse files Browse the repository at this point in the history
This feature is tracked by [rust-lang/rust#52662][1].

Fixes `[ref:trait_constraints_on_associated_types_do_not_propagate]`.
That is, when you have `C: ~const CfgTimer`, you don't need `C::System:
KernelTimer` anymore.

[1]: rust-lang/rust#52662
  • Loading branch information
yvt committed Jun 11, 2022
1 parent 8fc4685 commit d564393
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 54 deletions.
23 changes: 0 additions & 23 deletions doc/toolchain_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,6 @@ impl<T> StGeneric<for<'a> fn(&'a T)> {
```


### `[tag:trait_constraints_on_associated_types_do_not_propagate]` Trait constraints on associated types do not propagate to the trait's use sites

*Upstream issue:* [rust-lang/rust#32722](https://github.com/rust-lang/rust/issues/32722)

According to [this comment](https://github.com/rust-lang/rust/issues/32722#issuecomment-618044689), this is a symptom of [rust-lang/rust#20671](https://github.com/rust-lang/rust/issues/20671).

```rust,compile_fail,E0277
trait KernelMutex {}
trait CfgBase {
type System;
}
trait CfgMutex: CfgBase
where
Self::System: KernelMutex,
{}
// error[E0277]: the trait bound `<C as CfgBase>::System: KernelMutex` is not satisfied
fn foo<C: CfgMutex>() {}
```


### `[tag:impl_trait_false_type_alias_bounds]` `type_alias_bounds` misfires when `impl Trait` is used in a portion of a type alias

*Upstream issue:* [rust-lang/rust#94395](https://github.com/rust-lang/rust/issues/94395)
Expand Down
4 changes: 4 additions & 0 deletions src/r3_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- The `Cfg*` traits now imply the corresponding `Kernel*` traits (e.g., `C: CfgTimer` implies `C::System: KernelTimer`), making some trait bounds in configuration functions unnecessary.

## [0.1.2] - 2022-03-30

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/r3_core/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ impl<'pool, const LEN: usize, System, T> const UnzipBind for Bind<'pool, System,
/// where
/// C: ~const traits::CfgBase +
/// ~const traits::CfgTask,
/// C::System: traits::KernelBase + traits::KernelStatic,
/// C::System: traits::KernelStatic,
/// {
/// let foo = Bind::define().init(|| {
/// // `BindTable::get()` will fail because some bindings might not
Expand Down
3 changes: 0 additions & 3 deletions src/r3_core/src/kernel/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ define_object! {
/// const fn configure<C>(cfg: &mut Cfg<C>) -> Objects<C::System>
/// where
/// C: ~const traits::CfgMutex,
// The following bound is necessary becauase of a bug in the compiler
// [ref:trait_constraints_on_associated_types_do_not_propagate]
/// C::System: traits::KernelMutex,
/// {
/// let mutex = StaticMutex::define()
/// .protocol(MutexProtocol::Ceiling(1))
Expand Down
25 changes: 5 additions & 20 deletions src/r3_core/src/kernel/raw_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ pub struct TaskDescriptor<System> {
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgEventGroup: CfgBase
where
Self::System: raw::KernelEventGroup,
{
pub unsafe trait CfgEventGroup: CfgBase<System: raw::KernelEventGroup> {
fn event_group_define<Properties: ~const Bag>(
&mut self,
descriptor: EventGroupDescriptor<Self::System>,
Expand Down Expand Up @@ -151,10 +148,7 @@ pub struct EventGroupDescriptor<System> {
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgMutex: CfgBase
where
Self::System: raw::KernelMutex,
{
pub unsafe trait CfgMutex: CfgBase<System: raw::KernelMutex> {
fn mutex_define<Properties: ~const Bag>(
&mut self,
descriptor: MutexDescriptor<Self::System>,
Expand Down Expand Up @@ -185,10 +179,7 @@ pub struct MutexDescriptor<System> {
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgSemaphore: CfgBase
where
Self::System: raw::KernelSemaphore,
{
pub unsafe trait CfgSemaphore: CfgBase<System: raw::KernelSemaphore> {
fn semaphore_define<Properties: ~const Bag>(
&mut self,
descriptor: SemaphoreDescriptor<Self::System>,
Expand Down Expand Up @@ -221,10 +212,7 @@ pub struct SemaphoreDescriptor<System> {
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgTimer: CfgBase
where
Self::System: raw::KernelTimer,
{
pub unsafe trait CfgTimer: CfgBase<System: raw::KernelTimer> {
fn timer_define<Properties: ~const Bag>(
&mut self,
descriptor: TimerDescriptor<Self::System>,
Expand Down Expand Up @@ -258,10 +246,7 @@ pub struct TimerDescriptor<System> {
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgInterruptLine: CfgBase
where
Self::System: raw::KernelInterruptLine,
{
pub unsafe trait CfgInterruptLine: CfgBase<System: raw::KernelInterruptLine> {
fn interrupt_line_define<Properties: ~const Bag>(
&mut self,
descriptor: InterruptLineDescriptor<Self::System>,
Expand Down
6 changes: 0 additions & 6 deletions src/r3_core/src/kernel/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ define_object! {
/// const fn configure<C>(b: &mut Cfg<C>) -> StaticTimer<C::System>
/// where
/// C: ~const traits::CfgTimer,
// The following bound is necessary becauase of a bug in the compiler
// [ref:trait_constraints_on_associated_types_do_not_propagate]
/// C::System: traits::KernelTimer,
/// {
/// StaticTimer::define()
/// .delay(Duration::from_millis(70))
Expand Down Expand Up @@ -319,9 +316,6 @@ define_object! {
/// const fn configure<C>(b: &mut Cfg<C>) -> StaticTimer<C::System>
/// where
/// C: ~const traits::CfgTimer,
// The following bound is necessary becauase of a bug in the compiler
// [ref:trait_constraints_on_associated_types_do_not_propagate]
/// C::System: traits::KernelTimer,
/// {
/// StaticTimer::define()
/// .active(true)
Expand Down
1 change: 1 addition & 0 deletions src/r3_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![feature(const_precise_live_drops)]
#![feature(const_raw_ptr_comparison)]
#![feature(generic_associated_types)]
#![feature(associated_type_bounds)]
#![feature(const_slice_first_last)]
#![feature(cfg_target_has_atomic)] // `#[cfg(target_has_atomic_load_store)]`
#![feature(const_cell_into_inner)]
Expand Down
2 changes: 1 addition & 1 deletion src/r3_support_rp2040/src/usbstdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub const fn configure<'pool, C, TOptions: Options>(
rp2040_usbctrl_regs: Bind<'pool, C::System, rp2040_pac::USBCTRL_REGS>,
) where
C: ~const traits::CfgBase + ~const traits::CfgInterruptLine,
C::System: traits::KernelInterruptLine + traits::KernelStatic,
C::System: traits::KernelStatic,
{
bind(
(rp2040_resets.borrow_mut(), rp2040_usbctrl_regs.take()),
Expand Down

0 comments on commit d564393

Please sign in to comment.