Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to more recent Rust #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/error_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let counter = gen!({
for num in 0..10 {
// Perform some fallible operation, and yield the result (or the error)
let string = yield_!(process(num));
let _string = yield_!(process(num));
}
});

Expand Down
44 changes: 13 additions & 31 deletions genawaiter-proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@
#![warn(clippy::cargo, clippy::pedantic)]
#![cfg_attr(feature = "strict", deny(warnings))]

extern crate proc_macro;

use crate::visit::YieldReplace;
use proc_macro::TokenStream;
use proc_macro_error::{abort, abort_call_site, proc_macro_error};
use proc_macro_hack::proc_macro_hack;
use quote::quote;
use std::string::ToString;
use syn::{
self,
parse_macro_input,
parse_str,
spanned::Spanned,
visit_mut::VisitMut,
ExprBlock,
FnArg,
Ident,
ItemFn,
Type,
self, parse_macro_input, parse_str, spanned::Spanned, visit_mut::VisitMut,
ExprBlock, FnArg, Ident, ItemFn, Type,
};

mod visit;
Expand All @@ -42,7 +31,7 @@ pub fn stack_producer_fn(args: TokenStream, input: TokenStream) -> TokenStream {
tokens.into()
}

#[proc_macro_hack]
#[proc_macro]
#[proc_macro_error]
pub fn stack_producer(input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as ExprBlock);
Expand Down Expand Up @@ -76,7 +65,7 @@ pub fn sync_producer_fn(args: TokenStream, input: TokenStream) -> TokenStream {
tokens.into()
}

#[proc_macro_hack]
#[proc_macro]
#[proc_macro_error]
pub fn sync_producer(input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as ExprBlock);
Expand Down Expand Up @@ -109,7 +98,7 @@ pub fn rc_producer_fn(args: TokenStream, input: TokenStream) -> TokenStream {
tokens.into()
}

#[proc_macro_hack]
#[proc_macro]
#[proc_macro_error]
pub fn rc_producer(input: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(input as ExprBlock);
Expand Down Expand Up @@ -148,21 +137,14 @@ mod rc {
/// Mutates the input `Punctuated<FnArg, Comma>` to a lifetimeless `co:
/// Co<{type}>`.
fn add_coroutine_arg(func: &mut ItemFn, co_ty: &str) {
let co_arg_found = func.sig.inputs.iter().any(|input| {
match input {
FnArg::Receiver(_) => false,
FnArg::Typed(arg) => {
match &*arg.ty {
Type::Path(ty) => {
ty.path.segments.iter().any(|seg| {
seg.ident
== parse_str::<Ident>("Co").expect("Ident parse failed")
})
}
_ => false,
}
}
}
let co_arg_found = func.sig.inputs.iter().any(|input| match input {
FnArg::Receiver(_) => false,
FnArg::Typed(arg) => match &*arg.ty {
Type::Path(ty) => ty.path.segments.iter().any(|seg| {
seg.ident == parse_str::<Ident>("Co").expect("Ident parse failed")
}),
_ => false,
},
});
if !co_arg_found {
let co_arg: FnArg = match parse_str::<FnArg>(co_ty) {
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ extern crate self as genawaiter;

pub use crate::ops::{Coroutine, Generator, GeneratorState};

#[cfg(feature = "proc_macro")]
use proc_macro_hack::proc_macro_hack;

/// Creates a producer for use with [`sync::Gen`].
///
/// A producer can later be turned into a generator using
Expand All @@ -290,7 +287,6 @@ use proc_macro_hack::proc_macro_hack;
/// # my_generator.resume();
/// ```
#[cfg(feature = "proc_macro")]
#[proc_macro_hack]
pub use genawaiter_proc_macro::sync_producer;

/// Creates a producer for use with [`rc::Gen`].
Expand All @@ -314,12 +310,10 @@ pub use genawaiter_proc_macro::sync_producer;
/// # my_generator.resume();
/// ```
#[cfg(feature = "proc_macro")]
#[proc_macro_hack]
pub use genawaiter_proc_macro::rc_producer;

#[doc(hidden)] // This is not quite usable currently, so hide it for now.
#[cfg(feature = "proc_macro")]
#[proc_macro_hack]
pub use genawaiter_proc_macro::stack_producer;

mod core;
Expand Down
2 changes: 1 addition & 1 deletion src/stack/nightly_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{ops::GeneratorState, stack::let_gen_using};

#[test]
fn async_closure() {
let_gen_using!(gen, async move |co| {
let_gen_using!(gen, async move |mut co| {
co.yield_(10).await;
"done"
});
Expand Down