Skip to content

Commit 4086172

Browse files
committed
Update Rust nightly.
Fixes a new opaque type error in the task macro. Full error is "opaque type's hidden type cannot be another opaque type from the same scope". This got disallwed by the lazy-TAIT PR: rust-lang/rust#94081 Sadly there's now some weird type inference errors with pre-lazy-TAIT nightlies, so support for those is dropped.
1 parent 11143a1 commit 4086172

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

embassy-macros/src/macros/task.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ pub fn run(args: syn::AttributeArgs, mut f: syn::ItemFn) -> Result<TokenStream,
6161

6262
ctxt.check()?;
6363

64-
let name = f.sig.ident.clone();
64+
let task_ident = f.sig.ident.clone();
65+
let task_inner_ident = format_ident!("__{}_task", task_ident);
66+
let future_ident = format_ident!("__{}_Future", task_ident);
67+
let pool_ident = format_ident!("__{}_POOL", task_ident);
68+
let new_ts_ident = format_ident!("__{}_NEW_TASKSTORAGE", task_ident);
6569

6670
let visibility = &f.vis;
67-
f.sig.ident = format_ident!("task");
71+
f.sig.ident = task_inner_ident.clone();
6872
let impl_ty = if args.send {
6973
quote!(impl ::core::future::Future + Send + 'static)
7074
} else {
@@ -73,16 +77,26 @@ pub fn run(args: syn::AttributeArgs, mut f: syn::ItemFn) -> Result<TokenStream,
7377

7478
let attrs = &f.attrs;
7579

80+
let spawn_token = quote!(#embassy_path::executor::SpawnToken);
81+
let task_storage = quote!(#embassy_path::executor::raw::TaskStorage);
82+
7683
let result = quote! {
84+
85+
#[allow(non_camel_case_types)]
86+
type #future_ident = #impl_ty;
87+
7788
#(#attrs)*
78-
#visibility fn #name(#fargs) -> #embassy_path::executor::SpawnToken<#impl_ty> {
79-
use #embassy_path::executor::raw::TaskStorage;
89+
#visibility fn #task_ident(#fargs) -> #spawn_token<#future_ident> {
8090
#f
81-
type F = #impl_ty;
91+
92+
#[allow(non_upper_case_globals)]
8293
#[allow(clippy::declare_interior_mutable_const)]
83-
const NEW_TASK: TaskStorage<F> = TaskStorage::new();
84-
static POOL: [TaskStorage<F>; #pool_size] = [NEW_TASK; #pool_size];
85-
unsafe { TaskStorage::spawn_pool(&POOL, move || task(#arg_names)) }
94+
const #new_ts_ident: #task_storage<#future_ident> = #task_storage::new();
95+
96+
#[allow(non_upper_case_globals)]
97+
static #pool_ident: [#task_storage<#future_ident>; #pool_size] = [#new_ts_ident; #pool_size];
98+
99+
unsafe { #task_storage::spawn_pool(&#pool_ident, move || #task_inner_ident(#arg_names)) }
86100
}
87101
};
88102

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Before upgrading check that everything is available on all tier1 targets here:
22
# https://rust-lang.github.io/rustup-components-history
33
[toolchain]
4-
channel = "nightly-2022-03-10"
4+
channel = "nightly-2022-04-24"
55
components = [ "rust-src", "rustfmt" ]
66
targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", "thumbv7em-none-eabihf", "thumbv8m.main-none-eabihf", "wasm32-unknown-unknown" ]

0 commit comments

Comments
 (0)