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