mirror of https://github.com/rwf2/Rocket.git
Update codegen for 2017-12-22 nightly.
This works around #513 by patching 'ring' globally using the new '[patch]' Cargo section.
This commit is contained in:
parent
3d38e46d7c
commit
b8367d52f8
|
@ -38,3 +38,6 @@ members = [
|
||||||
"examples/tls",
|
"examples/tls",
|
||||||
"examples/fairings",
|
"examples/fairings",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
ring = { git = "https://github.com/SergioBenitez/ring", branch = "v0.12" }
|
||||||
|
|
|
@ -20,7 +20,7 @@ ordermap = "0.3"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
compiletest_rs = ">= 0.3.1, <= 0.3.3"
|
compiletest_rs = "0.3.4"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
yansi = "0.3"
|
yansi = "0.3"
|
||||||
|
|
|
@ -8,7 +8,7 @@ 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's codegen.
|
// Specifies the minimum nightly version needed to compile Rocket's codegen.
|
||||||
const MIN_DATE: &'static str = "2017-12-17";
|
const MIN_DATE: &'static str = "2017-12-22";
|
||||||
const MIN_VERSION: &'static str = "1.24.0-nightly";
|
const MIN_VERSION: &'static str = "1.24.0-nightly";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::collections::HashMap;
|
||||||
use syntax::ext::base::{Annotatable, ExtCtxt};
|
use syntax::ext::base::{Annotatable, ExtCtxt};
|
||||||
use syntax::print::pprust::{stmt_to_string};
|
use syntax::print::pprust::{stmt_to_string};
|
||||||
use syntax::ast::{ItemKind, Expr, MetaItem, Mutability, VariantData, Ident};
|
use syntax::ast::{ItemKind, Expr, MetaItem, Mutability, VariantData, Ident};
|
||||||
use syntax::ast::StructField;
|
use syntax::ast::{StructField, GenericParam};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
@ -21,34 +21,39 @@ static ONLY_STRUCTS_ERR: &'static str = "`FromForm` can only be derived for \
|
||||||
structures with named fields.";
|
structures with named fields.";
|
||||||
static PRIVATE_LIFETIME: &'static str = "'rocket";
|
static PRIVATE_LIFETIME: &'static str = "'rocket";
|
||||||
|
|
||||||
fn get_struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, span: Span)
|
fn struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, sp: Span) -> Option<String> {
|
||||||
-> Option<String> {
|
|
||||||
match *item {
|
match *item {
|
||||||
Annotatable::Item(ref item) => match item.node {
|
Annotatable::Item(ref item) => match item.node {
|
||||||
ItemKind::Struct(_, ref generics) => {
|
ItemKind::Struct(_, ref generics) => {
|
||||||
match generics.lifetimes.len() {
|
let mut lifetimes = generics.params.iter()
|
||||||
0 => None,
|
.filter_map(|p| match *p {
|
||||||
1 => {
|
GenericParam::Lifetime(ref def) => Some(def),
|
||||||
let lifetime = generics.lifetimes[0].lifetime;
|
_ => None
|
||||||
Some(lifetime.ident.to_string())
|
});
|
||||||
}
|
|
||||||
_ => {
|
let lifetime = lifetimes.next().map(|d| d.lifetime.ident.to_string());
|
||||||
ecx.span_err(item.span, "cannot have more than one \
|
if lifetimes.next().is_some() {
|
||||||
lifetime parameter when deriving `FromForm`.");
|
ecx.span_err(generics.span, "cannot have more than one \
|
||||||
None
|
lifetime parameter when deriving `FromForm`.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lifetime
|
||||||
},
|
},
|
||||||
_ => ecx.span_fatal(span, ONLY_STRUCTS_ERR)
|
_ => ecx.span_fatal(sp, ONLY_STRUCTS_ERR)
|
||||||
},
|
},
|
||||||
_ => ecx.span_fatal(span, ONLY_STRUCTS_ERR)
|
_ => ecx.span_fatal(sp, ONLY_STRUCTS_ERR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use proper logging to emit the error messages.
|
// TODO: Use proper logging to emit the error messages.
|
||||||
pub fn from_form_derive(ecx: &mut ExtCtxt, span: Span, meta_item: &MetaItem,
|
pub fn from_form_derive(
|
||||||
annotated: &Annotatable, push: &mut FnMut(Annotatable)) {
|
ecx: &mut ExtCtxt,
|
||||||
let struct_lifetime = get_struct_lifetime(ecx, annotated, span);
|
span: Span,
|
||||||
|
meta_item: &MetaItem,
|
||||||
|
annotated: &Annotatable,
|
||||||
|
push: &mut FnMut(Annotatable)
|
||||||
|
) {
|
||||||
|
let struct_lifetime = struct_lifetime(ecx, annotated, span);
|
||||||
let (lifetime_var, trait_generics) = match struct_lifetime {
|
let (lifetime_var, trait_generics) = match struct_lifetime {
|
||||||
Some(ref lifetime) => (Some(lifetime.as_str()), ty::LifetimeBounds::empty()),
|
Some(ref lifetime) => (Some(lifetime.as_str()), ty::LifetimeBounds::empty()),
|
||||||
None => (Some(PRIVATE_LIFETIME), ty::LifetimeBounds {
|
None => (Some(PRIVATE_LIFETIME), ty::LifetimeBounds {
|
||||||
|
@ -325,3 +330,4 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct
|
||||||
cx.expr_block(cx.block(trait_span, stmts))
|
cx.expr_block(cx.block(trait_span, stmts))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue