-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support async trait bounds in macros
- Loading branch information
1 parent
bc1b9e0
commit 77ab04d
Showing
14 changed files
with
197 additions
and
27 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
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 |
---|---|---|
@@ -1,8 +1,47 @@ | ||
error: expected type, found keyword `async` | ||
error: `async` trait implementations are unsupported | ||
--> $DIR/impl-header.rs:5:6 | ||
| | ||
LL | impl async Fn<()> for F {} | ||
| ^^^^^ expected type | ||
| ^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
error[E0658]: the precise format of `Fn`-family traits' type parameters is subject to change | ||
--> $DIR/impl-header.rs:5:12 | ||
| | ||
LL | impl async Fn<()> for F {} | ||
| ^^^^^^ | ||
| | ||
= note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information | ||
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0183]: manual implementations of `Fn` are experimental | ||
--> $DIR/impl-header.rs:5:12 | ||
| | ||
LL | impl async Fn<()> for F {} | ||
| ^^^^^^ manual implementations of `Fn` are experimental | ||
| | ||
= help: add `#![feature(unboxed_closures)]` to the crate attributes to enable | ||
|
||
error[E0277]: expected a `FnMut()` closure, found `F` | ||
--> $DIR/impl-header.rs:5:23 | ||
| | ||
LL | impl async Fn<()> for F {} | ||
| ^ expected an `FnMut()` closure, found `F` | ||
| | ||
= help: the trait `FnMut<()>` is not implemented for `F` | ||
= note: wrap the `F` in a closure with no arguments: `|| { /* code */ }` | ||
note: required by a bound in `Fn` | ||
--> $SRC_DIR/core/src/ops/function.rs:LL:COL | ||
|
||
error[E0046]: not all trait items implemented, missing: `call` | ||
--> $DIR/impl-header.rs:5:1 | ||
| | ||
LL | impl async Fn<()> for F {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ missing `call` in implementation | ||
| | ||
= help: implement the missing item: `fn call(&self, _: ()) -> <Self as FnOnce<()>>::Output { todo!() }` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0046, E0183, E0277, E0658. | ||
For more information about an error, try `rustc --explain E0046`. |
21 changes: 21 additions & 0 deletions
21
tests/ui/async-await/async-fn/mbe-async-trait-bound-theoretical-regression.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,21 @@ | ||
// Demonstrates and records a theoretical regressions / breaking changes caused by the | ||
// introduction of async trait bounds. | ||
|
||
// Setting the edition to 2018 since we don't regress `demo! { dyn async }` in Rust <2018. | ||
// edition:2018 | ||
|
||
macro_rules! demo { | ||
($ty:ty) => { compile_error!("ty"); }; | ||
//~^ ERROR ty | ||
//~| ERROR ty | ||
(impl $c:ident Trait) => {}; | ||
(dyn $c:ident Trait) => {}; | ||
} | ||
|
||
demo! { impl async Trait } | ||
//~^ ERROR async closures are unstable | ||
|
||
demo! { dyn async Trait } | ||
//~^ ERROR async closures are unstable | ||
|
||
fn main() {} |
47 changes: 47 additions & 0 deletions
47
tests/ui/async-await/async-fn/mbe-async-trait-bound-theoretical-regression.stderr
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,47 @@ | ||
error: ty | ||
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:8:19 | ||
| | ||
LL | ($ty:ty) => { compile_error!("ty"); }; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | demo! { impl async Trait } | ||
| -------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: ty | ||
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:8:19 | ||
| | ||
LL | ($ty:ty) => { compile_error!("ty"); }; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | demo! { dyn async Trait } | ||
| ------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0658]: async closures are unstable | ||
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:15:14 | ||
| | ||
LL | demo! { impl async Trait } | ||
| ^^^^^ | ||
| | ||
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information | ||
= help: add `#![feature(async_closure)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= help: to use an async block, remove the `||`: `async {` | ||
|
||
error[E0658]: async closures are unstable | ||
--> $DIR/mbe-async-trait-bound-theoretical-regression.rs:18:13 | ||
| | ||
LL | demo! { dyn async Trait } | ||
| ^^^^^ | ||
| | ||
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information | ||
= help: add `#![feature(async_closure)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= help: to use an async block, remove the `||`: `async {` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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 @@ | ||
// edition: 2021 | ||
|
||
macro_rules! x { | ||
($x:item) => {} | ||
} | ||
|
||
x! { | ||
async fn foo() -> impl async Fn() { } | ||
//~^ ERROR async closures are unstable | ||
} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
tests/ui/async-await/async-fn/trait-bounds-in-macro.stderr
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,14 @@ | ||
error[E0658]: async closures are unstable | ||
--> $DIR/trait-bounds-in-macro.rs:8:28 | ||
| | ||
LL | async fn foo() -> impl async Fn() { } | ||
| ^^^^^ | ||
| | ||
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information | ||
= help: add `#![feature(async_closure)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
= help: to use an async block, remove the `||`: `async {` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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
40 changes: 27 additions & 13 deletions
40
tests/ui/rfcs/rfc-2632-const-trait-impl/mbe-const-trait-bound-theoretical-regression.stderr
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 |
---|---|---|
@@ -1,31 +1,45 @@ | ||
error: expected identifier, found `<eof>` | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:13:14 | ||
error: ty | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:8:19 | ||
| | ||
LL | ($ty:ty) => { compile_error!("ty"); }; | ||
| ------ while parsing argument for this `ty` macro fragment | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | demo! { impl const } | ||
| ^^^^^ expected identifier | ||
LL | demo! { impl const Trait } | ||
| -------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: expected identifier, found `<eof>` | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:16:13 | ||
error: ty | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:8:19 | ||
| | ||
LL | ($ty:ty) => { compile_error!("ty"); }; | ||
| ------ while parsing argument for this `ty` macro fragment | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | demo! { dyn const } | ||
| ^^^^^ expected identifier | ||
LL | demo! { dyn const Trait } | ||
| ------------------------- in this macro invocation | ||
| | ||
= note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0658]: const trait impls are experimental | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:15:14 | ||
| | ||
LL | demo! { impl const Trait } | ||
| ^^^^^ | ||
| | ||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information | ||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error[E0658]: const trait impls are experimental | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:16:13 | ||
--> $DIR/mbe-const-trait-bound-theoretical-regression.rs:18:13 | ||
| | ||
LL | demo! { dyn const } | ||
LL | demo! { dyn const Trait } | ||
| ^^^^^ | ||
| | ||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information | ||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable | ||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |