Update rocket_codegen for latest nightly.

This commit is contained in:
Sergio Benitez 2016-12-06 00:31:01 -08:00
parent aff3f643f1
commit 0731cd6150
12 changed files with 43 additions and 44 deletions

View File

@ -4,8 +4,7 @@ use std::mem::transmute;
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::print::pprust::{stmt_to_string};
use syntax::parse::token::{str_to_ident};
use syntax::ast::{ItemKind, Expr, MetaItem, Mutability, VariantData};
use syntax::ast::{ItemKind, Expr, MetaItem, Mutability, VariantData, Ident};
use syntax::codemap::Span;
use syntax::ext::build::AstBuilder;
use syntax::ptr::P;
@ -107,7 +106,7 @@ pub fn from_form_derive(ecx: &mut ExtCtxt, span: Span, meta_item: &MetaItem,
}
],
associated_types: vec![
(str_to_ident("Error"), error_type.clone())
(Ident::from_str("Error"), error_type.clone())
],
};

View File

@ -5,7 +5,7 @@ use syntax::codemap::{Span};
use syntax::ast::{MetaItem, Ident, TyKind};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::tokenstream::TokenTree;
use syntax::parse::token::{self, str_to_ident};
use syntax::parse::token;
use parser::ErrorParams;
const ERR_PARAM: &'static str = "_error";
@ -53,7 +53,7 @@ pub fn error_decorator(ecx: &mut ExtCtxt, sp: Span, meta_item: &MetaItem,
let user_fn_name = error.annotated_fn.ident();
let catch_fn_name = user_fn_name.prepend(CATCH_FN_PREFIX);
let code = error.code.node;
let (err_ident, req_ident) = (str_to_ident(ERR_PARAM), str_to_ident(REQ_PARAM));
let (err_ident, req_ident) = (Ident::from_str(ERR_PARAM), Ident::from_str(REQ_PARAM));
let fn_arguments = error.generate_fn_arguments(ecx, err_ident, req_ident);
emit_item(push, quote_item!(ecx,

View File

@ -11,7 +11,7 @@ use syntax::tokenstream::TokenTree;
use syntax::ast::{Arg, Ident, Stmt, Expr, MetaItem, Path};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::parse::token::{self, str_to_ident};
use syntax::parse::token;
use syntax::ptr::P;
use rocket::http::{Method, ContentType};
@ -288,7 +288,7 @@ macro_rules! method_decorator {
($name:ident, $method:ident) => (
pub fn $name(ecx: &mut ExtCtxt, sp: Span, meta_item: &MetaItem,
annotated: &Annotatable, push: &mut FnMut(Annotatable)) {
let i_sp = meta_item.span.shorten_to(meta_item.name().len() as u32);
let i_sp = meta_item.span.shorten_to(stringify!($method).len());
let method = Some(span(Method::$method, i_sp));
generic_route_decorator(method, ecx, sp, meta_item, annotated, push);
}

View File

@ -17,7 +17,7 @@ mod decorators;
use rustc_plugin::Registry;
use syntax::ext::base::SyntaxExtension;
use syntax::parse::token::intern;
use syntax::symbol::Symbol;
const PARAM_PREFIX: &'static str = "rocket_param_";
const ROUTE_STRUCT_PREFIX: &'static str = "static_rocket_route_info_for_";
@ -27,7 +27,7 @@ const CATCH_FN_PREFIX: &'static str = "rocket_catch_fn_";
macro_rules! register_decorators {
($registry:expr, $($name:expr => $func:ident),+) => (
$($registry.register_syntax_extension(intern($name),
$($registry.register_syntax_extension(Symbol::intern($name),
SyntaxExtension::MultiDecorator(Box::new(decorators::$func)));
)+
)

View File

@ -57,7 +57,7 @@ fn parse_code(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned<u16> {
let sp = meta_item.span();
if let Some((name, lit)) = meta_item.name_value() {
if name != "code" {
if name != &"code" {
ecx.span_err(sp, "the first key, if any, must be 'code'");
} else if let LitKind::Int(n, _) = lit.node {
return code_from_u64(span(n, lit.span))

View File

@ -1,7 +1,6 @@
use syntax::ast::Ident;
use syntax::ext::base::ExtCtxt;
use syntax::codemap::{Span, Spanned, BytePos};
use syntax::parse::token::str_to_ident;
use utils::{span, SpanExt, is_valid_ident};
@ -87,13 +86,13 @@ impl<'s, 'a, 'c> Iterator for ParamIter<'s, 'a, 'c> {
} else if param.starts_with("_") {
err(self.ctxt, param_span, "parameters cannot be ignored")
} else if is_many && !self.string.is_empty() {
let sp = self.span.shorten_to(self.string.len() as u32);
let sp = self.span.shorten_to(self.string.len());
self.ctxt.struct_span_err(sp, "text after a trailing '..' param")
.span_note(param_span, "trailing param is here")
.emit();
None
} else {
let spanned_ident = span(str_to_ident(param), param_span);
let spanned_ident = span(Ident::from_str(param), param_span);
match is_many {
true => Some(Param::Many(spanned_ident)),
false => Some(Param::Single(spanned_ident))

View File

@ -4,7 +4,6 @@ use std::collections::HashSet;
use syntax::ast::*;
use syntax::ext::base::{ExtCtxt, Annotatable};
use syntax::codemap::{Span, Spanned, dummy_spanned};
use syntax::parse::token::str_to_ident;
use utils::{span, MetaItemExt, SpanExt, is_valid_ident};
use super::{Function, ParamIter};
@ -142,7 +141,7 @@ fn is_valid_method(method: Method) -> bool {
pub fn kv_from_nested(item: &NestedMetaItem) -> Option<KVSpanned<LitKind>> {
item.name_value().map(|(name, value)| {
let k_span = item.span().shorten_to(name.len() as u32);
let k_span = item.span().shorten_to(name.as_str().len());
KVSpanned {
key: span(name.to_string(), k_span),
value: value.clone(),
@ -156,7 +155,7 @@ fn param_string_to_ident(ecx: &ExtCtxt, s: Spanned<&str>) -> Option<Ident> {
if string.starts_with('<') && string.ends_with('>') {
let param = &string[1..(string.len() - 1)];
if is_valid_ident(param) {
return Some(str_to_ident(param));
return Some(Ident::from_str(param));
}
ecx.span_err(s.span, "parameter name must be alphanumeric");
@ -169,7 +168,7 @@ fn param_string_to_ident(ecx: &ExtCtxt, s: Spanned<&str>) -> Option<Ident> {
fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned<Method> {
if let Some(word) = meta_item.word() {
if let Ok(method) = Method::from_str(&*word.name()) {
if let Ok(method) = Method::from_str(&word.name().as_str()) {
if is_valid_method(method) {
return span(method, word.span());
}
@ -201,15 +200,15 @@ fn parse_path(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> (Spanned<String>, Op
let sp = meta_item.span();
if let Some((name, lit)) = meta_item.name_value() {
if name != "path" {
if name != &"path" {
ecx.span_err(sp, "the first key, if any, must be 'path'");
} else if let LitKind::Str(ref s, _) = lit.node {
return from_string(s, lit.span);
return from_string(&s.as_str(), lit.span);
} else {
ecx.span_err(lit.span, "`path` value must be a string")
}
} else if let Some(s) = meta_item.str_lit() {
return from_string(s, sp);
return from_string(&s.as_str(), sp);
} else {
ecx.struct_span_err(sp, r#"expected `path = string` or a path string"#)
.help(r#"you can specify the path directly as a string, \
@ -228,11 +227,12 @@ fn parse_opt<O, T, F>(ecx: &ExtCtxt, kv: &KVSpanned<T>, f: F) -> Option<KVSpanne
}
fn parse_data(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> Ident {
let mut str_name = "unknown";
let mut ident = Ident::from_str("unknown");
if let LitKind::Str(ref s, _) = *kv.value() {
str_name = s;
if let Some(ident) = param_string_to_ident(ecx, span(s, kv.value.span)) {
return ident;
ident = Ident::from_str(&s.as_str());
match param_string_to_ident(ecx, span(&s.as_str(), kv.value.span)) {
Some(ident) => return ident,
_ => { /* fall through if not an ident */ }
}
}
@ -243,7 +243,7 @@ fn parse_data(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> Ident {
parameter inside '<' '>'. e.g: data = "<user_form>""#)
.emit();
str_to_ident(str_name)
ident
}
fn parse_rank(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> isize {
@ -268,7 +268,7 @@ fn parse_rank(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> isize {
fn parse_format(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> ContentType {
if let LitKind::Str(ref s, _) = *kv.value() {
if let Ok(ct) = ContentType::from_str(s) {
if let Ok(ct) = ContentType::from_str(&s.as_str()) {
if ct.is_ext() {
let msg = format!("'{}' is not a known content-type", s);
ecx.span_warn(kv.value.span, &msg);

View File

@ -1,5 +1,4 @@
use std::fmt::Display;
use syntax::parse::token::str_to_ident;
use syntax::ast::Ident;
pub trait IdentExt {
@ -10,11 +9,11 @@ pub trait IdentExt {
impl IdentExt for Ident {
fn prepend<T: Display>(&self, other: T) -> Ident {
let new_ident = format!("{}{}", other, self.name);
str_to_ident(new_ident.as_str())
Ident::from_str(new_ident.as_str())
}
fn append<T: Display>(&self, other: T) -> Ident {
let new_ident = format!("{}{}", self.name, other);
str_to_ident(new_ident.as_str())
Ident::from_str(new_ident.as_str())
}
}

View File

@ -1,21 +1,21 @@
use syntax::ast::{LitKind, NestedMetaItem, MetaItemKind, Lit};
use syntax::parse::token::InternedString;
use syntax::symbol::Symbol;
pub trait MetaItemExt {
fn name_value(&self) -> Option<(&InternedString, &Lit)>;
fn str_lit(&self) -> Option<&InternedString>;
fn name_value(&self) -> Option<(&Symbol, &Lit)>;
fn str_lit(&self) -> Option<&Symbol>;
fn int_lit(&self) -> Option<u64>;
}
impl MetaItemExt for NestedMetaItem {
fn name_value(&self) -> Option<(&InternedString, &Lit)> {
fn name_value(&self) -> Option<(&Symbol, &Lit)> {
self.meta_item().and_then(|mi| match mi.node {
MetaItemKind::NameValue(ref s, ref l) => Some((s, l)),
MetaItemKind::NameValue(ref l) => Some((&mi.name, l)),
_ => None,
})
}
fn str_lit(&self) -> Option<&InternedString> {
fn str_lit(&self) -> Option<&Symbol> {
self.literal().and_then(|lit| match lit.node {
LitKind::Str(ref s, _) => Some(s),
_ => None,

View File

@ -62,11 +62,12 @@ macro_rules! quote_enum {
($ecx:expr, $var:expr => $(::$root:ident)+
{ $($variant:ident),+ ; $($extra:pat => $result:expr),* }) => ({
use syntax::codemap::DUMMY_SP;
use syntax::ast::Ident;
use $(::$root)+::*;
let root_idents = vec![$(str_to_ident(stringify!($root))),+];
let root_idents = vec![$(Ident::from_str(stringify!($root))),+];
match $var {
$($variant => {
let variant = str_to_ident(stringify!($variant));
let variant = Ident::from_str(stringify!($variant));
let mut idents = root_idents.clone();
idents.push(variant);
$ecx.path_global(DUMMY_SP, idents)

View File

@ -1,15 +1,15 @@
use syntax::codemap::{Span, BytePos};
pub trait SpanExt {
fn shorten_to(self, to_length: u32) -> Span;
fn shorten_to(self, to_length: usize) -> Span;
/// Trim the span on the left and right by `length`.
fn trim(self, length: u32) -> Span;
}
impl SpanExt for Span {
fn shorten_to(mut self, to_length: u32) -> Span {
self.hi = self.lo + BytePos(to_length);
fn shorten_to(mut self, to_length: usize) -> Span {
self.hi = self.lo + BytePos(to_length as u32);
self
}

View File

@ -60,10 +60,11 @@ for file in ${EXAMPLES_DIR}/*; do
if [ -x "${bootstrap_script}" ]; then
echo ":: Bootstrapping ${file}..."
if [ "$(basename $file)" = "todo" ]; then
echo ":: Skipping todo example due to broken Diesel..."
continue
fi
# We're just going to leave this commented out for next time...
# if [ "$(basename $file)" = "todo" ]; then
# echo ":: Skipping todo example due to broken Diesel..."
# continue
# fi
if ! ${bootstrap_script}; then
echo ":: Running bootstrap script (${bootstrap_script}) failed!"