From d300facff6856f1a57520fa7ecc4a2fded4f69f3 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Wed, 27 Dec 2017 19:37:15 -0800 Subject: [PATCH] Update codegen for 2017-12-22 nightly. This works around #513 by patching 'ring' globally using the new '[patch]' Cargo section. --- Cargo.toml | 3 ++ codegen/Cargo.toml | 2 +- codegen/build.rs | 2 +- codegen/src/decorators/derive_form.rs | 44 +++++++++++++++------------ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80842de1..9b749046 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,6 @@ members = [ "examples/tls", "examples/fairings", ] + +[patch.crates-io] +ring = { git = "https://github.com/SergioBenitez/ring", branch = "v0.11" } diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 303cb7ca..3632c260 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -19,7 +19,7 @@ rocket = { version = "0.3.5", path = "../lib/" } log = "0.3" [dev-dependencies] -compiletest_rs = ">= 0.3.1, <= 0.3.3" +compiletest_rs = "0.3.4" [build-dependencies] yansi = "0.3" diff --git a/codegen/build.rs b/codegen/build.rs index 6bd94f97..bd563ff6 100644 --- a/codegen/build.rs +++ b/codegen/build.rs @@ -8,7 +8,7 @@ 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'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"; fn main() { diff --git a/codegen/src/decorators/derive_form.rs b/codegen/src/decorators/derive_form.rs index 2632f543..59c5aeb1 100644 --- a/codegen/src/decorators/derive_form.rs +++ b/codegen/src/decorators/derive_form.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::print::pprust::{stmt_to_string}; use syntax::ast::{ItemKind, Expr, MetaItem, Mutability, VariantData, Ident}; -use syntax::ast::StructField; +use syntax::ast::{StructField, GenericParam}; use syntax::codemap::Span; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -21,34 +21,39 @@ static ONLY_STRUCTS_ERR: &'static str = "`FromForm` can only be derived for \ structures with named fields."; static PRIVATE_LIFETIME: &'static str = "'rocket"; -fn get_struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, span: Span) - -> Option { +fn struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, sp: Span) -> Option { match *item { Annotatable::Item(ref item) => match item.node { ItemKind::Struct(_, ref generics) => { - match generics.lifetimes.len() { - 0 => None, - 1 => { - let lifetime = generics.lifetimes[0].lifetime; - Some(lifetime.ident.to_string()) - } - _ => { - ecx.span_err(item.span, "cannot have more than one \ - lifetime parameter when deriving `FromForm`."); - None - } + let mut lifetimes = generics.params.iter() + .filter_map(|p| match *p { + GenericParam::Lifetime(ref def) => Some(def), + _ => None + }); + + let lifetime = lifetimes.next().map(|d| d.lifetime.ident.to_string()); + if lifetimes.next().is_some() { + ecx.span_err(generics.span, "cannot have more than one \ + 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. -pub fn from_form_derive(ecx: &mut ExtCtxt, span: Span, meta_item: &MetaItem, - annotated: &Annotatable, push: &mut FnMut(Annotatable)) { - let struct_lifetime = get_struct_lifetime(ecx, annotated, span); +pub fn from_form_derive( + ecx: &mut ExtCtxt, + 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 { Some(ref lifetime) => (Some(lifetime.as_str()), ty::LifetimeBounds::empty()), 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)) } +