Restore support for rust 1.31

This commit is contained in:
David Tolnay 2019-07-27 17:47:22 -07:00
parent b1cd699138
commit 0e1c815d5b
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
14 changed files with 77 additions and 75 deletions

View File

@ -1,5 +1,5 @@
use super::*;
use punctuated::Punctuated;
use crate::punctuated::Punctuated;
use std::iter;
@ -8,11 +8,11 @@ use proc_macro2::TokenStream;
use proc_macro2::{Delimiter, Spacing, TokenTree};
#[cfg(feature = "parsing")]
use parse::{ParseStream, Result};
use crate::parse::{ParseStream, Result};
#[cfg(feature = "extra-traits")]
use crate::tt::TokenStreamHelper;
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
#[cfg(feature = "extra-traits")]
use tt::TokenStreamHelper;
ast_struct! {
/// An attribute like `#[repr(transparent)]`.
@ -542,10 +542,10 @@ where
pub mod parsing {
use super::*;
use ext::IdentExt;
use parse::{Parse, ParseStream, Result};
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};
#[cfg(feature = "full")]
use private;
use crate::private;
pub fn single_parse_inner(input: ParseStream) -> Result<Attribute> {
let content;

View File

@ -11,7 +11,7 @@
not(all(target_arch = "wasm32", target_os = "unknown")),
feature = "proc-macro"
))]
use proc_macro as pm;
use crate::proc_macro as pm;
use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::marker::PhantomData;

View File

