Skip to content

Commit

Permalink
Update codegen for 2018-06-22 nightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jebrosen committed Jun 23, 2018
1 parent df71111 commit f33c8e3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/codegen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions core/codegen/src/decorators/derive_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,11 +27,11 @@ fn struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, sp: Span) -> Option<St
ItemKind::Struct(_, ref generics) => {
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`.");
Expand Down
6 changes: 3 additions & 3 deletions core/codegen/src/macros/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,8 +132,8 @@ pub fn uri_internal(

// path for call: <T as FromUriParam<_>>::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);

Expand Down
3 changes: 1 addition & 2 deletions core/codegen/src/parser/uri_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 25 additions & 2 deletions core/codegen/src/utils/parser_ext.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand All @@ -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<T, F>(&mut self, bra: &token::Token, ket: &token::Token, sep: SeqSep, f: F)
-> PResult<'a, codemap::Spanned<Vec<T>>> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>;
}

impl<'a> ParserExt<'a> for Parser<'a> {
Expand Down Expand Up @@ -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<T, F>(&mut self,
bra: &token::Token,
ket: &token::Token,
sep: SeqSep,
f: F)
-> PResult<'a, codemap::Spanned<Vec<T>>> 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))
}
}

0 comments on commit f33c8e3

Please sign in to comment.