Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codegen for 2018-06-22 nightly. #666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only part I'm not quite certain of. Seems to work, but there might be a better way of doing this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ident include the initial tick '? You should take a look at the generated code and ensure that it looks correct, even if it's accepted by the compiler otherwise. Aside from this, this looks good, though it would seem that kind doesn't need to be a ref kind.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pushing a slightly different fix for this in 0.3. Let's use the same one for master.

_ => 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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this link back to the rust repository more concretely? I wasn't sure if I should refer to a PR, commit, URL, or just leave a generic note like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's link to the PR that removed the method. Something like, "See https://github.com/rust-lang/rust/foo/bar/baz for more details.".

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))
}
}