Skip to content

Update syn, quote and proc-macro2 #940

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

Merged
merged 5 commits into from
Apr 11, 2018
Merged
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
8 changes: 4 additions & 4 deletions futures-macro-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ few other assorted macros.
proc-macro = true

[dependencies]
quote = "0.4"
proc-macro2 = "0.2"
quote = "0.5"
proc-macro2 = "0.3"

[dependencies.syn]
version = "0.12.13"
features = ["full", "fold", "parsing", "printing", "extra-traits"]
version = "0.13"
features = ["full", "fold", "parsing", "printing", "extra-traits", "proc-macro"]
default-features = false

[features]
Expand Down
4 changes: 2 additions & 2 deletions futures-macro-async/src/elision.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use proc_macro2::{Term, Span};
use proc_macro2::Span;
use syn::*;
use syn::punctuated::Punctuated;
use syn::token::Comma;
Expand Down Expand Up @@ -34,7 +34,7 @@ impl<'a> UnelideLifetimes<'a> {
// Constitute a new lifetime
fn new_lifetime(&mut self) -> Lifetime {
let lifetime_name = format!("{}{}", self.lifetime_name, self.count);
let lifetime = Lifetime::new(Term::intern(&lifetime_name), Span::call_site());
let lifetime = Lifetime::new(&lifetime_name, Span::call_site());

let idx = self.lifetime_index + self.count as usize;
self.generics.insert(idx, GenericParam::Lifetime(LifetimeDef::new(lifetime.clone())));
Expand Down
28 changes: 11 additions & 17 deletions futures-macro-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if_nightly! {
extern crate syn;

use proc_macro2::Span;
use proc_macro::{TokenStream, TokenTree, Delimiter, TokenNode};
use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
use quote::{Tokens, ToTokens};
use syn::*;
use syn::punctuated::Punctuated;
Expand Down Expand Up @@ -444,10 +444,7 @@ if_nightly! {

#[proc_macro]
pub fn async_block(input: TokenStream) -> TokenStream {
let input = TokenStream::from(TokenTree {
kind: TokenNode::Group(Delimiter::Brace, input),
span: proc_macro::Span::def_site(),
});
let input = TokenStream::from(TokenTree::Group(Group::new(Delimiter::Brace, input)));
let expr = syn::parse(input)
.expect("failed to parse tokens as an expression");
let expr = ExpandAsyncFor.fold_expr(expr);
Expand Down Expand Up @@ -475,10 +472,7 @@ if_nightly! {

#[proc_macro]
pub fn async_stream_block(input: TokenStream) -> TokenStream {
let input = TokenStream::from(TokenTree {
kind: TokenNode::Group(Delimiter::Brace, input),
span: proc_macro::Span::def_site(),
});
let input = TokenStream::from(TokenTree::Group(Group::new(Delimiter::Brace, input)));
let expr = syn::parse(input)
.expect("failed to parse tokens as an expression");
let expr = ExpandAsyncFor.fold_expr(expr);
Expand Down Expand Up @@ -573,19 +567,19 @@ if_nightly! {
let mut spans = Tokens::new();
tokens.to_tokens(&mut spans);
let good_tokens = proc_macro2::TokenStream::from(spans).into_iter().collect::<Vec<_>>();
let first_span = good_tokens.first().map(|t| t.span).unwrap_or(Span::def_site());
let last_span = good_tokens.last().map(|t| t.span).unwrap_or(first_span);
let first_span = good_tokens.first().map(|t| t.span()).unwrap_or(Span::call_site());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be call_site or better to make first_last function to return proc_macro::Span?

let last_span = good_tokens.last().map(|t| t.span()).unwrap_or(first_span);
(first_span, last_span)
}

fn respan(input: proc_macro2::TokenStream,
&(first_span, last_span): &(Span, Span)) -> proc_macro2::TokenStream {
let mut new_tokens = input.into_iter().collect::<Vec<_>>();
if let Some(token) = new_tokens.first_mut() {
token.span = first_span;
token.set_span(first_span);
}
for token in new_tokens.iter_mut().skip(1) {
token.span = last_span;
token.set_span(last_span);
}
new_tokens.into_iter().collect()
}
Expand All @@ -595,8 +589,8 @@ if_nightly! {
{
let mut new_tokens = Tokens::new();
for token in input.into_iter() {
match token.kind {
proc_macro2::TokenNode::Op('!', _) => tokens.to_tokens(&mut new_tokens),
match token {
proc_macro2::TokenTree::Op(op) if op.op() == '!' => tokens.to_tokens(&mut new_tokens),
_ => token.to_tokens(&mut new_tokens),
}
}
Expand All @@ -609,8 +603,8 @@ if_nightly! {
let mut replacements = replacements.iter().cycle();
let mut new_tokens = Tokens::new();
for token in input.into_iter() {
match token.kind {
proc_macro2::TokenNode::Op('!', _) => {
match token {
proc_macro2::TokenTree::Op(op) if op.op() == '!' => {
replacements.next().unwrap().to_tokens(&mut new_tokens);
}
_ => token.to_tokens(&mut new_tokens),
Expand Down
16 changes: 5 additions & 11 deletions futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,18 @@ travis-ci = { repository = "rust-lang-nursery/futures-rs" }
appveyor = { repository = "rust-lang-nursery/futures-rs" }

[dependencies]
# futures-async-runtime = { path = "../futures-async-runtime", version = "0.2.0", default-features = false }
futures-async-runtime = { path = "../futures-async-runtime", version = "0.2.0", default-features = false }
futures-core = { path = "../futures-core", version = "0.2.0", default-features = false }
futures-channel = { path = "../futures-channel", version = "0.2.0", default-features = false }
futures-executor = { path = "../futures-executor", version = "0.2.0", default-features = false }
futures-io = { path = "../futures-io", version = "0.2.0", default-features = false }
futures-sink = { path = "../futures-sink", version = "0.2.0", default-features = false }
futures-stable = { path = "../futures-stable", version = "0.2.0", default-features = false }
futures-util = { path = "../futures-util", version = "0.2.0", default-features = false }
# futures-macro-async = { path = "../futures-macro-async", version = "0.2.0", optional = true }
# futures-macro-await = { path = "../futures-macro-await", version = "0.2.0", optional = true }
futures-macro-async = { path = "../futures-macro-async", version = "0.2.0", optional = true }
futures-macro-await = { path = "../futures-macro-await", version = "0.2.0", optional = true }

[features]
nightly = ["futures-core/nightly", "futures-stable/nightly"]
std = ["futures-core/std", "futures-executor/std", "futures-io/std", "futures-sink/std", "futures-stable/std", "futures-util/std"]
nightly = ["futures-core/nightly", "futures-stable/nightly", "futures-async-runtime/nightly", "futures-macro-async", "futures-macro-await", "futures-macro-async/nightly"]
std = ["futures-core/std", "futures-executor/std", "futures-io/std", "futures-sink/std", "futures-stable/std", "futures-util/std", "futures-async-runtime/std"]
default = ["std"]

# TODO(cramertj) reenable on nightly
# , "futures-async-runtime/nightly", "futures-macro-async", "futures-macro-await", "futures-macro-async/nightly"

# TODO(cramertj) reenable on std
# "futures-async-runtime/std"
55 changes: 26 additions & 29 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))]
#![cfg_attr(feature = "nightly", feature(use_extern_macros))]

// extern crate futures_async_runtime;
extern crate futures_async_runtime;
extern crate futures_core;
extern crate futures_channel;
extern crate futures_executor;
Expand All @@ -34,9 +34,8 @@ extern crate futures_sink;
extern crate futures_stable;
extern crate futures_util;

// TODO(cramertj) reenable
// #[cfg(feature = "nightly")] extern crate futures_macro_async;
// #[cfg(feature = "nightly")] extern crate futures_macro_await;
#[cfg(feature = "nightly")] extern crate futures_macro_async;
#[cfg(feature = "nightly")] extern crate futures_macro_await;

pub use futures_core::future::{Future, IntoFuture};
pub use futures_util::future::FutureExt;
Expand Down Expand Up @@ -289,23 +288,22 @@ pub mod prelude {
AsyncWriteExt,
};

// TODO(cramertj) reenable
// #[cfg(feature = "nightly")]
// pub use futures_macro_async::{
// async,
// async_move,
// async_stream,
// async_stream_move,
// async_block,
// async_stream_block
// };
//
// #[cfg(feature = "nightly")]
// pub use futures_macro_await::{
// await,
// stream_yield,
// await_item
// };
#[cfg(feature = "nightly")]
pub use futures_macro_async::{
async,
async_move,
async_stream,
async_stream_move,
async_block,
async_stream_block
};

#[cfg(feature = "nightly")]
pub use futures_macro_await::{
await,
stream_yield,
await_item
};
}

pub mod sink {
Expand Down Expand Up @@ -402,11 +400,10 @@ pub mod stable {
pub use futures_stable::{StableExecutor, block_on_stable};
}

// TODO(cramertj) reenable
// #[cfg(feature = "nightly")]
// #[doc(hidden)]
// pub mod __rt {
// #[cfg(feature = "std")]
// pub extern crate std;
// pub use futures_async_runtime::*;
// }
#[cfg(feature = "nightly")]
#[doc(hidden)]
pub mod __rt {
#[cfg(feature = "std")]
pub extern crate std;
pub use futures_async_runtime::*;
}
2 changes: 1 addition & 1 deletion futures/tests/async_await/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,6 @@ fn poll_stream_after_error() {

#[test]
fn run_boxed_future_in_cpu_pool() {
let mut pool = executor::ThreadPool::new();
let mut pool = executor::ThreadPool::new().unwrap();
pool.spawn(_foo9()).unwrap();
}