Skip to content

Commit

Permalink
Update to the next version of proc-macro2
Browse files Browse the repository at this point in the history
Depends on dtolnay/quote#73
Depends on dtolnay/proc-macro2#90
Depends on a new nightly
  • Loading branch information
alexcrichton committed May 16, 2018
1 parent 1df4ef0 commit 57818b9
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 357 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ extra-traits = []
proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"]

[dependencies]
proc-macro2 = { version = "0.3", default-features = false }
quote = { version = "0.5", optional = true, default-features = false }
proc-macro2 = { version = "0.4", default-features = false }
quote = { version = "0.6", optional = true, default-features = false }
unicode-xid = "0.1"

[dev-dependencies]
Expand All @@ -42,3 +42,7 @@ all-features = true

[package.metadata.playground]
all-features = true

[patch.crates-io]
proc-macro2 = { git = 'https://github.com/alexcrichton/proc-macro2', branch = 'next' }
quote = { git = 'https://github.com/alexcrichton/quote', branch = 'next' }
8 changes: 6 additions & 2 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ publish = false # this is an internal crate which should never be published

[dependencies]
syn = { path = "..", features = ["full", "extra-traits"] }
quote = "0.5"
quote = "0.6"
failure = "0.1"
inflections = "1.1"
proc-macro2 = "0.3"
proc-macro2 = "0.4"

