Skip to content

Commit

Permalink
Update syn, quote, and proc-macro2 to post-1.0 versions
Browse files Browse the repository at this point in the history
This crate will currently stop compiling once PR rust-lang/rust#76130
(a bugfix to the Rust compiler) is merged, due to the fact than old
version of `syn` is in use. Newer versions of `syn` can parse the
`TokenStream` passed by newer versions of rustc, allowing this crate to
compile under both older and newer versions of rustc.
  • Loading branch information
Aaron1011 committed Sep 25, 2020
1 parent 5acb425 commit d67b022
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 75 deletions.
79 changes: 22 additions & 57 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions jsonrpc-types/internals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ license = "Apache-2.0"
edition = "2018"

[dependencies]
syn = "0.14"
quote = "0.6"
proc-macro2 = "0.4"
syn = "1.0.41"
quote = "1"
proc-macro2 = "1"

[lib]
proc-macro = true
39 changes: 24 additions & 15 deletions jsonrpc-types/internals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ extern crate syn;
#[macro_use]
extern crate quote;

use syn::parse::{Parse, ParseStream, Result};

struct TypeWithAttrs {
typ: syn::Type,
attrs: Vec<syn::Attribute>,
}

impl syn::synom::Synom for TypeWithAttrs {
named!(parse -> Self, do_parse!(
attrs: many0!(syn::Attribute::parse_outer) >>
typ: syn!(syn::Type) >>
(TypeWithAttrs{ typ, attrs })
));
impl Parse for TypeWithAttrs {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = input.call(syn::Attribute::parse_outer)?;
let typ: syn::Type = input.parse()?;
Ok(TypeWithAttrs { typ, attrs })
}
}

struct ParamsType {
Expand All @@ -41,15 +43,22 @@ struct ParamsType {
resp: syn::Ident,
}

impl syn::synom::Synom for ParamsType {
named!(parse -> Self, do_parse!(
name: syn!(syn::Ident) >>
punct!(:) >>
types: brackets!(call!(syn::punctuated::Punctuated::parse_separated)) >>
punct!(,) >>
resp: syn!(syn::Ident) >>
(ParamsType { name, types, resp })
));
impl Parse for ParamsType {
fn parse(input: ParseStream) -> Result<Self> {
let name: syn::Ident = input.parse()?;
let _colon: Token![:] = input.parse()?;

let inner;
let bracket = bracketed!(inner in input);
let types = syn::punctuated::Punctuated::parse_terminated(&inner)?;
let _comma: Token![,] = input.parse()?;
let resp: syn::Ident = input.parse()?;
Ok(ParamsType {
name,
types: (bracket, types),
resp
})
}
}

// Get JSON-RPC name from params name.
Expand Down

0 comments on commit d67b022

Please sign in to comment.