mirror of https://github.com/rwf2/Rocket.git
Update codegen and related dependencies for latest nightly.
This commit is contained in:
parent
350f4d04cd
commit
00dd691252
|
@ -14,6 +14,6 @@ license = "MIT/Apache-2.0"
|
|||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = "0.5.1"
|
||||
proc-macro2 = { version = "0.3.6", features = ["nightly"] }
|
||||
syn = { version = "0.13.1", features = ["full", "extra-traits"] }
|
||||
quote = "0.6.1"
|
||||
proc-macro2 = { version = "0.4.3", features = ["nightly"] }
|
||||
syn = { version = "0.14.0", features = ["full", "extra-traits"] }
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
use syn::*;
|
||||
use ext::*;
|
||||
use quote::Tokens;
|
||||
use proc_macro2::TokenStream;
|
||||
use spanned::Spanned;
|
||||
|
||||
use FieldMember;
|
||||
|
||||
pub trait CodegenFieldsExt {
|
||||
fn surround(&self, tokens: Tokens) -> Tokens;
|
||||
fn ignore_tokens(&self) -> Tokens;
|
||||
fn id_match_tokens(&self) -> Tokens;
|
||||
fn surround(&self, tokens: TokenStream) -> TokenStream;
|
||||
fn ignore_tokens(&self) -> TokenStream;
|
||||
fn id_match_tokens(&self) -> TokenStream;
|
||||
}
|
||||
|
||||
pub fn field_to_ident(i: usize, field: &Field) -> Ident {
|
||||
let name = match field.ident {
|
||||
Some(id) => format!("_{}", id),
|
||||
Some(ref id) => format!("_{}", id),
|
||||
None => format!("_{}", i)
|
||||
};
|
||||
|
||||
Ident::new(&name, field.span().into())
|
||||
}
|
||||
|
||||
pub fn field_to_match((i, field): (usize, &Field)) -> Tokens {
|
||||
pub fn field_to_match((i, field): (usize, &Field)) -> TokenStream {
|
||||
let ident = field_to_ident(i, field);
|
||||
match field.ident {
|
||||
Some(id) => quote!(#id: #ident),
|
||||
Some(ref id) => quote!(#id: #ident),
|
||||
None => quote!(#ident)
|
||||
}
|
||||
}
|
||||
|
||||
impl CodegenFieldsExt for Fields {
|
||||
fn surround(&self, tokens: Tokens) -> Tokens {
|
||||
fn surround(&self, tokens: TokenStream) -> TokenStream {
|
||||
match *self {
|
||||
Fields::Named(..) => quote!({ #tokens }),
|
||||
Fields::Unnamed(..) => quote!(( #tokens )),
|
||||
|
@ -37,11 +37,11 @@ impl CodegenFieldsExt for Fields {
|
|||
}
|
||||
}
|
||||
|
||||
fn ignore_tokens(&self) -> Tokens {
|
||||
fn ignore_tokens(&self) -> TokenStream {
|
||||
self.surround(quote!(..))
|
||||
}
|
||||
|
||||
fn id_match_tokens(&self) -> Tokens {
|
||||
fn id_match_tokens(&self) -> TokenStream {
|
||||
let idents = self.iter()
|
||||
.enumerate()
|
||||
.map(field_to_match);
|
||||
|
@ -50,12 +50,12 @@ impl CodegenFieldsExt for Fields {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait TokensExt {
|
||||
fn tokens(&self) -> Tokens;
|
||||
pub trait TokenStreamExt {
|
||||
fn tokens(&self) -> TokenStream;
|
||||
}
|
||||
|
||||
impl<'f> TokensExt for FieldMember<'f> {
|
||||
fn tokens(&self) -> Tokens {
|
||||
impl<'f> TokenStreamExt for FieldMember<'f> {
|
||||
fn tokens(&self) -> TokenStream {
|
||||
let index = self.member.unnamed().map(|i| i.index).unwrap_or(0);
|
||||
let ident = field_to_ident(index as usize, &self.field);
|
||||
quote!(#ident)
|
||||
|
@ -64,15 +64,15 @@ impl<'f> TokensExt for FieldMember<'f> {
|
|||
|
||||
// use rocket::http::{ContentType, MediaType, Status};
|
||||
|
||||
// impl TokensExt for ContentType {
|
||||
// fn tokens(&self) -> Tokens {
|
||||
// impl TokenStreamExt for ContentType {
|
||||
// fn tokens(&self) -> TokenStream {
|
||||
// let mt_tokens = self.0.tokens();
|
||||
// quote!(rocket::http::ContentType(#mt_tokens))
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl TokensExt for MediaType {
|
||||
// fn tokens(&self) -> Tokens {
|
||||
// impl TokenStreamExt for MediaType {
|
||||
// fn tokens(&self) -> TokenStream {
|
||||
// let (top, sub) = (self.top().as_str(), self.sub().as_str());
|
||||
// let (keys, values) = (self.params().map(|(k, _)| k), self.params().map(|(_, v)| v));
|
||||
// quote!(rocket::http::MediaType {
|
||||
|
@ -93,8 +93,8 @@ impl<'f> TokensExt for FieldMember<'f> {
|
|||
// }
|
||||
// }
|
||||
|
||||
// impl TokensExt for Status {
|
||||
// fn tokens(&self) -> Tokens {
|
||||
// impl TokenStreamExt for Status {
|
||||
// fn tokens(&self) -> TokenStream {
|
||||
// let (code, reason) = (self.code, self.reason);
|
||||
// quote!(rocket::http::Status { code: #code, reason: #reason })
|
||||
// }
|
||||
|
|
|
@ -80,8 +80,8 @@ impl FieldsExt for Fields {
|
|||
|
||||
fn to_field_members<'f>(&'f self) -> Box<Iterator<Item = FieldMember<'f>> + 'f> {
|
||||
Box::new(self.iter().enumerate().map(|(index, field)| {
|
||||
if let Some(ident) = field.ident {
|
||||
FieldMember { field, member: Member::Named(ident) }
|
||||
if let Some(ref ident) = field.ident {
|
||||
FieldMember { field, member: Member::Named(ident.clone()) }
|
||||
} else {
|
||||
let index = Index { index: index as u32, span: field.span().into() };
|
||||
let member = Member::Unnamed(index);
|
||||
|
|
|
@ -61,13 +61,13 @@ fn real_derive_from_form_value(input: TokenStream) -> PResult<TokenStream> {
|
|||
})?;
|
||||
|
||||
// Validate the enum.
|
||||
let name = input.ident;
|
||||
let name = input.ident.clone();
|
||||
let enum_data = validate_input(input)?;
|
||||
|
||||
// Create iterators over the identifers as idents and as strings.
|
||||
let variant_strs = enum_data.variants.iter().map(|v| v.ident.as_ref() as &str);
|
||||
let variant_idents = enum_data.variants.iter().map(|v| v.ident);
|
||||
let names = ::std::iter::repeat(name);
|
||||
let variant_strs = enum_data.variants.iter().map(|v| v.ident.to_string());
|
||||
let variant_idents = enum_data.variants.iter().map(|v| v.ident.clone());
|
||||
let names = ::std::iter::repeat(&name);
|
||||
|
||||
// Generate the implementation.
|
||||
Ok(quote! {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use proc_macro::Span;
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{Tokens, ToTokens};
|
||||
use quote::ToTokens;
|
||||
|
||||
pub trait Spanned {
|
||||
fn span(&self) -> Span;
|
||||
|
@ -10,9 +9,7 @@ pub trait Spanned {
|
|||
// FIXME: Remove this once proc_macro's stabilize.
|
||||
impl<T: ToTokens> Spanned for T {
|
||||
fn span(&self) -> Span {
|
||||
let mut tokens = Tokens::new();
|
||||
self.to_tokens(&mut tokens);
|
||||
let token_stream = TokenStream::from(tokens);
|
||||
let token_stream = self.into_token_stream();
|
||||
let mut iter = token_stream.into_iter();
|
||||
let mut span = match iter.next() {
|
||||
Some(tt) => tt.span().unstable(),
|
||||
|
|
|
@ -29,8 +29,8 @@ time = "0.1"
|
|||
memchr = "2"
|
||||
base64 = "0.9"
|
||||
smallvec = "0.6"
|
||||
pear = { git = "http://github.com/SergioBenitez/pear", rev = "44bbca0" }
|
||||
pear_codegen = { git = "http://github.com/SergioBenitez/pear", rev = "44bbca0" }
|
||||
pear = { git = "http://github.com/SergioBenitez/pear", rev = "a96a7fd" }
|
||||
pear_codegen = { git = "http://github.com/SergioBenitez/pear", rev = "a96a7fd" }
|
||||
rustls = { version = "0.12.0", optional = true }
|
||||
hyper = { version = "0.10.13", default-features = false }
|
||||
indexmap = "1.0"
|
||||
|
|
|
@ -8,8 +8,8 @@ use yansi::Color::{Red, Yellow, Blue, White};
|
|||
use version_check::{supports_features, is_min_version, is_min_date};
|
||||
|
||||
// Specifies the minimum nightly version needed to compile Rocket.
|
||||
const MIN_DATE: &'static str = "2018-04-28";
|
||||
const MIN_VERSION: &'static str = "1.27.0-nightly";
|
||||
const MIN_DATE: &'static str = "2018-05-20";
|
||||
const MIN_VERSION: &'static str = "1.28.0-nightly";
|
||||
|
||||
fn main() {
|
||||
let ok_channel = supports_features();
|
||||
|
|
Loading…
Reference in New Issue