[patch.crates-io]
proc-macro2 = { git = 'https://github.com/alexcrichton/proc-macro2', branch = 'next' }
quote = { git = 'https://github.com/alexcrichton/quote', branch = 'next' }
2 changes: 1 addition & 1 deletion codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ macro_rules! full {
use *;
#[cfg(any(feature = \"full\", feature = \"derive\"))]
use token::{{Brace, Bracket, Paren, Group}};
use proc_macro2::Span;
use proc_macro2::{Span, Ident};
#[cfg(any(feature = \"full\", feature = \"derive\"))]
use gen::helper::fold::*;
Expand Down
14 changes: 7 additions & 7 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use punctuated::Punctuated;

use std::iter;

use proc_macro2::{Delimiter, Spacing, TokenStream, TokenTree};
use proc_macro2::{Delimiter, Spacing, TokenStream, TokenTree, Ident};

#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -149,7 +149,7 @@ impl Attribute {

fn extract_name_value(ident: Ident, a: &TokenTree, b: &TokenTree) -> Option<Meta> {
let a = match *a {
TokenTree::Op(ref o) => o,
TokenTree::Punct(ref o) => o,
_ => return None,
};
if a.spacing() != Spacing::Alone {
Expand All @@ -167,7 +167,7 @@ impl Attribute {
lit: Lit::new(l.clone()),
}))
}
TokenTree::Term(ref term) => match term.as_str() {
TokenTree::Ident(ref term) => match term.as_str() {
v @ "true" | v @ "false" => Some(Meta::NameValue(MetaNameValue {
ident: ident,
eq_token: Token![=]([a.span()]),
Expand Down Expand Up @@ -196,7 +196,7 @@ fn nested_meta_item_from_tokens(tts: &[TokenTree]) -> Option<(NestedMeta, &[Toke
}
}

TokenTree::Term(sym) => {
TokenTree::Ident(sym) => {
let ident = Ident::new(sym.as_str(), sym.span());
if tts.len() >= 3 {
if let Some(meta) = Attribute::extract_name_value(ident, &tts[1], &tts[2]) {
Expand Down Expand Up @@ -227,7 +227,7 @@ fn list_of_nested_meta_items_from_tokens(
let prev_comma = if first {
first = false;
None
} else if let TokenTree::Op(ref op) = tts[0] {
} else if let TokenTree::Punct(ref op) = tts[0] {
if op.spacing() != Spacing::Alone {
return None;
}
Expand Down Expand Up @@ -397,11 +397,11 @@ pub mod parsing {
use super::*;
use buffer::Cursor;
use parse_error;
use proc_macro2::{Literal, Op, Spacing, Span, TokenTree};
use proc_macro2::{Literal, Punct, Spacing, Span, TokenTree};
use synom::PResult;

fn eq(span: Span) -> TokenTree {
let mut op = Op::new('=', Spacing::Alone);
let mut op = Punct::new('=', Spacing::Alone);
op.set_span(span);
op.into()
}
Expand Down
40 changes: 20 additions & 20 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@

#[cfg(feature = "proc-macro")]
use proc_macro as pm;
use proc_macro2::{Delimiter, Literal, Span, Term, TokenStream};
use proc_macro2::{Group, Op, TokenTree};
use proc_macro2::{Delimiter, Literal, Span, Ident, TokenStream};
use proc_macro2::{Group, Punct, TokenTree};

use std::marker::PhantomData;
use std::ptr;
Expand All @@ -143,8 +143,8 @@ use std::fmt::{self, Debug};
enum Entry {
// Mimicking types from proc-macro.
Group(Span, Delimiter, TokenBuffer),
Term(Term),
Op(Op),
Ident(Ident),
Punct(Punct),
Literal(Literal),
// End entries contain a raw pointer to the entry from the containing
// token tree, or null if this is the outermost level.
Expand Down Expand Up @@ -177,11 +177,11 @@ impl TokenBuffer {
let mut seqs = Vec::new();
for tt in stream {
match tt {
TokenTree::Term(sym) => {
entries.push(Entry::Term(sym));
TokenTree::Ident(sym) => {
entries.push(Entry::Ident(sym));
}
TokenTree::Op(op) => {
entries.push(Entry::Op(op));
TokenTree::Punct(op) => {
entries.push(Entry::Punct(op));
}
TokenTree::Literal(l) => {
entries.push(Entry::Literal(l));
Expand Down Expand Up @@ -275,8 +275,8 @@ impl<'a> Cursor<'a> {
pub fn empty() -> Self {
// It's safe in this situation for us to put an `Entry` object in global
// storage, despite it not actually being safe to send across threads
// (`Term` is a reference into a thread-local table). This is because
// this entry never includes a `Term` object.
// (`Ident` is a reference into a thread-local table). This is because
// this entry never includes a `Ident` object.
//
// This wrapper struct allows us to break the rules and put a `Sync`
// object in global storage.
Expand Down Expand Up @@ -368,22 +368,22 @@ impl<'a> Cursor<'a> {
None
}

/// If the cursor is pointing at a `Term`, returns it along with a cursor
/// If the cursor is pointing at a `Ident`, returns it along with a cursor
/// pointing at the next `TokenTree`.
pub fn term(mut self) -> Option<(Term, Cursor<'a>)> {
pub fn term(mut self) -> Option<(Ident, Cursor<'a>)> {
self.ignore_none();
match *self.entry() {
Entry::Term(term) => Some((term, unsafe { self.bump() })),
Entry::Ident(term) => Some((term, unsafe { self.bump() })),
_ => None,
}
}

/// If the cursor is pointing at an `Op`, returns it along with a cursor
/// If the cursor is pointing at an `Punct`, returns it along with a cursor
/// pointing at the next `TokenTree`.
pub fn op(mut self) -> Option<(Op, Cursor<'a>)> {
pub fn op(mut self) -> Option<(Punct, Cursor<'a>)> {
self.ignore_none();
match *self.entry() {
Entry::Op(op) => Some((op, unsafe { self.bump() })),
Entry::Punct(op) => Some((op, unsafe { self.bump() })),
_ => None,
}
}
Expand Down Expand Up @@ -426,8 +426,8 @@ impl<'a> Cursor<'a> {
TokenTree::from(g)
}
Entry::Literal(ref lit) => lit.clone().into(),
Entry::Term(term) => term.into(),
Entry::Op(op) => op.into(),
Entry::Ident(term) => term.into(),
Entry::Punct(op) => op.into(),
Entry::End(..) => {
return None;
}
Expand All @@ -442,8 +442,8 @@ impl<'a> Cursor<'a> {
match *self.entry() {
Entry::Group(span, ..) => span,
Entry::Literal(ref l) => l.span(),
Entry::Term(t) => t.span(),
Entry::Op(o) => o.span(),
Entry::Ident(t) => t.span(),
Entry::Punct(o) => o.span(),
Entry::End(..) => Span::call_site(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use proc_macro2::Ident;

use super::*;
use punctuated::Punctuated;

Expand Down
1 change: 1 addition & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// except according to those terms.

use super::*;
use proc_macro2::Ident;
use punctuated::Punctuated;

ast_struct! {
Expand Down
2 changes: 1 addition & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// except according to those terms.

use super::*;
use proc_macro2::{Span, TokenStream};
use proc_macro2::{Span, TokenStream, Ident};
use punctuated::Punctuated;
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
Expand Down
1 change: 1 addition & 0 deletions src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// except according to those terms.

use super::*;
use proc_macro2::Ident;
use punctuated::{Iter, IterMut, Punctuated};

ast_struct! {
Expand Down
Loading

0 comments on commit 57818b9

Please sign in to comment.