From f33c8e3434c7c5af4324a51bfc5b95e3c170b27c Mon Sep 17 00:00:00 2001 From: jeb Date: Mon, 18 Jun 2018 20:31:15 -1000 Subject: [PATCH] Update codegen for 2018-06-22 nightly. --- core/codegen/build.rs | 2 +- core/codegen/src/decorators/derive_form.rs | 6 ++--- core/codegen/src/macros/uri.rs | 6 ++--- core/codegen/src/parser/uri_macro.rs | 3 +-- core/codegen/src/utils/parser_ext.rs | 27 ++++++++++++++++++++-- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/core/codegen/build.rs b/core/codegen/build.rs index b12d413a1d..5d108b0c5f 100644 --- a/core/codegen/build.rs +++ b/core/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 = "2018-05-30"; +const MIN_DATE: &'static str = "2018-06-22"; const MIN_VERSION: &'static str = "1.28.0-nightly"; fn main() { diff --git a/core/codegen/src/decorators/derive_form.rs b/core/codegen/src/decorators/derive_form.rs index e8eaa82476..423ab75c00 100644 --- a/core/codegen/src/decorators/derive_form.rs +++ b/core/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, GenericParam}; +use syntax::ast::{StructField, GenericParam, GenericParamKind}; use syntax::codemap::Span; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -27,11 +27,11 @@ fn struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, sp: Span) -> Option { let mut lifetimes = generics.params.iter() .filter_map(|p| match *p { - GenericParam::Lifetime(ref def) => Some(def), + GenericParam { ref ident, ref kind, .. } if *kind == GenericParamKind::Lifetime => Some(ident), _ => None }); - let lifetime = lifetimes.next().map(|d| d.lifetime.ident.to_string()); + let lifetime = lifetimes.next().map(|ident| ident.to_string()); if lifetimes.next().is_some() { ecx.span_err(generics.span, "cannot have more than one \ lifetime parameter when deriving `FromForm`."); diff --git a/core/codegen/src/macros/uri.rs b/core/codegen/src/macros/uri.rs index 7988496eb5..349b4c0a41 100644 --- a/core/codegen/src/macros/uri.rs +++ b/core/codegen/src/macros/uri.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use syntax::codemap::Span; use syntax::ext::base::{DummyResult, ExtCtxt, MacEager, MacResult}; use syntax::tokenstream::{TokenStream, TokenTree}; -use syntax::ast::{self, MacDelimiter, Ident}; +use syntax::ast::{self, GenericArg, MacDelimiter, Ident}; use syntax::symbol::Symbol; use syntax::parse::PResult; use syntax::ext::build::AstBuilder; @@ -132,8 +132,8 @@ pub fn uri_internal( // path for call: >::from_uri_param let idents = split_idents("rocket::http::uri::FromUriParam"); - let generics = vec![ecx.ty(span, ast::TyKind::Infer)]; - let trait_path = ecx.path_all(span, true, idents, vec![], generics, vec![]); + let generics = vec![GenericArg::Type(ecx.ty(span, ast::TyKind::Infer))]; + let trait_path = ecx.path_all(span, true, idents, generics, vec![]); let method = Ident::new(Symbol::intern("from_uri_param"), span); let (qself, path) = ecx.qpath(ty.clone(), trait_path, method); diff --git a/core/codegen/src/parser/uri_macro.rs b/core/codegen/src/parser/uri_macro.rs index 8f251290f2..62ef6cb724 100644 --- a/core/codegen/src/parser/uri_macro.rs +++ b/core/codegen/src/parser/uri_macro.rs @@ -4,9 +4,8 @@ use syntax::codemap::{Spanned, Span}; use syntax::ext::base::ExtCtxt; use syntax::symbol::LocalInternedString; use syntax::ast::{self, Expr, Name, Ident, Path}; -use syntax::parse::PResult; +use syntax::parse::{SeqSep, PResult}; use syntax::parse::token::{DelimToken, Token}; -use syntax::parse::common::SeqSep; use syntax::parse::parser::{Parser, PathStyle}; use syntax::print::pprust::ty_to_string; use syntax::ptr::P; diff --git a/core/codegen/src/utils/parser_ext.rs b/core/codegen/src/utils/parser_ext.rs index 657e7606c4..d4faccc64a 100644 --- a/core/codegen/src/utils/parser_ext.rs +++ b/core/codegen/src/utils/parser_ext.rs @@ -1,8 +1,9 @@ +use syntax::codemap; use syntax::parse::parser::{PathStyle, Parser}; -use syntax::parse::PResult; +use syntax::parse::{SeqSep, PResult}; use syntax::ast::{self, Path, StrStyle, Ident}; +use syntax::parse::token; use syntax::parse::token::Token::{Eof, Comma}; -use syntax::parse::common::SeqSep; use syntax::symbol::Symbol; pub trait ParserExt<'a> { @@ -14,6 +15,10 @@ pub trait ParserExt<'a> { // Like `parse_ident` but also looks for an `ident` in a `Pat`. fn parse_ident_inc_pat(&mut self) -> PResult<'a, Ident>; + + // Duplicates previously removed method in libsyntax + fn parse_seq(&mut self, bra: &token::Token, ket: &token::Token, sep: SeqSep, f: F) + -> PResult<'a, codemap::Spanned>> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>; } impl<'a> ParserExt<'a> for Parser<'a> { @@ -53,4 +58,22 @@ impl<'a> ParserExt<'a> for Parser<'a> { Ok(ident) }) } + + // NB: Do not use this function unless you actually plan to place the + // spanned list in the AST. + fn parse_seq(&mut self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: F) + -> PResult<'a, codemap::Spanned>> where + F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, + { + let lo = self.span; + self.expect(bra)?; + let result = self.parse_seq_to_before_end(ket, sep, f)?; + let hi = self.span; + self.bump(); + Ok(codemap::respan(lo.to(hi), result)) + } }