async-recursion-1.1.1/.cargo_vcs_info.json0000644000000001360000000000100141600ustar { "git": { "sha1": "3254b12e384f7688f9a1b95c54cfa07fe82baee7" }, "path_in_vcs": "" }async-recursion-1.1.1/.github/dependabot.yml000064400000000000000000000002211046102023000171330ustar 00000000000000version: 2 updates: - package-ecosystem: cargo directory: "/" schedule: interval: daily time: "19:00" open-pull-requests-limit: 10 async-recursion-1.1.1/.github/workflows/ci.yml000064400000000000000000000021171046102023000174640ustar 00000000000000name: CI on: push: branches: - master pull_request: schedule: [cron: "0 0 * * *"] permissions: contents: read env: RUSTFLAGS: -Dwarnings jobs: test: name: Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable with: components: rust-src # required for consistent error messages - run: cargo install cargo-expand - run: cargo test --verbose fmt: name: Fmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly with: components: rustfmt - run: cargo fmt -- --check clippy: name: Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly with: components: clippy - run: cargo clippy -- -Dwarnings outdated: name: Outdated runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dtolnay/install@cargo-outdated - run: cargo outdated --exit-code 1 async-recursion-1.1.1/.gitignore000064400000000000000000000000671046102023000147430ustar 00000000000000/target **/*.rs.bk Cargo.lock .idea async-recursion.imlasync-recursion-1.1.1/Cargo.toml0000644000000024030000000000100121550ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "async-recursion" version = "1.1.1" authors = ["Robert Usher <266585+dcchut@users.noreply.github.com>"] description = "Recursion for async functions" documentation = "https://docs.rs/async-recursion" readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/dcchut/async-recursion" [lib] proc-macro = true [dependencies.proc-macro2] version = "1.0" default-features = false [dependencies.quote] version = "1.0" default-features = false [dependencies.syn] version = "2.0" features = [ "full", "visit-mut", "parsing", "printing", "proc-macro", "clone-impls", ] default-features = false [dev-dependencies.futures-executor] version = "0.3" [dev-dependencies.macrotest] version = "1.0" [dev-dependencies.trybuild] version = "1.0" async-recursion-1.1.1/Cargo.toml.orig000064400000000000000000000013131046102023000156350ustar 00000000000000[package] name = "async-recursion" version = "1.1.1" authors = ["Robert Usher <266585+dcchut@users.noreply.github.com>"] edition = "2018" license = "MIT OR Apache-2.0" description = "Recursion for async functions" repository = "https://github.com/dcchut/async-recursion" documentation = "https://docs.rs/async-recursion" readme = "README.md" [lib] proc-macro = true [dependencies] proc-macro2 = { version = "1.0", default-features = false } quote = { version = "1.0", default-features = false } syn = { version = "2.0", features = ["full", "visit-mut", "parsing", "printing", "proc-macro", "clone-impls"], default-features = false } [dev-dependencies] futures-executor = "0.3" trybuild = "1.0" macrotest = "1.0"async-recursion-1.1.1/LICENSE-APACHE000064400000000000000000000251361046102023000147030ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.async-recursion-1.1.1/LICENSE-MIT000064400000000000000000000017761046102023000144170ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.async-recursion-1.1.1/README.md000064400000000000000000000052301046102023000142270ustar 00000000000000# async-recursion macro [![Latest version](https://img.shields.io/crates/v/async-recursion)](https://crates.io/crates/async-recursion) [![crates.io downloads](https://img.shields.io/crates/d/async_recursion)](https://crates.io/crates/async-recursion) [![Build Status](https://img.shields.io/github/actions/workflow/status/dcchut/async-recursion/ci.yml?branch=master)](https://github.com/dcchut/async-recursion/actions) ![Apache/MIT2.0 License](https://img.shields.io/crates/l/async-recursion) Procedural macro for recursive async functions. * [Documentation](https://docs.rs/async-recursion/) * Cargo package: [async-recursion](https://crates.io/crates/async-recursion) ## Motivation Consider the following recursive implementation of the fibonacci numbers: ```rust,compile_fail async fn fib(n : u32) -> u32 { match n { 0 | 1 => 1, _ => fib(n-1).await + fib(n-2).await } } ``` The compiler helpfully tells us that: ```console error[E0733]: recursion in an `async fn` requires boxing --> src/main.rs:1:26 | 1 | async fn fib(n : u32) -> u32 { | ^^^ recursive `async fn` | = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future` = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion ``` This crate provides an attribute macro to automatically convert an async function to one returning a boxed `Future`. ## Example ```rust use async_recursion::async_recursion; #[async_recursion] async fn fib(n : u32) -> u32 { match n { 0 | 1 => 1, _ => fib(n-1).await + fib(n-2).await } } ``` ## ?Send option The returned `Future` has a `Send` bound to make sure it can be sent between threads. If this is undesirable you can mark that the bound should be left out like so: ```rust #[async_recursion(?Send)] async fn returned_future_is_not_send() { // ... } ``` ## Sync option The returned `Future` doesn't have a `Sync` bound as it is usually not required. You can include a `Sync` bound as follows: ```rust #[async_recursion(Sync)] async fn returned_future_is_sync() { // ... } ``` In detail: - `#[async_recursion]` modifies your function to return a boxed `Future` with a `Send` bound. - `#[async_recursion(?Send)]` modifies your function to return a boxed `Future` _without_ a `Send` bound. - `#[async_recursion(Sync)]` modifies your function to return a boxed `Future` with a `Send` and `Sync` bound. ### License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or ) * MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. async-recursion-1.1.1/rustfmt.toml000064400000000000000000000001011046102023000153410ustar 00000000000000group_imports = "StdExternalCrate" imports_granularity = "Crate" async-recursion-1.1.1/src/expand.rs000064400000000000000000000142071046102023000153700ustar 00000000000000use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; use syn::{ parse_quote, punctuated::Punctuated, visit_mut::VisitMut, Block, Lifetime, Receiver, ReturnType, Signature, TypeReference, WhereClause, }; use crate::parse::{AsyncItem, RecursionArgs}; impl ToTokens for AsyncItem { fn to_tokens(&self, tokens: &mut TokenStream) { self.0.to_tokens(tokens); } } pub fn expand(item: &mut AsyncItem, args: &RecursionArgs) { item.0.attrs.push(parse_quote!(#[must_use])); transform_sig(&mut item.0.sig, args); transform_block(&mut item.0.block); } fn transform_block(block: &mut Block) { let brace = block.brace_token; *block = parse_quote!({ Box::pin(async move #block) }); block.brace_token = brace; } enum ArgLifetime { New(Lifetime), Existing(Lifetime), } impl ArgLifetime { pub fn lifetime(self) -> Lifetime { match self { ArgLifetime::New(lt) | ArgLifetime::Existing(lt) => lt, } } } #[derive(Default)] struct ReferenceVisitor { counter: usize, lifetimes: Vec, self_receiver: bool, self_receiver_new_lifetime: bool, self_lifetime: Option, } impl VisitMut for ReferenceVisitor { fn visit_receiver_mut(&mut self, receiver: &mut Receiver) { self.self_lifetime = Some(if let Some((_, lt)) = &mut receiver.reference { self.self_receiver = true; if let Some(lt) = lt { lt.clone() } else { // Use 'life_self to avoid collisions with 'life lifetimes. let new_lifetime: Lifetime = parse_quote!('life_self); lt.replace(new_lifetime.clone()); self.self_receiver_new_lifetime = true; new_lifetime } } else { return; }); } fn visit_type_reference_mut(&mut self, argument: &mut TypeReference) { if argument.lifetime.is_none() { // If this reference doesn't have a lifetime (e.g. &T), then give it one. let lt = Lifetime::new(&format!("'life{}", self.counter), Span::call_site()); self.lifetimes.push(ArgLifetime::New(parse_quote!(#lt))); argument.lifetime = Some(lt); self.counter += 1; } else { // If it does (e.g. &'life T), then keep track of it. let lt = argument.lifetime.as_ref().cloned().unwrap(); // Check that this lifetime isn't already in our vector let ident_matches = |x: &ArgLifetime| { if let ArgLifetime::Existing(elt) = x { elt.ident == lt.ident } else { false } }; if !self.lifetimes.iter().any(ident_matches) { self.lifetimes.push(ArgLifetime::Existing(lt)); } } } } // Input: // async fn f(x : S, y : &T) -> Ret; // // Output: // fn f(x : S, y : &T) -> Pin + Send> fn transform_sig(sig: &mut Signature, args: &RecursionArgs) { // Determine the original return type let ret = match &sig.output { ReturnType::Default => quote!(()), ReturnType::Type(_, ret) => quote!(#ret), }; // Remove the asyncness of this function sig.asyncness = None; // Find and update any references in the input arguments let mut v = ReferenceVisitor::default(); for input in &mut sig.inputs { v.visit_fn_arg_mut(input); } // Does this expansion require `async_recursion to be added to the output? let mut requires_lifetime = false; let mut where_clause_lifetimes = vec![]; let mut where_clause_generics = vec![]; // 'async_recursion lifetime let asr: Lifetime = parse_quote!('async_recursion); // Add an S : 'async_recursion bound to any generic parameter for param in sig.generics.type_params() { let ident = param.ident.clone(); where_clause_generics.push(ident); requires_lifetime = true; } // Add an 'a : 'async_recursion bound to any lifetimes 'a appearing in the function if !v.lifetimes.is_empty() { requires_lifetime = true; for alt in v.lifetimes { if let ArgLifetime::New(lt) = &alt { // If this is a new argument, sig.generics.params.push(parse_quote!(#lt)); } // Add a bound to the where clause let lt = alt.lifetime(); where_clause_lifetimes.push(lt); } } // If our function accepts &self, then we modify this to the explicit lifetime &'life_self, // and add the bound &'life_self : 'async_recursion if v.self_receiver { if v.self_receiver_new_lifetime { sig.generics.params.push(parse_quote!('life_self)); } where_clause_lifetimes.extend(v.self_lifetime); requires_lifetime = true; } let box_lifetime: TokenStream = if requires_lifetime { // Add 'async_recursion to our generic parameters sig.generics.params.push(parse_quote!('async_recursion)); quote!(+ #asr) } else { quote!() }; let send_bound: TokenStream = if args.send_bound { quote!(+ ::core::marker::Send) } else { quote!() }; let sync_bound: TokenStream = if args.sync_bound { quote!(+ ::core::marker::Sync) } else { quote!() }; let where_clause = sig .generics .where_clause .get_or_insert_with(|| WhereClause { where_token: Default::default(), predicates: Punctuated::new(), }); // Add our S : 'async_recursion bounds for generic_ident in where_clause_generics { where_clause .predicates .push(parse_quote!(#generic_ident : #asr)); } // Add our 'a : 'async_recursion bounds for lifetime in where_clause_lifetimes { where_clause.predicates.push(parse_quote!(#lifetime : #asr)); } // Modify the return type sig.output = parse_quote! { -> ::core::pin::Pin #box_lifetime #send_bound #sync_bound>> }; } async-recursion-1.1.1/src/lib.rs000064400000000000000000000067741046102023000146710ustar 00000000000000//! # async-recursion macro //! //! [![Latest version](https://img.shields.io/crates/v/async-recursion)](https://crates.io/crates/async-recursion) //! [![crates.io downloads](https://img.shields.io/crates/d/async_recursion)](https://crates.io/crates/async-recursion) //! [![Build Status](https://img.shields.io/github/actions/workflow/status/dcchut/async-recursion/ci.yml?branch=master)](https://github.com/dcchut/async-recursion/actions) //! ![Apache/MIT2.0 License](https://img.shields.io/crates/l/async-recursion) //! //! Procedural macro for recursive async functions. //! //! * [Documentation](https://docs.rs/async-recursion/) //! * Cargo package: [async-recursion](https://crates.io/crates/async-recursion) //! //! ## Motivation //! Consider the following recursive implementation of the fibonacci numbers: //! //! ```rust,compile_fail //! async fn fib(n : u32) -> u32 { //! match n { //! 0 | 1 => 1, //! _ => fib(n-1).await + fib(n-2).await //! } //! } //! ``` //! //! The compiler helpfully tells us that: //! //! ```console //! error[E0733]: recursion in an `async fn` requires boxing //! --> src/main.rs:1:26 //! | //! 1 | async fn fib(n : u32) -> u32 { //! | ^^^ recursive `async fn` //! | //! = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`. //! = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion //! ``` //! //! This crate provides an attribute macro to automatically convert an async function //! to one returning a boxed [`Future`](core::future::Future). //! //! ## Example //! //! ```rust //! use async_recursion::async_recursion; //! //! #[async_recursion] //! async fn fib(n : u32) -> u32 { //! match n { //! 0 | 1 => 1, //! _ => fib(n-1).await + fib(n-2).await //! } //! } //! ``` //! //! ## ?Send option //! //! The returned [`Future`] has a [`Send`] bound to make sure it can be sent between threads. //! If this is undesirable you can mark that the bound should be left out like so: //! //! ```rust //! # use async_recursion::async_recursion; //! //! #[async_recursion(?Send)] //! async fn returned_future_is_not_send() { //! // ... //! } //! ``` //! //! ## Sync option //! //! The returned [`Future`] doesn't have a [`Sync`] bound as it is usually not required. //! You can include a [`Sync`] bound as follows: //! //! ```rust //! # use async_recursion::async_recursion; //! //! #[async_recursion(Sync)] //! async fn returned_future_is_send_and_sync() { //! // ... //! } //! ``` //! //! In detail: //! //! //! - `#[async_recursion]` modifies your function to return a boxed [`Future`] with a [`Send`] bound. //! - `#[async_recursion(?Send)]` modifies your function to return a boxed [`Future`] _without_ a [`Send`] bound. //! - `#[async_recursion(Sync)]` modifies your function to return a boxed [`Future`] with [`Send`] and [`Sync`] bounds. //! //! ### License //! //! Licensed under either of //! * Apache License, Version 2.0 () //! * MIT license () //! //! at your option. extern crate proc_macro; mod expand; mod parse; use proc_macro::TokenStream; use quote::quote; use syn::parse_macro_input; #[proc_macro_attribute] pub fn async_recursion(args: TokenStream, input: TokenStream) -> TokenStream { let mut item = parse_macro_input!(input as parse::AsyncItem); let args = parse_macro_input!(args as parse::RecursionArgs); expand::expand(&mut item, &args); TokenStream::from(quote!(#item)) } async-recursion-1.1.1/src/parse.rs000064400000000000000000000046021046102023000152210ustar 00000000000000use proc_macro2::Span; use syn::{ parse::{Error, Parse, ParseStream, Result}, token::Question, ItemFn, Token, }; pub struct AsyncItem(pub ItemFn); impl Parse for AsyncItem { fn parse(input: ParseStream) -> Result { let item: ItemFn = input.parse()?; // Check that this is an async function if item.sig.asyncness.is_none() { return Err(Error::new(Span::call_site(), "expected an async function")); } Ok(AsyncItem(item)) } } pub struct RecursionArgs { pub send_bound: bool, pub sync_bound: bool, } /// Custom keywords for parser mod kw { syn::custom_keyword!(Send); syn::custom_keyword!(Sync); } #[derive(Debug, PartialEq, Eq)] enum Arg { NotSend, Sync, } impl std::fmt::Display for Arg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::NotSend => write!(f, "?Send"), Self::Sync => write!(f, "Sync"), } } } impl Parse for Arg { fn parse(input: ParseStream) -> Result { if input.peek(Token![?]) { input.parse::()?; input.parse::()?; Ok(Arg::NotSend) } else { input.parse::()?; Ok(Arg::Sync) } } } impl Parse for RecursionArgs { fn parse(input: ParseStream) -> Result { let mut send_bound: bool = true; let mut sync_bound: bool = false; let args_parsed: Vec = syn::punctuated::Punctuated::::parse_terminated(input) .map_err(|e| input.error(format!("failed to parse macro arguments: {e}")))? .into_iter() .collect(); // Avoid sloppy input if args_parsed.len() > 2 { return Err(Error::new(Span::call_site(), "received too many arguments")); } else if args_parsed.len() == 2 && args_parsed[0] == args_parsed[1] { return Err(Error::new( Span::call_site(), format!("received duplicate argument: `{}`", args_parsed[0]), )); } for arg in args_parsed { match arg { Arg::NotSend => send_bound = false, Arg::Sync => sync_bound = true, } } Ok(Self { send_bound, sync_bound, }) } } async-recursion-1.1.1/tests/args_sync.rs000064400000000000000000000003431046102023000164500ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(Sync)] async fn send_and_sync() {} fn assert_is_send_and_sync(_: impl Send + Sync) {} #[test] fn test_sync_argument() { assert_is_send_and_sync(send_and_sync()); } async-recursion-1.1.1/tests/compiletest.rs000064400000000000000000000002461046102023000170120ustar 00000000000000#[test] fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/ui/*.rs"); } #[test] fn expand() { macrotest::expand("tests/expand/*.rs"); } async-recursion-1.1.1/tests/core_module.rs000064400000000000000000000003251046102023000167550ustar 00000000000000use async_recursion::async_recursion; mod core { // already defined core module shouldn't fail with message like 'could not find `pin` in `core`' } #[async_recursion] pub async fn n(x: i32) -> i32 { x } async-recursion-1.1.1/tests/expand/args_not_send.expanded.rs000064400000000000000000000002471046102023000223560ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn no_send_bound() -> ::core::pin::Pin>> { Box::pin(async move {}) } async-recursion-1.1.1/tests/expand/args_not_send.rs000064400000000000000000000001341046102023000205620ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(?Send)] async fn no_send_bound() {}async-recursion-1.1.1/tests/expand/args_punctuated.expanded.rs000064400000000000000000000012521046102023000227160ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn not_send_sync_1() -> ::core::pin::Pin< Box + ::core::marker::Sync>, > { Box::pin(async move {}) } #[must_use] fn not_send_sync_2() -> ::core::pin::Pin< Box + ::core::marker::Sync>, > { Box::pin(async move {}) } #[must_use] fn sync_not_send_1() -> ::core::pin::Pin< Box + ::core::marker::Sync>, > { Box::pin(async move {}) } #[must_use] fn sync_not_send_2() -> ::core::pin::Pin< Box + ::core::marker::Sync>, > { Box::pin(async move {}) } async-recursion-1.1.1/tests/expand/args_punctuated.rs000064400000000000000000000004371046102023000211330ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(?Send, Sync)] async fn not_send_sync_1() {} #[async_recursion(?Send,Sync)] async fn not_send_sync_2() {} #[async_recursion(Sync, ?Send)] async fn sync_not_send_1() {} #[async_recursion(Sync,?Send)] async fn sync_not_send_2() {}async-recursion-1.1.1/tests/expand/args_sync.expanded.rs000064400000000000000000000003711046102023000215170ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn sync() -> ::core::pin::Pin< Box< dyn ::core::future::Future< Output = (), > + ::core::marker::Send + ::core::marker::Sync, >, > { Box::pin(async move {}) } async-recursion-1.1.1/tests/expand/args_sync.rs000064400000000000000000000001221046102023000177220ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(Sync)] async fn sync() {}async-recursion-1.1.1/tests/expand/core_module.expanded.rs000064400000000000000000000003161046102023000220230ustar 00000000000000use async_recursion::async_recursion; #[must_use] pub fn n( x: i32, ) -> ::core::pin::Pin< Box + ::core::marker::Send>, > { Box::pin(async move { x }) } async-recursion-1.1.1/tests/expand/core_module.rs000064400000000000000000000001421046102023000202310ustar 00000000000000use async_recursion::async_recursion; #[async_recursion] pub async fn n(x: i32) -> i32 { x } async-recursion-1.1.1/tests/expand/fibonacci.expanded.rs000064400000000000000000000006771046102023000214550ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn fib( n: u32, ) -> ::core::pin::Pin< Box + ::core::marker::Send>, > { Box::pin(async move { match n { 0 => { ::std::rt::begin_panic("zero is not a valid argument to fib()!"); } 1 | 2 => 1, 3 => 2, _ => fib(n - 1).await + fib(n - 2).await, } }) } async-recursion-1.1.1/tests/expand/fibonacci.rs000064400000000000000000000004021046102023000176500ustar 00000000000000use async_recursion::async_recursion; #[async_recursion] async fn fib(n: u32) -> u64 { match n { 0 => panic!("zero is not a valid argument to fib()!"), 1 | 2 => 1, 3 => 2, _ => fib(n - 1).await + fib(n - 2).await, } }async-recursion-1.1.1/tests/expand/generic_parameter.expanded.rs000064400000000000000000000006231046102023000232030ustar 00000000000000use async_recursion::async_recursion; #[must_use] pub fn generic_parameter<'async_recursion, S: Marker + Send>( mut x: S, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future< Output = u64, > + 'async_recursion + ::core::marker::Send, >, > where S: 'async_recursion, { Box::pin(async move { if x.descend() { generic_parameter(x).await } else { 0 } }) } async-recursion-1.1.1/tests/expand/generic_parameter.rs000064400000000000000000000003241046102023000214120ustar 00000000000000use async_recursion::async_recursion; #[async_recursion] pub async fn generic_parameter(mut x: S) -> u64 { if x.descend() { generic_parameter(x).await } else { 0 } }async-recursion-1.1.1/tests/expand/generic_parameter_no_send.expanded.rs000064400000000000000000000005471046102023000247150ustar 00000000000000use async_recursion::async_recursion; #[must_use] pub fn generic_parameter_no_send<'async_recursion, T>( x: T, y: u64, ) -> ::core::pin::Pin + 'async_recursion>> where T: 'async_recursion, { Box::pin(async move { if y > 0 { generic_parameter_no_send(x, y - 1).await } else { 111 } }) } async-recursion-1.1.1/tests/expand/generic_parameter_no_send.rs000064400000000000000000000003431046102023000231200ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(?Send)] pub async fn generic_parameter_no_send(x: T, y: u64) -> u64 { if y > 0 { generic_parameter_no_send(x, y - 1).await } else { 111 } }async-recursion-1.1.1/tests/expand/lifetimes_explicit_async_recursion_bound.expanded.rs000064400000000000000000000010071046102023000300630ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn explicit_async_recursion_bound<'life0, 'life1, 'async_recursion>( t: &'life0 T, p: &'life1 [String], prefix: Option<&'async_recursion [u8]>, layer: Option<&'async_recursion [u8]>, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future + 'async_recursion + ::core::marker::Send, >, > where 'life0: 'async_recursion, 'life1: 'async_recursion, 'async_recursion: 'async_recursion, { Box::pin(async move {}) } async-recursion-1.1.1/tests/expand/lifetimes_explicit_async_recursion_bound.rs000064400000000000000000000004701046102023000262770ustar 00000000000000// Test that an explicit `async_recursion bound is left alone. // This is a workaround many use async_recursion::async_recursion; #[async_recursion] async fn explicit_async_recursion_bound( t: &T, p: &[String], prefix: Option<&'async_recursion [u8]>, layer: Option<&'async_recursion [u8]>, ) {}async-recursion-1.1.1/tests/expand/lifetimes_multiple.expanded.rs000064400000000000000000000005611046102023000234240ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn contains_value_2<'a, 'b, 'async_recursion, T: PartialEq>( value: &'b T, node: &'b Node<'a, T>, ) -> ::core::pin::Pin + 'async_recursion>> where T: 'async_recursion, 'b: 'async_recursion, { Box::pin(async move { contains_value(value, node).await }) } async-recursion-1.1.1/tests/expand/lifetimes_multiple.rs000064400000000000000000000003071046102023000216330ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(?Send)] async fn contains_value_2<'a, 'b, T: PartialEq>(value: &'b T, node: &'b Node<'a, T>) -> bool { contains_value(value, node).await }async-recursion-1.1.1/tests/expand/lifetimes_nested_reference.expanded.rs000064400000000000000000000005751046102023000250760ustar 00000000000000use async_recursion::async_recursion; #[must_use] fn count_down<'life0, 'async_recursion>( foo: Option<&'life0 str>, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future< Output = i32, > + 'async_recursion + ::core::marker::Send, >, > where 'life0: 'async_recursion, { Box::pin(async move { let _ = foo; 0 }) } async-recursion-1.1.1/tests/expand/lifetimes_nested_reference.rs000064400000000000000000000002021046102023000232720ustar 00000000000000use async_recursion::async_recursion; #[async_recursion] async fn count_down(foo: Option<&str>) -> i32 { let _ = foo; 0 }async-recursion-1.1.1/tests/expand/lifetimes_no_send_bound.expanded.rs000064400000000000000000000007301046102023000244030ustar 00000000000000use async_recursion::async_recursion; struct Node<'a, T> { ptr: &'a T, } #[must_use] fn contains_value<'a, 'life0, 'life1, 'async_recursion, T: PartialEq>( value: &'life0 T, node: &'life1 Node<'a, T>, ) -> ::core::pin::Pin + 'async_recursion>> where T: 'async_recursion, 'life0: 'async_recursion, 'life1: 'async_recursion, { Box::pin(async move { if &node.ptr == value { true } else { false } }) } async-recursion-1.1.1/tests/expand/lifetimes_no_send_bound.rs000064400000000000000000000004071046102023000226150ustar 00000000000000use async_recursion::async_recursion; struct Node<'a, T> { ptr: &'a T, } #[async_recursion(?Send)] async fn contains_value<'a, T: PartialEq>(value: &T, node: &Node<'a, T>) -> bool { if &node.ptr == value { true } else { false } }async-recursion-1.1.1/tests/expand/macros_nested.expanded.rs000064400000000000000000000022711046102023000223560ustar 00000000000000#[must_use] fn owned<'life0, 'async_recursion, F>( param: usize, f: &'life0 F, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future + 'async_recursion + ::core::marker::Send, >, > where F: Fn(usize) + Sync + Send, F: 'async_recursion, 'life0: 'async_recursion, { Box::pin(async move { f(param); }) } #[must_use] fn by_ref<'life0, 'life1, 'async_recursion, F>( param: &'life0 usize, f: &'life1 F, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future + 'async_recursion + ::core::marker::Send, >, > where F: Fn(&usize) + Sync + Send, F: 'async_recursion, 'life0: 'async_recursion, 'life1: 'async_recursion, { Box::pin(async move { f(param); }) } #[must_use] fn by_ref_mut<'life0, 'life1, 'async_recursion, F>( param: &'life0 mut usize, f: &'life1 F, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future + 'async_recursion + ::core::marker::Send, >, > where F: Fn(&mut usize) + Sync + Send, F: 'async_recursion, 'life0: 'async_recursion, 'life1: 'async_recursion, { Box::pin(async move { f(param); }) } async-recursion-1.1.1/tests/expand/macros_nested.rs000064400000000000000000000005251046102023000205670ustar 00000000000000macro_rules! recurse { ($name:ident, $param:ty) => { #[::async_recursion::async_recursion] async fn $name(param: $param, f: &F) where F: Fn($param) + Sync + Send, { f(param); } }; } recurse!(owned, usize); recurse!(by_ref, &usize); recurse!(by_ref_mut, &mut usize);async-recursion-1.1.1/tests/expand/struct_methods.expanded.rs000064400000000000000000000014031046102023000225730ustar 00000000000000use async_recursion::async_recursion; struct S; impl S { #[must_use] pub fn all_of_the_above<'a, 'b, 'life0, 'life1, 'life_self, 'async_recursion, S, T>( &'life_self self, _x: &'life0 S, _y: &'b T, _w: S, _z: T, _p: &'life1 usize, _q: &'a u64, ) -> ::core::pin::Pin< Box< dyn ::core::future::Future< Output = (), > + 'async_recursion + ::core::marker::Send, >, > where S: 'async_recursion, T: 'async_recursion, 'life0: 'async_recursion, 'b: 'async_recursion, 'life1: 'async_recursion, 'a: 'async_recursion, 'life_self: 'async_recursion, { Box::pin(async move {}) } } async-recursion-1.1.1/tests/expand/struct_methods.rs000064400000000000000000000007771046102023000210210ustar 00000000000000use async_recursion::async_recursion; struct S; impl S { #[async_recursion] pub async fn all_of_the_above<'a, 'b, S, T>( &self, // Some references with / without lifetimes to generic parameters _x: &S, _y: &'b T, // Some generic parameters passed by value _w: S, _z: T, // A reference to a concrete type without a lifetime _p: &usize, // A reference to a concrete type with a lifetime _q: &'a u64, ) { } }async-recursion-1.1.1/tests/fibonacci.rs000064400000000000000000000011621046102023000163750ustar 00000000000000use async_recursion::async_recursion; use futures_executor::block_on; #[async_recursion] async fn fib(n: u32) -> u64 { match n { 0 => panic!("zero is not a valid argument to fib()!"), 1 | 2 => 1, 3 => 2, _ => fib(n - 1).await + fib(n - 2).await, } } #[test] fn fibonacci_example_works() { block_on(async move { assert_eq!(fib(3).await, 2); assert_eq!(fib(4).await, 3); assert_eq!(fib(5).await, 5); assert_eq!(fib(6).await, 8); }); } #[test] fn fibonacci_example_is_send() { fn assert_is_send(_: impl Send) {} assert_is_send(fib(6)); } async-recursion-1.1.1/tests/generic_parameters.rs000064400000000000000000000023311046102023000203160ustar 00000000000000use async_recursion::async_recursion; use futures_executor::block_on; pub trait ThirtySeven { fn thirty_seven(&self) -> u64 { 37 } fn descend(&mut self) -> bool; } struct Silly { counter: usize, } impl ThirtySeven for Silly { fn descend(&mut self) -> bool { if self.counter == 0 { false } else { self.counter -= 1; true } } } #[async_recursion] pub async fn generic_parameter(mut x: S) -> u64 { if x.descend() { generic_parameter(x).await } else { x.thirty_seven() } } #[async_recursion(?Send)] pub async fn generic_parameter_no_send(x: T, y: u64) -> u64 { if y > 0 { generic_parameter_no_send(x, y - 1).await } else { 111 } } #[test] fn generic_parameter_is_send() { fn assert_is_send(_: impl Send) {} assert_is_send(generic_parameter(Silly { counter: 10 })); } #[test] fn generic_parameter_bounds() { block_on(async move { let s = Silly { counter: 45 }; assert_eq!(generic_parameter(s).await, 37); assert_eq!( generic_parameter_no_send(Silly { counter: 999 }, 10).await, 111 ); }); } async-recursion-1.1.1/tests/lifetimes.rs000064400000000000000000000047051046102023000164470ustar 00000000000000use async_recursion::async_recursion; use futures_executor::block_on; struct Node<'a, T> { value: T, left: Option<&'a Node<'a, T>>, right: Option<&'a Node<'a, T>>, } impl Node<'_, T> { pub fn new(value: T) -> Self { Self { value, left: None, right: None, } } } // Note: Use the `?Send` notation here allows us not to require that our type parameter `T` is // `T: PartialEq + Sync + Send`. #[async_recursion(?Send)] async fn contains_value<'a, T: PartialEq>(value: &T, node: &Node<'a, T>) -> bool { if &node.value == value { true } else { (node.left.is_some() && contains_value(value, node.left.unwrap()).await) || (node.right.is_some() && contains_value(value, node.right.unwrap()).await) } } #[async_recursion(?Send)] async fn contains_value_2<'a, 'b, T: PartialEq>(value: &'b T, node: &'b Node<'a, T>) -> bool { contains_value(value, node).await } // The reference inside foo needs a `async_recursion bound #[async_recursion] async fn count_down(foo: Option<&str>) -> i32 { let _ = foo; 0 } #[async_recursion] async fn explicit_async_recursion_bound(_: Option<&'async_recursion String>) {} #[test] fn lifetime_expansion_works() { block_on(async move { let mut node = Node::new(10); let mut left = Node::new(5); let left_left = Node::new(3); let left_right = Node::new(7); let mut right = Node::new(15); let right_left = Node::new(13); let right_right = Node::new(17); left.left = Some(&left_left); left.right = Some(&left_right); right.left = Some(&right_left); right.right = Some(&right_right); node.left = Some(&left); node.right = Some(&right); assert_eq!(contains_value(&3, &node).await, true); assert_eq!(contains_value(&4, &node).await, false); assert_eq!(contains_value(&17, &node).await, true); assert_eq!(contains_value(&13, &node).await, true); assert_eq!(contains_value(&12, &node).await, false); assert_eq!(contains_value_2(&3, &node).await, true); assert_eq!(contains_value_2(&4, &node).await, false); assert_eq!(contains_value_2(&17, &node).await, true); assert_eq!(contains_value_2(&13, &node).await, true); assert_eq!(contains_value_2(&12, &node).await, false); count_down(None).await; explicit_async_recursion_bound(None).await; }); } async-recursion-1.1.1/tests/macros_all_the_way_down.rs000064400000000000000000000010511046102023000213400ustar 00000000000000use futures_executor::block_on; macro_rules! recurse { ($name:ident, $param:ty) => { #[::async_recursion::async_recursion] async fn $name(param: $param, f: &F) where F: Fn($param) + Sync + Send, { f(param); } }; } recurse!(owned, usize); recurse!(by_ref, &usize); recurse!(by_ref_mut, &mut usize); #[test] fn async_in_macro() { block_on(async move { owned(5, &|_| ()).await; by_ref(&5, &|_| ()).await; by_ref_mut(&mut 5, &|_| ()).await; }); } async-recursion-1.1.1/tests/struct_methods.rs000064400000000000000000000035161046102023000175340ustar 00000000000000use async_recursion::async_recursion; use futures_executor::block_on; pub struct Empty {} impl Empty { #[async_recursion] pub async fn fib(&self, n: u32) -> u64 { match n { 0 => panic!("zero is not a valid argument to fib()!"), 1 | 2 => 1, 3 => 2, _ => self.fib(n - 1).await + self.fib(n - 2).await, } } #[async_recursion] pub async fn empty_string<'a>(&self, some_str: &'a str) -> &'a str { if some_str.is_empty() { "" } else { self.empty_string(&some_str[1..]).await } } #[async_recursion] pub async fn generic_parameter(&self, _something: &T) -> u64 { 0 } #[async_recursion] pub async fn all_of_the_above<'a, 'b, S, T>( &self, // Some references with / without lifetimes to generic parameters _x: &S, _y: &'b T, // Some generic parameters passed by value _w: S, _z: T, // A reference to a concrete type without a lifetime _p: &usize, // A reference to a concrete type with a lifetime _q: &'a u64, ) { } } #[test] fn struct_method_fib_works() { block_on(async move { let e = Empty {}; assert_eq!(e.fib(6).await, 8); assert_eq!(e.fib(5).await, 5); assert_eq!(e.fib(7).await, 13); }); } #[test] fn struct_method_empty_string_works() { block_on(async move { let e = Empty {}; assert_eq!(e.empty_string("hello world").await, ""); assert_eq!(e.empty_string("something else").await, ""); }); } #[test] fn struct_method_with_generic_parameter_works() { block_on(async move { let e = Empty {}; assert_eq!( e.generic_parameter::<*const u64>(&(0 as *const u64)).await, 0 ); }) } async-recursion-1.1.1/tests/ui/arg_not_sync.rs000064400000000000000000000004221046102023000175600ustar 00000000000000use async_recursion::async_recursion; fn assert_is_sync(_: impl Sync) {} #[async_recursion] async fn send_not_sync() {} #[async_recursion(?Send)] async fn not_send_not_sync() {} fn main() { assert_is_sync(send_not_sync()); assert_is_sync(not_send_not_sync()); }async-recursion-1.1.1/tests/ui/arg_not_sync.stderr000064400000000000000000000042721046102023000204460ustar 00000000000000error[E0277]: `dyn Future + Send` cannot be shared between threads safely --> tests/ui/arg_not_sync.rs:13:20 | 13 | assert_is_sync(send_not_sync()); | -------------- ^^^^^^^^^^^^^^^ `dyn Future + Send` cannot be shared between threads safely | | | required by a bound introduced by this call | = help: the trait `Sync` is not implemented for `dyn Future + Send`, which is required by `Pin + Send>>: Sync` = note: required for `Unique + Send>` to implement `Sync` note: required because it appears within the type `Box + Send>` --> $RUST/alloc/src/boxed.rs | | pub struct Box< | ^^^ note: required because it appears within the type `Pin + Send>>` --> $RUST/core/src/pin.rs | | pub struct Pin { | ^^^ note: required by a bound in `assert_is_sync` --> tests/ui/arg_not_sync.rs:3:27 | 3 | fn assert_is_sync(_: impl Sync) {} | ^^^^ required by this bound in `assert_is_sync` error[E0277]: `dyn Future` cannot be shared between threads safely --> tests/ui/arg_not_sync.rs:14:20 | 14 | assert_is_sync(not_send_not_sync()); | -------------- ^^^^^^^^^^^^^^^^^^^ `dyn Future` cannot be shared between threads safely | | | required by a bound introduced by this call | = help: the trait `Sync` is not implemented for `dyn Future`, which is required by `Pin>>: Sync` = note: required for `Unique>` to implement `Sync` note: required because it appears within the type `Box>` --> $RUST/alloc/src/boxed.rs | | pub struct Box< | ^^^ note: required because it appears within the type `Pin>>` --> $RUST/core/src/pin.rs | | pub struct Pin { | ^^^ note: required by a bound in `assert_is_sync` --> tests/ui/arg_not_sync.rs:3:27 | 3 | fn assert_is_sync(_: impl Sync) {} | ^^^^ required by this bound in `assert_is_sync` async-recursion-1.1.1/tests/ui/args_invalid.rs000064400000000000000000000003421046102023000175360ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(?Sync)] async fn not_sync() {} #[async_recursion(Sync Sync)] async fn not_punctuated() {} #[async_recursion(Sync?Send)] async fn what_even_is_this() {} fn main() {}async-recursion-1.1.1/tests/ui/args_invalid.stderr000064400000000000000000000007231046102023000204200ustar 00000000000000error: failed to parse macro arguments: expected `Send` --> tests/ui/args_invalid.rs:3:20 | 3 | #[async_recursion(?Sync)] | ^^^^ error: failed to parse macro arguments: expected `,` --> tests/ui/args_invalid.rs:6:24 | 6 | #[async_recursion(Sync Sync)] | ^^^^ error: failed to parse macro arguments: expected `,` --> tests/ui/args_invalid.rs:9:23 | 9 | #[async_recursion(Sync?Send)] | ^ async-recursion-1.1.1/tests/ui/args_repeated.rs000064400000000000000000000004051046102023000177010ustar 00000000000000use async_recursion::async_recursion; #[async_recursion(?Send, ?Send)] async fn repeated_args_1() {} #[async_recursion(?Send, Sync, ?Send)] async fn repeated_args_2() {} #[async_recursion(Sync, ?Send, Sync, ?Send)] async fn repeated_args_3() {} fn main() {}async-recursion-1.1.1/tests/ui/args_repeated.stderr000064400000000000000000000016171046102023000205660ustar 00000000000000error: received duplicate argument: `?Send` --> tests/ui/args_repeated.rs:3:1 | 3 | #[async_recursion(?Send, ?Send)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `async_recursion` (in Nightly builds, run with -Z macro-backtrace for more info) error: received too many arguments --> tests/ui/args_repeated.rs:6:1 | 6 | #[async_recursion(?Send, Sync, ?Send)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `async_recursion` (in Nightly builds, run with -Z macro-backtrace for more info) error: received too many arguments --> tests/ui/args_repeated.rs:9:1 | 9 | #[async_recursion(Sync, ?Send, Sync, ?Send)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `async_recursion` (in Nightly builds, run with -Z macro-backtrace for more info) async-recursion-1.1.1/tests/ui/must_use.rs000064400000000000000000000002151046102023000167370ustar 00000000000000#![deny(unused_must_use)] use async_recursion::async_recursion; #[async_recursion] async fn apples(_: u16) {} fn main() { apples(3); }async-recursion-1.1.1/tests/ui/must_use.stderr000064400000000000000000000010671046102023000176240ustar 00000000000000error: unused pinned boxed `Future` trait object that must be used --> tests/ui/must_use.rs:9:5 | 9 | apples(3); | ^^^^^^^^^ | = note: futures do nothing unless you `.await` or poll them note: the lint level is defined here --> tests/ui/must_use.rs:1:9 | 1 | #![deny(unused_must_use)] | ^^^^^^^^^^^^^^^ error: unused return value of `apples` that must be used --> tests/ui/must_use.rs:9:5 | 9 | apples(3); | ^^^^^^^^^ | help: use `let _ = ...` to ignore the resulting value | 9 | let _ = apples(3); | +++++++ async-recursion-1.1.1/tests/ui/not_async.rs000064400000000000000000000001311046102023000170650ustar 00000000000000use async_recursion::async_recursion; #[async_recursion] fn not_async() {} fn main() {}async-recursion-1.1.1/tests/ui/not_async.stderr000064400000000000000000000003771046102023000177600ustar 00000000000000error: expected an async function --> tests/ui/not_async.rs:3:1 | 3 | #[async_recursion] | ^^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `async_recursion` (in Nightly builds, run with -Z macro-backtrace for more info)