Merge pull request #4023 from 0e4ef622/better-errors
Fix ugly compiler error from task macro
This commit is contained in:
commit
7479a5f7b7
@ -145,42 +145,19 @@ pub fn run(args: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
};
|
};
|
||||||
#[cfg(not(feature = "nightly"))]
|
#[cfg(not(feature = "nightly"))]
|
||||||
let mut task_outer_body = quote! {
|
let mut task_outer_body = quote! {
|
||||||
const fn __task_pool_size<F, Args>(_: F) -> usize
|
const fn __task_pool_get<F, Args, Fut>(_: F) -> &'static #embassy_executor::raw::TaskPool<Fut, POOL_SIZE>
|
||||||
where
|
where
|
||||||
F: #embassy_executor::_export::TaskFn<Args>,
|
F: #embassy_executor::_export::TaskFn<Args, Fut = Fut>,
|
||||||
{
|
Fut: ::core::future::Future + 'static,
|
||||||
::core::mem::size_of::<
|
|
||||||
#embassy_executor::raw::TaskPool<F::Fut, POOL_SIZE>
|
|
||||||
>()
|
|
||||||
}
|
|
||||||
const fn __task_pool_align<F, Args>(_: F) -> usize
|
|
||||||
where
|
|
||||||
F: #embassy_executor::_export::TaskFn<Args>,
|
|
||||||
{
|
|
||||||
::core::mem::align_of::<
|
|
||||||
#embassy_executor::raw::TaskPool<F::Fut, POOL_SIZE>
|
|
||||||
>()
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn __task_pool_new<F, Args>(_: F) -> #embassy_executor::raw::TaskPool<F::Fut, POOL_SIZE>
|
|
||||||
where
|
|
||||||
F: #embassy_executor::_export::TaskFn<Args>,
|
|
||||||
{
|
|
||||||
#embassy_executor::raw::TaskPool::new()
|
|
||||||
}
|
|
||||||
|
|
||||||
const fn __task_pool_get<F, Args>(_: F) -> &'static #embassy_executor::raw::TaskPool<F::Fut, POOL_SIZE>
|
|
||||||
where
|
|
||||||
F: #embassy_executor::_export::TaskFn<Args>
|
|
||||||
{
|
{
|
||||||
unsafe { &*POOL.get().cast() }
|
unsafe { &*POOL.get().cast() }
|
||||||
}
|
}
|
||||||
|
|
||||||
const POOL_SIZE: usize = #pool_size;
|
const POOL_SIZE: usize = #pool_size;
|
||||||
static POOL: #embassy_executor::_export::TaskPoolHolder<
|
static POOL: #embassy_executor::_export::TaskPoolHolder<
|
||||||
{__task_pool_size(#task_inner_ident)},
|
{#embassy_executor::_export::task_pool_size::<_, _, _, POOL_SIZE>(#task_inner_ident)},
|
||||||
{__task_pool_align(#task_inner_ident)},
|
{#embassy_executor::_export::task_pool_align::<_, _, _, POOL_SIZE>(#task_inner_ident)},
|
||||||
> = unsafe { ::core::mem::transmute(__task_pool_new(#task_inner_ident)) };
|
> = unsafe { ::core::mem::transmute(#embassy_executor::_export::task_pool_new::<_, _, _, POOL_SIZE>(#task_inner_ident)) };
|
||||||
unsafe { __task_pool_get(#task_inner_ident)._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) }
|
unsafe { __task_pool_get(#task_inner_ident)._spawn_async_fn(move || #task_inner_ident(#(#full_args,)*)) }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,8 @@ pub mod _export {
|
|||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
|
|
||||||
|
use crate::raw::TaskPool;
|
||||||
|
|
||||||
pub trait TaskFn<Args>: Copy {
|
pub trait TaskFn<Args>: Copy {
|
||||||
type Fut: Future + 'static;
|
type Fut: Future + 'static;
|
||||||
}
|
}
|
||||||
@ -116,6 +118,30 @@ pub mod _export {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const fn task_pool_size<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize
|
||||||
|
where
|
||||||
|
F: TaskFn<Args, Fut = Fut>,
|
||||||
|
Fut: Future + 'static,
|
||||||
|
{
|
||||||
|
size_of::<TaskPool<Fut, POOL_SIZE>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn task_pool_align<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> usize
|
||||||
|
where
|
||||||
|
F: TaskFn<Args, Fut = Fut>,
|
||||||
|
Fut: Future + 'static,
|
||||||
|
{
|
||||||
|
align_of::<TaskPool<Fut, POOL_SIZE>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn task_pool_new<F, Args, Fut, const POOL_SIZE: usize>(_: F) -> TaskPool<Fut, POOL_SIZE>
|
||||||
|
where
|
||||||
|
F: TaskFn<Args, Fut = Fut>,
|
||||||
|
Fut: Future + 'static,
|
||||||
|
{
|
||||||
|
TaskPool::new()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(private_bounds)]
|
#[allow(private_bounds)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Align<const N: usize>([<Self as Alignment>::Archetype; 0])
|
pub struct Align<const N: usize>([<Self as Alignment>::Archetype; 0])
|
||||||
|
|||||||
@ -19,5 +19,6 @@ fn ui() {
|
|||||||
t.compile_fail("tests/ui/not_async.rs");
|
t.compile_fail("tests/ui/not_async.rs");
|
||||||
t.compile_fail("tests/ui/self_ref.rs");
|
t.compile_fail("tests/ui/self_ref.rs");
|
||||||
t.compile_fail("tests/ui/self.rs");
|
t.compile_fail("tests/ui/self.rs");
|
||||||
|
t.compile_fail("tests/ui/type_error.rs");
|
||||||
t.compile_fail("tests/ui/where_clause.rs");
|
t.compile_fail("tests/ui/where_clause.rs");
|
||||||
}
|
}
|
||||||
|
|||||||
8
embassy-executor/tests/ui/type_error.rs
Normal file
8
embassy-executor/tests/ui/type_error.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))]
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn task() {
|
||||||
|
5
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
7
embassy-executor/tests/ui/type_error.stderr
Normal file
7
embassy-executor/tests/ui/type_error.stderr
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> tests/ui/type_error.rs:5:5
|
||||||
|
|
|
||||||
|
4 | async fn task() {
|
||||||
|
| - help: try adding a return type: `-> i32`
|
||||||
|
5 | 5
|
||||||
|
| ^ expected `()`, found integer
|
||||||
Loading…
x
Reference in New Issue
Block a user