From ee5f77326cf1a46f81d820567882942b99aae2f2 Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Wed, 19 Nov 2025 23:04:34 +0100 Subject: [PATCH] Rename Dummy to TaskArg --- rtic-macros/src/codegen/util.rs | 6 +++--- rtic/src/export.rs | 2 +- rtic/src/export/dummy.rs | 15 --------------- rtic/src/export/task_arg.rs | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 19 deletions(-) delete mode 100644 rtic/src/export/dummy.rs create mode 100644 rtic/src/export/task_arg.rs diff --git a/rtic-macros/src/codegen/util.rs b/rtic-macros/src/codegen/util.rs index c94fd8b459b..1a7f18b94f5 100644 --- a/rtic-macros/src/codegen/util.rs +++ b/rtic-macros/src/codegen/util.rs @@ -35,7 +35,7 @@ pub fn link_section_uninit() -> TokenStream2 { pub fn regroup_inputs( inputs: &[PatType], ) -> ( - // Generic args e.g. &[`_0: impl Dummy`, `_1: impl Dummy`] + // Generic args e.g. &[`_0: impl TaskArg`, `_1: impl TaskArg`] Vec, // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] Vec, @@ -50,7 +50,7 @@ pub fn regroup_inputs( let ty = &inputs[0].ty; ( - vec![quote!(_0: impl rtic::export::dummy::Dummy + Send + Sync)], + vec![quote!(_0: impl rtic::export::task_arg::TaskArg + Send + Sync)], vec![quote!(_0: #ty)], quote!(_0), vec![quote!(_0)], @@ -66,7 +66,7 @@ pub fn regroup_inputs( let i = Ident::new(&format!("_{i}"), Span::call_site()); let ty = &input.ty; - generic_args.push(quote!(#i: impl rtic::export::dummy::Dummy + Send + Sync)); + generic_args.push(quote!(#i: impl rtic::export::task_arg::TaskArg + Send + Sync)); args.push(quote!(#i: #ty)); diff --git a/rtic/src/export.rs b/rtic/src/export.rs index 0beeafbba92..c6b0dafa544 100644 --- a/rtic/src/export.rs +++ b/rtic/src/export.rs @@ -1,8 +1,8 @@ pub use critical_section::CriticalSection; pub use portable_atomic as atomic; -pub mod dummy; pub mod executor; +pub mod task_arg; // Cortex-M target (any) #[cfg(feature = "cortex-m")] diff --git a/rtic/src/export/dummy.rs b/rtic/src/export/dummy.rs deleted file mode 100644 index be16aeb5ae1..00000000000 --- a/rtic/src/export/dummy.rs +++ /dev/null @@ -1,15 +0,0 @@ -// TODO: What should we name this? - -/// Dummy trait which will only ever be implemented where type T is Self -pub trait Dummy { - /// This should always be same as `Self` - type T; - fn to(self) -> Self::T; -} - -impl Dummy for T { - type T = T; - fn to(self) -> T { - self - } -} diff --git a/rtic/src/export/task_arg.rs b/rtic/src/export/task_arg.rs new file mode 100644 index 00000000000..05fa59a2593 --- /dev/null +++ b/rtic/src/export/task_arg.rs @@ -0,0 +1,22 @@ +/// A trait for types that can be passed as arguments when spawning tasks +/// +/// This trait will only ever be implemented where type `Self::T` is `Self` +/// +/// The global `my_task::spawn` requires its args to be `Send`. This trait has to +/// be used because we can not have a function with a where clause which +/// requires a concrete type to be `Send` if that type is not `Send`. The compiler +/// will error out on us. However hiding that behind a dummy trait which is +/// only implemented for that same type enables us to defer the error to when +/// the user erroneously tries to call the function. +pub trait TaskArg { + /// This should always be same as `Self` + type T; + fn to(self) -> Self::T; +} + +impl TaskArg for T { + type T = T; + fn to(self) -> T { + self + } +}