@ -1,5 +1,5 @@
use super::*;
use punctuated::Punctuated;
use crate::punctuated::Punctuated;
ast_struct! {
/// An enum variant.
@ -179,8 +179,8 @@ ast_enum_of_structs! {
pub mod parsing {
use super::*;
use ext::IdentExt;
use parse::{Parse, ParseStream, Result};
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};
impl Parse for Variant {
fn parse(input: ParseStream) -> Result<Self> {
@ -319,7 +319,7 @@ mod printing {
use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
use print::TokensOrDefault;
use crate::print::TokensOrDefault;
impl ToTokens for Variant {
fn to_tokens(&self, tokens: &mut TokenStream) {

View File

@ -1,5 +1,5 @@
use super::*;
use punctuated::Punctuated;
use crate::punctuated::Punctuated;
ast_struct! {
/// Data structure sent to a `proc_macro_derive` macro.
@ -74,7 +74,7 @@ ast_enum_of_structs! {
pub mod parsing {
use super::*;
use parse::{Parse, ParseStream, Result};
use crate::parse::{Parse, ParseStream, Result};
impl Parse for DeriveInput {
fn parse(input: ParseStream) -> Result<Self> {
@ -210,8 +210,8 @@ mod printing {
use proc_macro2::TokenStream;
use quote::ToTokens;
use attr::FilterAttrs;
use print::TokensOrDefault;
use crate::attr::FilterAttrs;
use crate::print::TokensOrDefault;
impl ToTokens for DeriveInput {
fn to_tokens(&self, tokens: &mut TokenStream) {

View File

@ -1,12 +1,12 @@
use super::*;
use crate::punctuated::Punctuated;
#[cfg(feature = "extra-traits")]
use crate::tt::TokenStreamHelper;
use proc_macro2::{Span, TokenStream};
use punctuated::Punctuated;
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
#[cfg(all(feature = "parsing", feature = "full"))]
use std::mem;
#[cfg(feature = "extra-traits")]
use tt::TokenStreamHelper;
ast_enum_of_structs! {
/// A Rust expression.
@ -981,9 +981,9 @@ pub mod parsing {
use super::*;
#[cfg(feature = "full")]
use ext::IdentExt;
use parse::{Parse, ParseStream, Result};
use path;
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
// When we're parsing expressions which occur before blocks, like in an if
// statement's condition, we cannot parse a struct literal.
@ -3038,9 +3038,9 @@ mod printing {
use quote::{ToTokens, TokenStreamExt};
#[cfg(feature = "full")]
use attr::FilterAttrs;
use crate::attr::FilterAttrs;
#[cfg(feature = "full")]
use print::TokensOrDefault;
use crate::print::TokensOrDefault;
// If the given expression is a bare `ExprStruct`, wraps it in parenthesis
// before appending it to `TokenStream`.

View File

@ -78,7 +78,7 @@ ast_struct! {
pub mod parsing {
use super::*;
use parse::{Parse, ParseStream, Result};
use crate::parse::{Parse, ParseStream, Result};
impl Parse for File {
fn parse(input: ParseStream) -> Result<Self> {
@ -100,7 +100,7 @@ pub mod parsing {
#[cfg(feature = "printing")]
mod printing {
use super::*;
use attr::FilterAttrs;
use crate::attr::FilterAttrs;
use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};

View File

@ -1,5 +1,5 @@
use super::*;
use punctuated::{Iter, IterMut, Punctuated};
use crate::punctuated::{Iter, IterMut, Punctuated};
ast_struct! {
/// Lifetimes and type parameters attached to a declaration of a function,
@ -479,7 +479,7 @@ ast_enum_of_structs! {
pub mod parsing {
use super::*;
use parse::{Parse, ParseStream, Result};
use crate::parse::{Parse, ParseStream, Result};
impl Parse for Generics {
fn parse(input: ParseStream) -> Result<Self> {
@ -872,8 +872,8 @@ mod printing {
use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
use attr::FilterAttrs;
use print::TokensOrDefault;
use crate::attr::FilterAttrs;
use crate::print::TokensOrDefault;
impl ToTokens for Generics {
fn to_tokens(&self, tokens: &mut TokenStream) {

View File

@ -1,13 +1,13 @@
use super::*;
use derive::{Data, DeriveInput};
use crate::derive::{Data, DeriveInput};
use crate::punctuated::Punctuated;
use crate::token::{Brace, Paren};
use proc_macro2::TokenStream;
use punctuated::Punctuated;
use token::{Brace, Paren};
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
use crate::tt::TokenStreamHelper;
#[cfg(feature = "extra-traits")]
use tt::TokenStreamHelper;
use std::hash::{Hash, Hasher};
ast_enum_of_structs! {
/// Things that can appear directly inside of a module or scope.
@ -778,8 +778,8 @@ ast_enum_of_structs! {
pub mod parsing {
use super::*;
use ext::IdentExt;
use parse::{Parse, ParseStream, Result};
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};
use proc_macro2::{Punct, Spacing, TokenTree};
use std::iter::FromIterator;
@ -2209,8 +2209,8 @@ mod printing {
use proc_macro2::TokenStream;
use quote::{ToTokens, TokenStreamExt};
use attr::FilterAttrs;
use print::TokensOrDefault;
use crate::attr::FilterAttrs;
use crate::print::TokensOrDefault;
impl ToTokens for ItemExternCrate {
fn to_tokens(&self, tokens: &mut TokenStream) {

View File

@ -299,17 +299,19 @@ pub mod group;
pub mod token;
mod ident;
pub use ident::Ident;
pub use crate::ident::Ident;
#[cfg(any(feature = "full", feature = "derive"))]
mod attr;
#[cfg(any(feature = "full", feature = "derive"))]
pub use attr::{AttrStyle, Attribute, AttributeArgs, Meta, MetaList, MetaNameValue, NestedMeta};
pub use crate::attr::{
AttrStyle, Attribute, AttributeArgs, Meta, MetaList, MetaNameValue, NestedMeta,
};
#[cfg(any(feature = "full", feature = "derive"))]
mod data;
#[cfg(any(feature = "full", feature = "derive"))]
pub use data::{
pub use crate::data::{
Field, Fields, FieldsNamed, FieldsUnnamed, Variant, VisCrate, VisPublic, VisRestricted,
Visibility,
};
@ -317,7 +319,7 @@ pub use data::{
#[cfg(any(feature = "full", feature = "derive"))]
mod expr;
#[cfg(any(feature = "full", feature = "derive"))]
pub use expr::{
pub use crate::expr::{
Expr, ExprArray, ExprAssign, ExprAssignOp, ExprAsync, ExprBinary, ExprBlock, ExprBox,
ExprBreak, ExprCall, ExprCast, ExprClosure, ExprContinue, ExprField, ExprForLoop, ExprGroup,
ExprIf, ExprInPlace, ExprIndex, ExprLet, ExprLit, ExprLoop, ExprMacro, ExprMatch,
@ -327,7 +329,7 @@ pub use expr::{
};
#[cfg(feature = "full")]
pub use expr::{
pub use crate::expr::{
Arm, Block, FieldPat, FieldValue, GenericMethodArgument, Label, Local, MethodTurbofish, Pat,
PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatRef, PatSlice, PatStruct, PatTuple,
PatTupleStruct, PatVerbatim, PatWild, RangeLimits, Stmt,
@ -336,18 +338,18 @@ pub use expr::{
#[cfg(any(feature = "full", feature = "derive"))]
mod generics;
#[cfg(any(feature = "full", feature = "derive"))]
pub use generics::{
pub use crate::generics::{
BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef, PredicateEq,
PredicateLifetime, PredicateType, TraitBound, TraitBoundModifier, TypeParam, TypeParamBound,
WhereClause, WherePredicate,
};
#[cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))]
pub use generics::{ImplGenerics, Turbofish, TypeGenerics};
pub use crate::generics::{ImplGenerics, Turbofish, TypeGenerics};
#[cfg(feature = "full")]
mod item;
#[cfg(feature = "full")]
pub use item::{
pub use crate::item::{
ArgCaptured, ArgSelf, ArgSelfRef, FnArg, FnDecl, ForeignItem, ForeignItemFn, ForeignItemMacro,
ForeignItemStatic, ForeignItemType, ForeignItemVerbatim, ImplItem, ImplItemConst,
ImplItemExistential, ImplItemMacro, ImplItemMethod, ImplItemType, ImplItemVerbatim, Item,
@ -361,15 +363,15 @@ pub use item::{
#[cfg(feature = "full")]
mod file;
#[cfg(feature = "full")]
pub use file::File;
pub use crate::file::File;
mod lifetime;
pub use lifetime::Lifetime;
pub use crate::lifetime::Lifetime;
#[cfg(any(feature = "full", feature = "derive"))]
mod lit;
#[cfg(any(feature = "full", feature = "derive"))]
pub use lit::{
pub use crate::lit::{
FloatSuffix, IntSuffix, Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr,
LitVerbatim, StrStyle,
};
@ -377,22 +379,22 @@ pub use lit::{
#[cfg(any(feature = "full", feature = "derive"))]
mod mac;
#[cfg(any(feature = "full", feature = "derive"))]
pub use mac::{Macro, MacroDelimiter};
pub use crate::mac::{Macro, MacroDelimiter};
#[cfg(any(feature = "full", feature = "derive"))]
mod derive;
#[cfg(feature = "derive")]
pub use derive::{Data, DataEnum, DataStruct, DataUnion, DeriveInput};
pub use crate::derive::{Data, DataEnum, DataStruct, DataUnion, DeriveInput};
#[cfg(any(feature = "full", feature = "derive"))]
mod op;
#[cfg(any(feature = "full", feature = "derive"))]
pub use op::{BinOp, UnOp};
pub use crate::op::{BinOp, UnOp};
#[cfg(any(feature = "full", feature = "derive"))]
mod ty;
#[cfg(any(feature = "full", feature = "derive"))]
pub use ty::{
pub use crate::ty::{
Abi, BareFnArg, BareFnArgName, ReturnType, Type, TypeArray, TypeBareFn, TypeGroup,
TypeImplTrait, TypeInfer, TypeMacro, TypeNever, TypeParen, TypePath, TypePtr, TypeReference,
TypeSlice, TypeTraitObject, TypeTuple, TypeVerbatim,
@ -401,7 +403,7 @@ pub use ty::{
#[cfg(any(feature = "full", feature = "derive"))]
mod path;
#[cfg(any(feature = "full", feature = "derive"))]
pub use path::{
pub use crate::path::{
AngleBracketedGenericArguments, Binding, Constraint, GenericArgument,
ParenthesizedGenericArguments, Path, PathArguments, PathSegment, QSelf,
};
@ -546,7 +548,7 @@ mod gen {
#[path = "../gen_helper.rs"]
mod helper;
}
pub use gen::*;
pub use crate::gen::*;
// Not public API.
#[doc(hidden)]

View File

@ -1,15 +1,15 @@
use super::*;
use crate::token::{Brace, Bracket, Paren};
use proc_macro2::TokenStream;
#[cfg(feature = "parsing")]
use proc_macro2::{Delimiter, Span, TokenTree};
use token::{Brace, Bracket, Paren};
#[cfg(feature = "parsing")]
use parse::{Parse, ParseStream, Parser, Result};
use crate::parse::{Parse, ParseStream, Parser, Result};
#[cfg(feature = "extra-traits")]
use crate::tt::TokenStreamHelper;
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
#[cfg(feature = "extra-traits")]
use tt::TokenStreamHelper;
ast_struct! {
/// A macro invocation: `println!("{}", mac)`.
@ -194,7 +194,7 @@ pub fn parse_delimiter(input: ParseStream) -> Result<(MacroDelimiter, TokenStrea
pub mod parsing {
use super::*;
use parse::{Parse, ParseStream, Result};
use crate::parse::{Parse, ParseStream, Result};
impl Parse for Macro {
fn parse(input: ParseStream) -> Result<Self> {

View File

@ -203,7 +203,7 @@ use std::str::FromStr;
not(all(target_arch = "wasm32", target_os = "unknown")),
feature = "proc-macro"
))]
use proc_macro;
use crate::proc_macro;
use proc_macro2::{self, Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree};
use crate::buffer::{Cursor, TokenBuffer};

View File

@ -1,5 +1,5 @@
use super::*;
use punctuated::Punctuated;
use crate::punctuated::Punctuated;
ast_struct! {
/// A path at which a named item is exported: `std::collections::HashMap`.
@ -205,9 +205,9 @@ pub mod parsing {
use super::*;
#[cfg(feature = "full")]
use expr;
use ext::IdentExt;
use parse::{Parse, ParseStream, Result};
use crate::expr;
use crate::ext::IdentExt;
use crate::parse::{Parse, ParseStream, Result};
impl Parse for Path {
fn parse(input: ParseStream) -> Result<Self> {
@ -524,7 +524,7 @@ mod printing {
use proc_macro2::TokenStream;
use quote::ToTokens;
use print::TokensOrDefault;
use crate::print::TokensOrDefault;
impl ToTokens for Path {
fn to_tokens(&self, tokens: &mut TokenStream) {

View File

@ -1,10 +1,10 @@
use super::*;
use crate::punctuated::Punctuated;
#[cfg(feature = "extra-traits")]
use crate::tt::TokenStreamHelper;
use proc_macro2::TokenStream;
use punctuated::Punctuated;
#[cfg(feature = "extra-traits")]
use std::hash::{Hash, Hasher};
#[cfg(feature = "extra-traits")]
use tt::TokenStreamHelper;
ast_enum_of_structs! {
/// The possible types that a Rust value could have.
@ -245,8 +245,8 @@ ast_enum! {
pub mod parsing {
use super::*;
use parse::{Parse, ParseStream, Result};
use path;
use crate::parse::{Parse, ParseStream, Result};
use crate::path;
impl Parse for Type {
fn parse(input: ParseStream) -> Result<Self> {
@ -827,7 +827,7 @@ mod printing {
use proc_macro2::TokenStream;
use quote::ToTokens;
use print::TokensOrDefault;
use crate::print::TokensOrDefault;
impl ToTokens for TypeSlice {
fn to_tokens(&self, tokens: &mut TokenStream) {

View File

@ -40,12 +40,12 @@ macro_rules! snapshot {
#[macro_export]
macro_rules! snapshot_impl {
(($expr:ident) as $t:ty, @$snapshot:literal) => {
let $expr = ::macros::Tokens::parse::<$t>($expr).unwrap();
let $expr = crate::macros::Tokens::parse::<$t>($expr).unwrap();
let debug = crate::macros::debug::Lite(&$expr);
insta::assert_debug_snapshot_matches!(debug, @$snapshot);
};
(($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{
let syntax_tree = ::macros::Tokens::parse::<$t>($($expr)*).unwrap();
let syntax_tree = crate::macros::Tokens::parse::<$t>($($expr)*).unwrap();
let debug = crate::macros::debug::Lite(&syntax_tree);
insta::assert_debug_snapshot_matches!(debug, @$snapshot);
syntax_tree