Skip to content

Commit d564393

Browse files
committed
feat(core): use #![feature(associated_type_bounds)]
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
1 parent 8fc4685 commit d564393

File tree

8 files changed

+12
-54
lines changed

8 files changed

+12
-54
lines changed

doc/toolchain_limitations.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,6 @@ impl<T> StGeneric<for<'a> fn(&'a T)> {
3838
```
3939

4040

41-
### `[tag:trait_constraints_on_associated_types_do_not_propagate]` Trait constraints on associated types do not propagate to the trait's use sites
42-
43-
*Upstream issue:* [rust-lang/rust#32722](https://github.com/rust-lang/rust/issues/32722)
44-
45-
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).
46-
47-
```rust,compile_fail,E0277
48-
trait KernelMutex {}
49-
50-
trait CfgBase {
51-
type System;
52-
}
53-
54-
trait CfgMutex: CfgBase
55-
where
56-
Self::System: KernelMutex,
57-
{}
58-
59-
// error[E0277]: the trait bound `<C as CfgBase>::System: KernelMutex` is not satisfied
60-
fn foo<C: CfgMutex>() {}
61-
```
62-
63-
6441
### `[tag:impl_trait_false_type_alias_bounds]` `type_alias_bounds` misfires when `impl Trait` is used in a portion of a type alias
6542

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

src/r3_core/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- 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.
13+
1014
## [0.1.2] - 2022-03-30
1115

1216
### Changed

src/r3_core/src/bind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl<'pool, const LEN: usize, System, T> const UnzipBind for Bind<'pool, System,
820820
/// where
821821
/// C: ~const traits::CfgBase +
822822
/// ~const traits::CfgTask,
823-
/// C::System: traits::KernelBase + traits::KernelStatic,
823+
/// C::System: traits::KernelStatic,
824824
/// {
825825
/// let foo = Bind::define().init(|| {
826826
/// // `BindTable::get()` will fail because some bindings might not

src/r3_core/src/kernel/mutex.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ define_object! {
5454
/// const fn configure<C>(cfg: &mut Cfg<C>) -> Objects<C::System>
5555
/// where
5656
/// C: ~const traits::CfgMutex,
57-
// The following bound is necessary becauase of a bug in the compiler
58-
// [ref:trait_constraints_on_associated_types_do_not_propagate]
59-
/// C::System: traits::KernelMutex,
6057
/// {
6158
/// let mutex = StaticMutex::define()
6259
/// .protocol(MutexProtocol::Ceiling(1))

src/r3_core/src/kernel/raw_cfg.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ pub struct TaskDescriptor<System> {
116116
/// [3]: self#stability
117117
/// [4]: self#safety
118118
// The supertrait can't be `~const` due to [ref:const_supertraits]
119-
pub unsafe trait CfgEventGroup: CfgBase
120-
where
121-
Self::System: raw::KernelEventGroup,
122-
{
119+
pub unsafe trait CfgEventGroup: CfgBase<System: raw::KernelEventGroup> {
123120
fn event_group_define<Properties: ~const Bag>(
124121
&mut self,
125122
descriptor: EventGroupDescriptor<Self::System>,
@@ -151,10 +148,7 @@ pub struct EventGroupDescriptor<System> {
151148
/// [3]: self#stability
152149
/// [4]: self#safety
153150
// The supertrait can't be `~const` due to [ref:const_supertraits]
154-
pub unsafe trait CfgMutex: CfgBase
155-
where
156-
Self::System: raw::KernelMutex,
157-
{
151+
pub unsafe trait CfgMutex: CfgBase<System: raw::KernelMutex> {
158152
fn mutex_define<Properties: ~const Bag>(
159153
&mut self,
160154
descriptor: MutexDescriptor<Self::System>,
@@ -185,10 +179,7 @@ pub struct MutexDescriptor<System> {
185179
/// [3]: self#stability
186180
/// [4]: self#safety
187181
// The supertrait can't be `~const` due to [ref:const_supertraits]
188-
pub unsafe trait CfgSemaphore: CfgBase
189-
where
190-
Self::System: raw::KernelSemaphore,
191-
{
182+
pub unsafe trait CfgSemaphore: CfgBase<System: raw::KernelSemaphore> {
192183
fn semaphore_define<Properties: ~const Bag>(
193184
&mut self,
194185
descriptor: SemaphoreDescriptor<Self::System>,
@@ -221,10 +212,7 @@ pub struct SemaphoreDescriptor<System> {
221212
/// [3]: self#stability
222213
/// [4]: self#safety
223214
// The supertrait can't be `~const` due to [ref:const_supertraits]
224-
pub unsafe trait CfgTimer: CfgBase
225-
where
226-
Self::System: raw::KernelTimer,
227-
{
215+
pub unsafe trait CfgTimer: CfgBase<System: raw::KernelTimer> {
228216
fn timer_define<Properties: ~const Bag>(
229217
&mut self,
230218
descriptor: TimerDescriptor<Self::System>,
@@ -258,10 +246,7 @@ pub struct TimerDescriptor<System> {
258246
/// [3]: self#stability
259247
/// [4]: self#safety
260248
// The supertrait can't be `~const` due to [ref:const_supertraits]
261-
pub unsafe trait CfgInterruptLine: CfgBase
262-
where
263-
Self::System: raw::KernelInterruptLine,
264-
{
249+
pub unsafe trait CfgInterruptLine: CfgBase<System: raw::KernelInterruptLine> {
265250
fn interrupt_line_define<Properties: ~const Bag>(
266251
&mut self,
267252
descriptor: InterruptLineDescriptor<Self::System>,

src/r3_core/src/kernel/timer.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ define_object! {
279279
/// const fn configure<C>(b: &mut Cfg<C>) -> StaticTimer<C::System>
280280
/// where
281281
/// C: ~const traits::CfgTimer,
282-
// The following bound is necessary becauase of a bug in the compiler
283-
// [ref:trait_constraints_on_associated_types_do_not_propagate]
284-
/// C::System: traits::KernelTimer,
285282
/// {
286283
/// StaticTimer::define()
287284
/// .delay(Duration::from_millis(70))
@@ -319,9 +316,6 @@ define_object! {
319316
/// const fn configure<C>(b: &mut Cfg<C>) -> StaticTimer<C::System>
320317
/// where
321318
/// C: ~const traits::CfgTimer,
322-
// The following bound is necessary becauase of a bug in the compiler
323-
// [ref:trait_constraints_on_associated_types_do_not_propagate]
324-
/// C::System: traits::KernelTimer,
325319
/// {
326320
/// StaticTimer::define()
327321
/// .active(true)

src/r3_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(const_precise_live_drops)]
1414
#![feature(const_raw_ptr_comparison)]
1515
#![feature(generic_associated_types)]
16+
#![feature(associated_type_bounds)]
1617
#![feature(const_slice_first_last)]
1718
#![feature(cfg_target_has_atomic)] // `#[cfg(target_has_atomic_load_store)]`
1819
#![feature(const_cell_into_inner)]

src/r3_support_rp2040/src/usbstdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub const fn configure<'pool, C, TOptions: Options>(
8080
rp2040_usbctrl_regs: Bind<'pool, C::System, rp2040_pac::USBCTRL_REGS>,
8181
) where
8282
C: ~const traits::CfgBase + ~const traits::CfgInterruptLine,
83-
C::System: traits::KernelInterruptLine + traits::KernelStatic,
83+
C::System: traits::KernelStatic,
8484
{
8585
bind(
8686
(rp2040_resets.borrow_mut(), rp2040_usbctrl_regs.take()),

0 commit comments

Comments
 (0)