Update to 2018 edition
diff --git a/Cargo.toml b/Cargo.toml
index 013dca0..bd7d78d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,7 @@
homepage = "https://github.com/alexcrichton/proc-macro2"
documentation = "https://docs.rs/proc-macro2"
build = "build.rs"
+edition = "2018"
description = """
A stable implementation of the upcoming new `proc_macro` API. Comes with an
option, off by default, to also reimplement itself in terms of the upstream
diff --git a/src/fallback.rs b/src/fallback.rs
index 0e073ba..f49318c 100644
--- a/src/fallback.rs
+++ b/src/fallback.rs
@@ -10,11 +10,10 @@
use std::str::FromStr;
use std::vec;
-use strnom::{block_comment, skip_whitespace, whitespace, word_break, Cursor, PResult};
+use crate::strnom::{block_comment, skip_whitespace, whitespace, word_break, Cursor, PResult};
+use crate::{Delimiter, Punct, Spacing, TokenTree};
use unicode_xid::UnicodeXID;
-use {Delimiter, Punct, Spacing, TokenTree};
-
#[derive(Clone)]
pub struct TokenStream {
inner: Vec<TokenTree>,
@@ -118,8 +117,8 @@
}
#[cfg(use_proc_macro)]
-impl From<::proc_macro::TokenStream> for TokenStream {
- fn from(inner: ::proc_macro::TokenStream) -> TokenStream {
+impl From<proc_macro::TokenStream> for TokenStream {
+ fn from(inner: proc_macro::TokenStream) -> TokenStream {
inner
.to_string()
.parse()
@@ -128,8 +127,8 @@
}
#[cfg(use_proc_macro)]
-impl From<TokenStream> for ::proc_macro::TokenStream {
- fn from(inner: TokenStream) -> ::proc_macro::TokenStream {
+impl From<TokenStream> for proc_macro::TokenStream {
+ fn from(inner: TokenStream) -> proc_macro::TokenStream {
inner
.to_string()
.parse()
@@ -820,21 +819,21 @@
fn spanned<'a, T>(
input: Cursor<'a>,
f: fn(Cursor<'a>) -> PResult<'a, T>,
-) -> PResult<'a, (T, ::Span)> {
+) -> PResult<'a, (T, crate::Span)> {
let (a, b) = f(skip_whitespace(input))?;
- Ok((a, ((b, ::Span::_new_stable(Span::call_site())))))
+ Ok((a, ((b, crate::Span::_new_stable(Span::call_site())))))
}
#[cfg(span_locations)]
fn spanned<'a, T>(
input: Cursor<'a>,
f: fn(Cursor<'a>) -> PResult<'a, T>,
-) -> PResult<'a, (T, ::Span)> {
+) -> PResult<'a, (T, crate::Span)> {
let input = skip_whitespace(input);
let lo = input.off;
let (a, b) = f(input)?;
let hi = a.off;
- let span = ::Span::_new_stable(Span { lo, hi });
+ let span = crate::Span::_new_stable(Span { lo, hi });
Ok((a, (b, span)))
}
@@ -845,9 +844,9 @@
}
named!(token_kind -> TokenTree, alt!(
- map!(group, |g| TokenTree::Group(::Group::_new_stable(g)))
+ map!(group, |g| TokenTree::Group(crate::Group::_new_stable(g)))
|
- map!(literal, |l| TokenTree::Literal(::Literal::_new_stable(l))) // must be before symbol
+ map!(literal, |l| TokenTree::Literal(crate::Literal::_new_stable(l))) // must be before symbol
|
map!(op, TokenTree::Punct)
|
@@ -905,9 +904,9 @@
Err(LexError)
} else {
let ident = if raw {
- ::Ident::_new_raw(&a[2..], ::Span::call_site())
+ crate::Ident::_new_raw(&a[2..], crate::Span::call_site())
} else {
- ::Ident::new(a, ::Span::call_site())
+ crate::Ident::new(a, crate::Span::call_site())
};
Ok((input.advance(end), ident.into()))
}
@@ -1379,15 +1378,15 @@
trees.push(Punct::new('!', Spacing::Alone).into());
}
let mut stream = vec![
- TokenTree::Ident(::Ident::new("doc", span)),
+ TokenTree::Ident(crate::Ident::new("doc", span)),
TokenTree::Punct(Punct::new('=', Spacing::Alone)),
- TokenTree::Literal(::Literal::string(comment)),
+ TokenTree::Literal(crate::Literal::string(comment)),
];
for tt in stream.iter_mut() {
tt.set_span(span);
}
let group = Group::new(Delimiter::Bracket, stream.into_iter().collect());
- trees.push(::Group::_new_stable(group).into());
+ trees.push(crate::Group::_new_stable(group).into());
for tt in trees.iter_mut() {
tt.set_span(span);
}
diff --git a/src/lib.rs b/src/lib.rs
index 72c82a3..ac75408 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -91,7 +91,6 @@
#[cfg(use_proc_macro)]
extern crate proc_macro;
-extern crate unicode_xid;
use std::cmp::Ordering;
use std::fmt;
@@ -1150,9 +1149,8 @@
use std::marker;
use std::rc::Rc;
- use imp;
- pub use TokenStream;
- use TokenTree;
+ pub use crate::TokenStream;
+ use crate::{imp, TokenTree};
/// An iterator over `TokenStream`'s `TokenTree`s.
///
diff --git a/src/strnom.rs b/src/strnom.rs
index 3d8ba85..eb7d0b8 100644
--- a/src/strnom.rs
+++ b/src/strnom.rs
@@ -1,11 +1,9 @@
//! Adapted from [`nom`](https://github.com/Geal/nom).
+use crate::fallback::LexError;
use std::str::{Bytes, CharIndices, Chars};
-
use unicode_xid::UnicodeXID;
-use fallback::LexError;
-
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Cursor<'a> {
pub rest: &'a str,
diff --git a/src/wrapper.rs b/src/wrapper.rs
index 69e8e86..04cf306 100644
--- a/src/wrapper.rs
+++ b/src/wrapper.rs
@@ -5,10 +5,7 @@
use std::path::PathBuf;
use std::str::FromStr;
-use fallback;
-use proc_macro;
-
-use {Delimiter, Punct, Spacing, TokenTree};
+use crate::{fallback, Delimiter, Punct, Spacing, TokenTree};
#[derive(Clone)]
pub enum TokenStream {
@@ -318,18 +315,18 @@
TokenTreeIter::Fallback(iter) => return iter.next(),
};
Some(match token {
- proc_macro::TokenTree::Group(tt) => ::Group::_new(Group::Compiler(tt)).into(),
+ proc_macro::TokenTree::Group(tt) => crate::Group::_new(Group::Compiler(tt)).into(),
proc_macro::TokenTree::Punct(tt) => {
let spacing = match tt.spacing() {
proc_macro::Spacing::Joint => Spacing::Joint,
proc_macro::Spacing::Alone => Spacing::Alone,
};
let mut o = Punct::new(tt.as_char(), spacing);
- o.set_span(::Span::_new(Span::Compiler(tt.span())));
+ o.set_span(crate::Span::_new(Span::Compiler(tt.span())));
o.into()
}
- proc_macro::TokenTree::Ident(s) => ::Ident::_new(Ident::Compiler(s)).into(),
- proc_macro::TokenTree::Literal(l) => ::Literal::_new(Literal::Compiler(l)).into(),
+ proc_macro::TokenTree::Ident(s) => crate::Ident::_new(Ident::Compiler(s)).into(),
+ proc_macro::TokenTree::Literal(l) => crate::Literal::_new(Literal::Compiler(l)).into(),
})
}
@@ -510,9 +507,9 @@
}
}
-impl From<proc_macro::Span> for ::Span {
- fn from(proc_span: proc_macro::Span) -> ::Span {
- ::Span::_new(Span::Compiler(proc_span))
+impl From<proc_macro::Span> for crate::Span {
+ fn from(proc_span: proc_macro::Span) -> crate::Span {
+ crate::Span::_new(Span::Compiler(proc_span))
}
}
diff --git a/tests/marker.rs b/tests/marker.rs
index 7bb5027..7af2539 100644
--- a/tests/marker.rs
+++ b/tests/marker.rs
@@ -1,5 +1,3 @@
-extern crate proc_macro2;
-
use proc_macro2::*;
macro_rules! assert_impl {
diff --git a/tests/test.rs b/tests/test.rs
index 370392b..8ab975c 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1,5 +1,3 @@
-extern crate proc_macro2;
-
use std::str::{self, FromStr};
use proc_macro2::{Ident, Literal, Spacing, Span, TokenStream, TokenTree};