-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3434 from embassy-rs/macro-fixes
executor: improve macro error messages, add compile-fail / ui tests.
- Loading branch information
Showing
39 changed files
with
302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[cfg(not(miri))] | ||
#[test] | ||
fn ui() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/ui/abi.rs"); | ||
t.compile_fail("tests/ui/bad_return.rs"); | ||
t.compile_fail("tests/ui/generics.rs"); | ||
t.compile_fail("tests/ui/impl_trait_nested.rs"); | ||
t.compile_fail("tests/ui/impl_trait.rs"); | ||
t.compile_fail("tests/ui/impl_trait_static.rs"); | ||
t.compile_fail("tests/ui/nonstatic_ref_anon_nested.rs"); | ||
t.compile_fail("tests/ui/nonstatic_ref_anon.rs"); | ||
t.compile_fail("tests/ui/nonstatic_ref_elided.rs"); | ||
t.compile_fail("tests/ui/nonstatic_ref_generic.rs"); | ||
t.compile_fail("tests/ui/nonstatic_struct_anon.rs"); | ||
#[cfg(not(feature = "nightly"))] // we can't catch this case with the macro, so the output changes on nightly. | ||
t.compile_fail("tests/ui/nonstatic_struct_elided.rs"); | ||
t.compile_fail("tests/ui/nonstatic_struct_generic.rs"); | ||
t.compile_fail("tests/ui/not_async.rs"); | ||
t.compile_fail("tests/ui/self_ref.rs"); | ||
t.compile_fail("tests/ui/self.rs"); | ||
t.compile_fail("tests/ui/where_clause.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async extern "C" fn task() {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: task functions must not have an ABI qualifier | ||
--> tests/ui/abi.rs:6:1 | ||
| | ||
6 | async extern "C" fn task() {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task() -> u32 { | ||
5 | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: task functions must either not return a value, return `()` or return `!` | ||
--> tests/ui/bad_return.rs:6:1 | ||
| | ||
6 | async fn task() -> u32 { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task<T: Sized>(_t: T) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: task functions must not be generic | ||
--> tests/ui/generics.rs:6:1 | ||
| | ||
6 | async fn task<T: Sized>(_t: T) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
#[embassy_executor::task] | ||
async fn foo(_x: impl Sized) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `impl Trait` is not allowed in task arguments. It is syntax sugar for generics, and tasks can't be generic. | ||
--> tests/ui/impl_trait.rs:4:18 | ||
| | ||
4 | async fn foo(_x: impl Sized) {} | ||
| ^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<T>(T); | ||
|
||
#[embassy_executor::task] | ||
async fn foo(_x: Foo<impl Sized + 'static>) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `impl Trait` is not allowed in task arguments. It is syntax sugar for generics, and tasks can't be generic. | ||
--> tests/ui/impl_trait_nested.rs:6:22 | ||
| | ||
6 | async fn foo(_x: Foo<impl Sized + 'static>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
#[embassy_executor::task] | ||
async fn foo(_x: impl Sized + 'static) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: `impl Trait` is not allowed in task arguments. It is syntax sugar for generics, and tasks can't be generic. | ||
--> tests/ui/impl_trait_static.rs:4:18 | ||
| | ||
4 | async fn foo(_x: impl Sized + 'static) {} | ||
| ^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
#[embassy_executor::task] | ||
async fn foo(_x: &'_ u32) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
--> tests/ui/nonstatic_ref_anon.rs:4:19 | ||
| | ||
4 | async fn foo(_x: &'_ u32) {} | ||
| ^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
#[embassy_executor::task] | ||
async fn foo(_x: &'static &'_ u32) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
--> tests/ui/nonstatic_ref_anon_nested.rs:4:28 | ||
| | ||
4 | async fn foo(_x: &'static &'_ u32) {} | ||
| ^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
#[embassy_executor::task] | ||
async fn foo(_x: &u32) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
--> tests/ui/nonstatic_ref_elided.rs:4:18 | ||
| | ||
4 | async fn foo(_x: &u32) {} | ||
| ^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
#[embassy_executor::task] | ||
async fn foo<'a>(_x: &'a u32) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: task functions must not be generic | ||
--> tests/ui/nonstatic_ref_generic.rs:4:1 | ||
| | ||
4 | async fn foo<'a>(_x: &'a u32) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
--> tests/ui/nonstatic_ref_generic.rs:4:23 | ||
| | ||
4 | async fn foo<'a>(_x: &'a u32) {} | ||
| ^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task(_x: Foo<'_>) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
--> tests/ui/nonstatic_struct_anon.rs:6:23 | ||
| | ||
6 | async fn task(_x: Foo<'_>) {} | ||
| ^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task(_x: Foo) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error[E0726]: implicit elided lifetime not allowed here | ||
--> tests/ui/nonstatic_struct_elided.rs:6:19 | ||
| | ||
6 | async fn task(_x: Foo) {} | ||
| ^^^ expected lifetime parameter | ||
| | ||
help: indicate the anonymous lifetime | ||
| | ||
6 | async fn task(_x: Foo<'_>) {} | ||
| ++++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task<'a>(_x: Foo<'a>) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: task functions must not be generic | ||
--> tests/ui/nonstatic_struct_generic.rs:6:1 | ||
| | ||
6 | async fn task<'a>(_x: Foo<'a>) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: Arguments for tasks must live forever. Try using the `'static` lifetime. | ||
--> tests/ui/nonstatic_struct_generic.rs:6:27 | ||
| | ||
6 | async fn task<'a>(_x: Foo<'a>) {} | ||
| ^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
fn task() {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: task functions must be async | ||
--> tests/ui/not_async.rs:6:1 | ||
| | ||
6 | fn task() {} | ||
| ^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task(self) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: task functions must not have `self` arguments | ||
--> tests/ui/self.rs:6:15 | ||
| | ||
6 | async fn task(self) {} | ||
| ^^^^ | ||
|
||
error: `self` parameter is only allowed in associated functions | ||
--> tests/ui/self.rs:6:15 | ||
| | ||
6 | async fn task(self) {} | ||
| ^^^^ not semantically valid as function parameter | ||
| | ||
= note: associated functions are those in `impl` or `trait` definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task(&mut self) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: task functions must not have `self` arguments | ||
--> tests/ui/self_ref.rs:6:15 | ||
| | ||
6 | async fn task(&mut self) {} | ||
| ^^^^^^^^^ | ||
|
||
error: `self` parameter is only allowed in associated functions | ||
--> tests/ui/self_ref.rs:6:15 | ||
| | ||
6 | async fn task(&mut self) {} | ||
| ^^^^^^^^^ not semantically valid as function parameter | ||
| | ||
= note: associated functions are those in `impl` or `trait` definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![cfg_attr(feature = "nightly", feature(impl_trait_in_assoc_type))] | ||
|
||
struct Foo<'a>(&'a ()); | ||
|
||
#[embassy_executor::task] | ||
async fn task() | ||
where | ||
(): Sized, | ||
{ | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error: task functions must not have `where` clauses | ||
--> tests/ui/where_clause.rs:6:1 | ||
| | ||
6 | / async fn task() | ||
7 | | where | ||
8 | | (): Sized, | ||
| |______________^ |