Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 1f2f38ea5f441b9517de43271eb47ddaccd802bd
parent cfdb2a404b8ae1f42d551b200d0555fe2b85c1f9
Author: Sergio Benitez <sb@sergio.bz>
Date:   Fri, 14 Sep 2018 23:15:31 -0700

Update to latest 'derive_utils'.

Diffstat:
Mcontrib/codegen/Cargo.toml | 2+-
Mcore/codegen_next/Cargo.toml | 2+-
Mcore/codegen_next/src/derive/from_form.rs | 12++++++------
Mcore/codegen_next/src/http_codegen.rs | 23++++++++++-------------
Mcore/codegen_next/src/lib.rs | 2+-
Mcore/codegen_next/tests/ui-fail/from_form.rs | 6+++---
Mcore/codegen_next/tests/ui-fail/from_form.stderr | 16++++++++--------
Mcore/codegen_next/tests/ui-fail/from_form_value.rs | 2+-
Mcore/codegen_next/tests/ui-fail/from_form_value.stderr | 4++--
9 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/contrib/codegen/Cargo.toml b/contrib/codegen/Cargo.toml @@ -21,7 +21,7 @@ proc-macro = true [dependencies.derive_utils] git = "https://github.com/SergioBenitez/derive-utils" -rev = "160da392" +rev = "5fad71394" [dependencies] quote = "0.6" diff --git a/core/codegen_next/Cargo.toml b/core/codegen_next/Cargo.toml @@ -22,7 +22,7 @@ rocket_http = { version = "0.4.0-dev", path = "../http/" } [dependencies.derive_utils] git = "https://github.com/SergioBenitez/derive-utils" -rev = "160da392" +rev = "5fad71394" [dev-dependencies] rocket = { version = "0.4.0-dev", path = "../lib" } diff --git a/core/codegen_next/src/derive/from_form.rs b/core/codegen_next/src/derive/from_form.rs @@ -1,5 +1,5 @@ use proc_macro::{Span, TokenStream}; -use derive_utils::{*, syn, ext::{TypeExt, Split3}}; +use derive_utils::{*, ext::{TypeExt, Split3}}; #[derive(FromMeta)] struct Form { @@ -23,13 +23,13 @@ fn is_valid_field_name(s: &str) -> bool { } impl FromMeta for FormField { - fn from_meta(meta: &syn::Meta) -> Result<Self> { - let string = <SpanWrapped<String>>::from_meta(meta)?; - if !is_valid_field_name(&string.value) { - return Err(string.value_span.error("invalid form field name")); + fn from_meta(meta: MetaItem) -> Result<Self> { + let string = String::from_meta(meta)?; + if !is_valid_field_name(&string) { + return Err(meta.value_span().error("invalid form field name")); } - Ok(FormField { span: string.value_span, name: string.value }) + Ok(FormField { span: meta.value_span(), name: string }) } } diff --git a/core/codegen_next/src/http_codegen.rs b/core/codegen_next/src/http_codegen.rs @@ -1,7 +1,6 @@ -use syn; use quote::ToTokens; use proc_macro2::TokenStream as TokenStream2; -use derive_utils::{SpanWrapped, FromMeta, Result, ext::Split2}; +use derive_utils::{FromMeta, MetaItem, Result, ext::Split2}; use rocket_http as http; pub struct ContentType(http::ContentType); @@ -11,13 +10,13 @@ pub struct Status(http::Status); struct MediaType(http::MediaType); impl FromMeta for Status { - fn from_meta(meta: &syn::Meta) -> Result<Self> { - let num = <SpanWrapped<usize>>::from_meta(meta)?; - if num.value < 100 || num.value >= 600 { - return Err(num.value_span.error("status must be in range [100, 600)")); + fn from_meta(meta: MetaItem) -> Result<Self> { + let num = usize::from_meta(meta)?; + if num < 100 || num >= 600 { + return Err(meta.value_span().error("status must be in range [100, 600)")); } - Ok(Status(http::Status::raw(num.value as u16))) + Ok(Status(http::Status::raw(num as u16))) } } @@ -29,12 +28,10 @@ impl ToTokens for Status { } impl FromMeta for ContentType { - fn from_meta(meta: &syn::Meta) -> Result<Self> { - let s = <SpanWrapped<String>>::from_meta(meta)?; - let parsed = http::ContentType::parse_flexible(&s.value) - .ok_or_else(|| s.value_span.error("invalid or unknown content-type"))?; - - Ok(ContentType(parsed)) + fn from_meta(meta: MetaItem) -> Result<Self> { + http::ContentType::parse_flexible(&String::from_meta(meta)?) + .map(ContentType) + .ok_or(meta.value_span().error("invalid or unknown content-type")) } } diff --git a/core/codegen_next/src/lib.rs b/core/codegen_next/src/lib.rs @@ -10,7 +10,7 @@ extern crate rocket_http; mod derive; mod http_codegen; -crate use derive_utils::{syn, proc_macro2}; +crate use derive_utils::proc_macro2; use proc_macro::TokenStream; diff --git a/core/codegen_next/tests/ui-fail/from_form.rs b/core/codegen_next/tests/ui-fail/from_form.rs @@ -74,14 +74,14 @@ struct MyForm1 { #[derive(FromForm)] struct MyForm2 { #[form("blah")] - //~^ ERROR unexpected literal + //~^ ERROR expected key/value my_field: String, } #[derive(FromForm)] struct MyForm3 { #[form(123)] - //~^ ERROR unexpected literal + //~^ ERROR expected key/value my_field: String, } @@ -110,7 +110,7 @@ struct MyForm6 { #[derive(FromForm)] struct MyForm7 { #[form(field)] - //~^ ERROR malformed parameter + //~^ ERROR expected literal or key/value my_field: String, } diff --git a/core/codegen_next/tests/ui-fail/from_form.stderr b/core/codegen_next/tests/ui-fail/from_form.stderr @@ -133,20 +133,20 @@ note: error occurred while deriving `FromForm` 60 | #[derive(FromForm)] | ^^^^^^^^ -error: malformed attribute +error: malformed attribute: expected list --> $DIR/from_form.rs:69:7 | 69 | #[form] | ^^^^ | - = help: expected syntax: #[attr(key = value, ..)] + = help: expected syntax: #[form(key = value, ..)] note: error occurred while deriving `FromForm` --> $DIR/from_form.rs:67:10 | 67 | #[derive(FromForm)] | ^^^^^^^^ -error: unexpected literal +error: expected key/value pair --> $DIR/from_form.rs:76:12 | 76 | #[form("blah")] @@ -158,7 +158,7 @@ note: error occurred while deriving `FromForm` 74 | #[derive(FromForm)] | ^^^^^^^^ -error: unexpected literal +error: expected key/value pair --> $DIR/from_form.rs:83:12 | 83 | #[form(123)] @@ -170,7 +170,7 @@ note: error occurred while deriving `FromForm` 81 | #[derive(FromForm)] | ^^^^^^^^ -error: unexpected attribute parameter: beep +error: unexpected attribute parameter: `beep` --> $DIR/from_form.rs:90:12 | 90 | #[form(beep = "bop")] @@ -194,7 +194,7 @@ note: error occurred while deriving `FromForm` 95 | #[derive(FromForm)] | ^^^^^^^^ -error: invalid value: expected string +error: invalid value: expected string literal --> $DIR/from_form.rs:105:20 | 105 | #[form(field = true)] @@ -206,7 +206,7 @@ note: error occurred while deriving `FromForm` 103 | #[derive(FromForm)] | ^^^^^^^^ -error: malformed parameter: expected key/value pair +error: expected literal or key/value pair --> $DIR/from_form.rs:112:12 | 112 | #[form(field)] @@ -218,7 +218,7 @@ note: error occurred while deriving `FromForm` 110 | #[derive(FromForm)] | ^^^^^^^^ -error: invalid value: expected string +error: invalid value: expected string literal --> $DIR/from_form.rs:119:20 | 119 | #[form(field = 123)] diff --git a/core/codegen_next/tests/ui-fail/from_form_value.rs b/core/codegen_next/tests/ui-fail/from_form_value.rs @@ -40,6 +40,6 @@ enum Bar1 { #[derive(FromFormValue)] enum Bar2 { #[form(value)] - //~^ ERROR malformed parameter + //~^ ERROR expected literal or key/value A, } diff --git a/core/codegen_next/tests/ui-fail/from_form_value.stderr b/core/codegen_next/tests/ui-fail/from_form_value.stderr @@ -67,7 +67,7 @@ note: error occurred while deriving `FromFormValue` 27 | #[derive(FromFormValue)] | ^^^^^^^^^^^^^ -error: invalid value: expected string +error: invalid value: expected string literal --> $DIR/from_form_value.rs:35:20 | 35 | #[form(value = 123)] @@ -79,7 +79,7 @@ note: error occurred while deriving `FromFormValue` 33 | #[derive(FromFormValue)] | ^^^^^^^^^^^^^ -error: malformed parameter: expected key/value pair +error: expected literal or key/value pair --> $DIR/from_form_value.rs:42:12 | 42 | #[form(value)]