mirror of https://github.com/rwf2/Rocket.git
Migrate codegen to Rust 2018.
This commit is contained in:
parent
34cb1c14b8
commit
be784a7845
|
@ -10,6 +10,7 @@ readme = "../../README.md"
|
|||
keywords = ["rocket", "web", "framework", "code", "generation"]
|
||||
license = "MIT/Apache-2.0"
|
||||
build = "build.rs"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
//! Ensures Rocket isn't compiled with an incompatible version of Rust.
|
||||
|
||||
extern crate yansi;
|
||||
extern crate version_check;
|
||||
|
||||
use yansi::{Paint, Color::{Red, Yellow, Blue}};
|
||||
|
||||
// Specifies the minimum nightly version needed to compile Rocket.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use proc_macro::{TokenStream, Span};
|
||||
use devise::{syn, Spanned, Result, FromMeta};
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use crate::proc_macro2::TokenStream as TokenStream2;
|
||||
|
||||
use http_codegen::Status;
|
||||
use syn_ext::{syn_to_diag, IdentExt, ReturnTypeExt};
|
||||
use crate::http_codegen::Status;
|
||||
use crate::syn_ext::{syn_to_diag, IdentExt, ReturnTypeExt};
|
||||
use self::syn::{Attribute, parse::Parser};
|
||||
use {CATCH_FN_PREFIX, CATCH_STRUCT_PREFIX};
|
||||
use crate::{CATCH_FN_PREFIX, CATCH_STRUCT_PREFIX};
|
||||
|
||||
/// The raw, parsed `#[catch(code)]` attribute.
|
||||
#[derive(Debug, FromMeta)]
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use proc_macro::{TokenStream, Span};
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use crate::proc_macro2::TokenStream as TokenStream2;
|
||||
use devise::{syn, Spanned, SpanWrapped, Result, FromMeta, ext::TypeExt};
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use proc_macro_ext::{Diagnostics, StringLit};
|
||||
use syn_ext::{syn_to_diag, IdentExt};
|
||||
use crate::proc_macro_ext::{Diagnostics, StringLit};
|
||||
use crate::syn_ext::{syn_to_diag, IdentExt};
|
||||
use self::syn::{Attribute, parse::Parser};
|
||||
|
||||
use http_codegen::{Method, MediaType, RoutePath, DataSegment, Optional};
|
||||
use attribute::segments::{Source, Kind, Segment};
|
||||
use {ROUTE_FN_PREFIX, ROUTE_STRUCT_PREFIX, URI_MACRO_PREFIX, ROCKET_PARAM_PREFIX};
|
||||
use crate::http_codegen::{Method, MediaType, RoutePath, DataSegment, Optional};
|
||||
use crate::attribute::segments::{Source, Kind, Segment};
|
||||
use crate::{ROUTE_FN_PREFIX, ROUTE_STRUCT_PREFIX, URI_MACRO_PREFIX, ROCKET_PARAM_PREFIX};
|
||||
|
||||
/// The raw, parsed `#[route]` attribute.
|
||||
#[derive(Debug, FromMeta)]
|
||||
|
@ -425,7 +425,7 @@ fn complete_route(args: TokenStream2, input: TokenStream) -> Result<TokenStream>
|
|||
}
|
||||
|
||||
fn incomplete_route(
|
||||
method: ::http::Method,
|
||||
method: crate::http::Method,
|
||||
args: TokenStream2,
|
||||
input: TokenStream
|
||||
) -> Result<TokenStream> {
|
||||
|
@ -459,7 +459,7 @@ fn incomplete_route(
|
|||
codegen_route(parse_route(attribute, function)?)
|
||||
}
|
||||
|
||||
pub fn route_attribute<M: Into<Option<::http::Method>>>(
|
||||
pub fn route_attribute<M: Into<Option<crate::http::Method>>>(
|
||||
method: M,
|
||||
args: TokenStream,
|
||||
input: TokenStream
|
||||
|
|
|
@ -3,11 +3,11 @@ use std::hash::{Hash, Hasher};
|
|||
use devise::syn;
|
||||
use proc_macro::{Span, Diagnostic};
|
||||
|
||||
use http::uri::{UriPart, Path};
|
||||
use http::route::RouteSegment;
|
||||
use proc_macro_ext::{Diagnostics, StringLit, PResult, DResult};
|
||||
use crate::http::uri::{UriPart, Path};
|
||||
use crate::http::route::RouteSegment;
|
||||
use crate::proc_macro_ext::{Diagnostics, StringLit, PResult, DResult};
|
||||
|
||||
crate use http::route::{Error, Kind, Source};
|
||||
crate use crate::http::route::{Error, Kind, Source};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
crate struct Segment {
|
||||
|
@ -19,7 +19,7 @@ crate struct Segment {
|
|||
}
|
||||
|
||||
impl Segment {
|
||||
fn from<P: UriPart>(segment: RouteSegment<P>, span: Span) -> Segment {
|
||||
fn from<P: UriPart>(segment: RouteSegment<'_, P>, span: Span) -> Segment {
|
||||
let source = match P::DELIMITER {
|
||||
'/' => Source::Path,
|
||||
'&' => Source::Query,
|
||||
|
@ -31,7 +31,7 @@ impl Segment {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a syn::Ident> for Segment {
|
||||
impl From<&syn::Ident> for Segment {
|
||||
fn from(ident: &syn::Ident) -> Segment {
|
||||
Segment {
|
||||
kind: Kind::Static,
|
||||
|
@ -76,7 +76,7 @@ fn into_diagnostic(
|
|||
segment: &str, // The segment that failed.
|
||||
source: &str, // The haystack where `segment` can be found.
|
||||
span: Span, // The `Span` of `Source`.
|
||||
error: &Error, // The error.
|
||||
error: &Error<'_>, // The error.
|
||||
) -> Diagnostic {
|
||||
let seg_span = subspan(segment, source, span);
|
||||
match error {
|
||||
|
@ -116,7 +116,7 @@ fn into_diagnostic(
|
|||
}
|
||||
|
||||
crate fn parse_data_segment(segment: &str, span: Span) -> PResult<Segment> {
|
||||
<RouteSegment<Path>>::parse_one(segment)
|
||||
<RouteSegment<'_, Path>>::parse_one(segment)
|
||||
.map(|segment| {
|
||||
let mut seg = Segment::from(segment, span);
|
||||
seg.source = Source::Data;
|
||||
|
@ -133,7 +133,7 @@ crate fn parse_segments<P: UriPart>(
|
|||
let mut segments = vec![];
|
||||
let mut diags = Diagnostics::new();
|
||||
|
||||
for result in <RouteSegment<P>>::parse_many(string) {
|
||||
for result in <RouteSegment<'_, P>>::parse_many(string) {
|
||||
if let Err((segment_string, error)) = result {
|
||||
diags.push(into_diagnostic(segment_string, string, span, &error));
|
||||
if let Error::Trailing(..) = error {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use crate::proc_macro2::TokenStream as TokenStream2;
|
||||
|
||||
use devise::{syn, Spanned, Result};
|
||||
use self::syn::{Path, punctuated::Punctuated, parse::Parser, token::Comma};
|
||||
use syn_ext::{IdentExt, syn_to_diag};
|
||||
use {ROUTE_STRUCT_PREFIX, CATCH_STRUCT_PREFIX};
|
||||
use crate::syn_ext::{IdentExt, syn_to_diag};
|
||||
use crate::{ROUTE_STRUCT_PREFIX, CATCH_STRUCT_PREFIX};
|
||||
|
||||
mod uri;
|
||||
mod uri_parsing;
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
use std::fmt::Display;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use crate::proc_macro2::TokenStream as TokenStream2;
|
||||
|
||||
use devise::{syn, Result};
|
||||
use devise::syn::{Expr, Ident, Type, spanned::Spanned};
|
||||
use http::{uri::{Origin, Path, Query}, ext::IntoOwned};
|
||||
use http::route::{RouteSegment, Kind, Source};
|
||||
use crate::http::{uri::{Origin, Path, Query}, ext::IntoOwned};
|
||||
use crate::http::route::{RouteSegment, Kind, Source};
|
||||
|
||||
use http_codegen::Optional;
|
||||
use syn_ext::{IdentExt, syn_to_diag};
|
||||
use bang::{prefix_last_segment, uri_parsing::*};
|
||||
use crate::http_codegen::Optional;
|
||||
use crate::syn_ext::{IdentExt, syn_to_diag};
|
||||
use crate::bang::{prefix_last_segment, uri_parsing::*};
|
||||
|
||||
use URI_MACRO_PREFIX;
|
||||
use crate::URI_MACRO_PREFIX;
|
||||
|
||||
macro_rules! p {
|
||||
(@go $num:expr, $singular:expr, $plural:expr) => (
|
||||
|
@ -122,7 +122,7 @@ fn add_binding(to: &mut Vec<TokenStream2>, ident: &Ident, ty: &Type, expr: &Expr
|
|||
}
|
||||
|
||||
fn explode_path<'a, I: Iterator<Item = (&'a Ident, &'a Type, &'a Expr)>>(
|
||||
uri: &Origin,
|
||||
uri: &Origin<'_>,
|
||||
bindings: &mut Vec<TokenStream2>,
|
||||
mut items: I
|
||||
) -> TokenStream2 {
|
||||
|
@ -132,7 +132,7 @@ fn explode_path<'a, I: Iterator<Item = (&'a Ident, &'a Type, &'a Expr)>>(
|
|||
}
|
||||
|
||||
let uri_display = quote!(#uri_mod::UriDisplay<#uri_mod::Path>);
|
||||
let dyn_exprs = <RouteSegment<Path>>::parse(uri).map(|segment| {
|
||||
let dyn_exprs = <RouteSegment<'_, Path>>::parse(uri).map(|segment| {
|
||||
let segment = segment.expect("segment okay; prechecked on parse");
|
||||
match segment.kind {
|
||||
Kind::Static => {
|
||||
|
@ -151,7 +151,7 @@ fn explode_path<'a, I: Iterator<Item = (&'a Ident, &'a Type, &'a Expr)>>(
|
|||
}
|
||||
|
||||
fn explode_query<'a, I: Iterator<Item = (&'a Ident, &'a Type, &'a ArgExpr)>>(
|
||||
uri: &Origin,
|
||||
uri: &Origin<'_>,
|
||||
bindings: &mut Vec<TokenStream2>,
|
||||
mut items: I
|
||||
) -> Option<TokenStream2> {
|
||||
|
@ -162,7 +162,7 @@ fn explode_query<'a, I: Iterator<Item = (&'a Ident, &'a Type, &'a ArgExpr)>>(
|
|||
|
||||
let query_arg = quote!(#uri_mod::UriQueryArgument);
|
||||
let uri_display = quote!(#uri_mod::UriDisplay<#uri_mod::Query>);
|
||||
let dyn_exprs = <RouteSegment<Query>>::parse(uri)?.filter_map(|segment| {
|
||||
let dyn_exprs = <RouteSegment<'_, Query>>::parse(uri)?.filter_map(|segment| {
|
||||
let segment = segment.expect("segment okay; prechecked on parse");
|
||||
if segment.kind == Kind::Static {
|
||||
let string = &segment.string;
|
||||
|
|
|
@ -9,7 +9,7 @@ use self::syn::{Expr, Ident, LitStr, Path, Token, Type};
|
|||
use self::syn::parse::{self, Parse, ParseStream};
|
||||
use self::syn::punctuated::Punctuated;
|
||||
|
||||
use http::{uri::Origin, ext::IntoOwned};
|
||||
use crate::http::{uri::Origin, ext::IntoOwned};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -79,7 +79,7 @@ pub struct InternalUriParams {
|
|||
}
|
||||
|
||||
impl Parse for ArgExpr {
|
||||
fn parse(input: ParseStream) -> parse::Result<Self> {
|
||||
fn parse(input: ParseStream<'_>) -> parse::Result<Self> {
|
||||
if input.peek(Token![_]) {
|
||||
return Ok(ArgExpr::Ignored(input.parse::<Token![_]>()?));
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ impl Parse for ArgExpr {
|
|||
}
|
||||
|
||||
impl Parse for Arg {
|
||||
fn parse(input: ParseStream) -> parse::Result<Self> {
|
||||
fn parse(input: ParseStream<'_>) -> parse::Result<Self> {
|
||||
let has_key = input.peek2(Token![=]);
|
||||
if has_key {
|
||||
let ident = input.parse::<Ident>()?;
|
||||
|
@ -109,7 +109,7 @@ fn err<T, S: AsRef<str>>(span: Span, s: S) -> parse::Result<T> {
|
|||
|
||||
impl Parse for UriParams {
|
||||
// Parses the mount point, if any, route identifier, and arguments.
|
||||
fn parse(input: ParseStream) -> parse::Result<Self> {
|
||||
fn parse(input: ParseStream<'_>) -> parse::Result<Self> {
|
||||
if input.is_empty() {
|
||||
return Err(input.error("call to `uri!` cannot be empty"));
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ impl Parse for UriParams {
|
|||
}
|
||||
|
||||
impl Parse for FnArg {
|
||||
fn parse(input: ParseStream) -> parse::Result<FnArg> {
|
||||
fn parse(input: ParseStream<'_>) -> parse::Result<FnArg> {
|
||||
let ident = input.parse::<Ident>()?;
|
||||
input.parse::<Token![:]>()?;
|
||||
let mut ty = input.parse::<Type>()?;
|
||||
|
@ -186,7 +186,7 @@ impl Parse for FnArg {
|
|||
}
|
||||
|
||||
impl Parse for InternalUriParams {
|
||||
fn parse(input: ParseStream) -> parse::Result<InternalUriParams> {
|
||||
fn parse(input: ParseStream<'_>) -> parse::Result<InternalUriParams> {
|
||||
let route_uri_str = input.parse::<LitStr>()?;
|
||||
input.parse::<Token![,]>()?;
|
||||
|
||||
|
@ -215,7 +215,7 @@ impl InternalUriParams {
|
|||
.join(", ")
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> Validation {
|
||||
pub fn validate(&self) -> Validation<'_> {
|
||||
let args = &self.uri_params.arguments;
|
||||
match args {
|
||||
Args::Unnamed(inner) => {
|
||||
|
|
|
@ -23,7 +23,7 @@ fn is_valid_field_name(s: &str) -> bool {
|
|||
}
|
||||
|
||||
impl FromMeta for FormField {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
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"));
|
||||
|
@ -33,7 +33,7 @@ impl FromMeta for FormField {
|
|||
}
|
||||
}
|
||||
|
||||
fn validate_struct(gen: &DeriveGenerator, data: Struct) -> Result<()> {
|
||||
fn validate_struct(gen: &DeriveGenerator, data: Struct<'_>) -> Result<()> {
|
||||
if data.fields().is_empty() {
|
||||
return Err(gen.input.span().error("at least one field is required"));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use proc_macro::TokenStream;
|
|||
use devise::{*, ext::TypeExt};
|
||||
use devise::proc_macro2::TokenStream as TokenStream2;
|
||||
|
||||
use http_codegen::{ContentType, Status};
|
||||
use crate::http_codegen::{ContentType, Status};
|
||||
|
||||
#[derive(Default, FromMeta)]
|
||||
struct ItemAttr {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use proc_macro::{Span, TokenStream};
|
||||
use devise::*;
|
||||
|
||||
use derive::from_form::Form;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use crate::derive::from_form::Form;
|
||||
use crate::proc_macro2::TokenStream as TokenStream2;
|
||||
|
||||
const NO_EMPTY_FIELDS: &str = "fieldless structs or variants are not supported";
|
||||
const NO_NULLARY: &str = "nullary items are not supported";
|
||||
|
@ -10,7 +10,7 @@ const NO_EMPTY_ENUMS: &str = "empty enums are not supported";
|
|||
const ONLY_ONE_UNNAMED: &str = "tuple structs or variants must have exactly one field";
|
||||
const EXACTLY_ONE_FIELD: &str = "struct must have exactly one field";
|
||||
|
||||
fn validate_fields(fields: Fields, parent_span: Span) -> Result<()> {
|
||||
fn validate_fields(fields: Fields<'_>, parent_span: Span) -> Result<()> {
|
||||
if fields.count() == 0 {
|
||||
return Err(parent_span.error(NO_EMPTY_FIELDS))
|
||||
} else if fields.are_unnamed() && fields.count() > 1 {
|
||||
|
@ -22,11 +22,11 @@ fn validate_fields(fields: Fields, parent_span: Span) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_struct(gen: &DeriveGenerator, data: Struct) -> Result<()> {
|
||||
fn validate_struct(gen: &DeriveGenerator, data: Struct<'_>) -> Result<()> {
|
||||
validate_fields(data.fields(), gen.input.span())
|
||||
}
|
||||
|
||||
fn validate_enum(gen: &DeriveGenerator, data: Enum) -> Result<()> {
|
||||
fn validate_enum(gen: &DeriveGenerator, data: Enum<'_>) -> Result<()> {
|
||||
if data.variants().count() == 0 {
|
||||
return Err(gen.input.span().error(NO_EMPTY_ENUMS));
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use quote::ToTokens;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use crate::proc_macro2::TokenStream as TokenStream2;
|
||||
use devise::{FromMeta, MetaItem, Result, ext::Split2};
|
||||
use http::{self, ext::IntoOwned};
|
||||
use http::uri::{Path, Query};
|
||||
use attribute::segments::{parse_segments, parse_data_segment, Segment, Kind};
|
||||
use crate::http::{self, ext::IntoOwned};
|
||||
use crate::http::uri::{Path, Query};
|
||||
use crate::attribute::segments::{parse_segments, parse_data_segment, Segment, Kind};
|
||||
|
||||
use proc_macro_ext::StringLit;
|
||||
use crate::proc_macro_ext::StringLit;
|
||||
|
||||
#[derive(Debug)]
|
||||
crate struct ContentType(crate http::ContentType);
|
||||
|
@ -29,7 +29,7 @@ crate struct DataSegment(crate Segment);
|
|||
crate struct Optional<T>(crate Option<T>);
|
||||
|
||||
impl FromMeta for StringLit {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
fn from_meta(meta: MetaItem<'_>) -> Result<Self> {
|
||||
Ok(StringLit::new(String::from_meta(meta)?, meta.value_span()))
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ crate struct RoutePath {
|
|||
}
|
||||
|
||||
impl FromMeta for Status {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
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, 599]"));
|
||||
|
@ -60,7 +60,7 @@ impl ToTokens for Status {
|
|||
}
|
||||
|
||||
impl FromMeta for ContentType {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
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"))
|
||||
|
@ -76,7 +76,7 @@ impl ToTokens for ContentType {
|
|||
}
|
||||
|
||||
impl FromMeta for MediaType {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
fn from_meta(meta: MetaItem<'_>) -> Result<Self> {
|
||||
let mt = http::MediaType::parse_flexible(&String::from_meta(meta)?)
|
||||
.ok_or(meta.value_span().error("invalid or unknown media type"))?;
|
||||
|
||||
|
@ -126,7 +126,7 @@ const VALID_METHODS: &[http::Method] = &[
|
|||
];
|
||||
|
||||
impl FromMeta for Method {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
fn from_meta(meta: MetaItem<'_>) -> Result<Self> {
|
||||
let span = meta.value_span();
|
||||
let help_text = format!("method must be one of: {}", VALID_METHODS_STR);
|
||||
|
||||
|
@ -166,7 +166,7 @@ impl ToTokens for Method {
|
|||
}
|
||||
|
||||
impl FromMeta for Origin {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
fn from_meta(meta: MetaItem<'_>) -> Result<Self> {
|
||||
let string = StringLit::from_meta(meta)?;
|
||||
|
||||
let uri = http::uri::Origin::parse_route(&string)
|
||||
|
@ -190,7 +190,7 @@ impl FromMeta for Origin {
|
|||
}
|
||||
|
||||
impl FromMeta for DataSegment {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
fn from_meta(meta: MetaItem<'_>) -> Result<Self> {
|
||||
let string = StringLit::from_meta(meta)?;
|
||||
let span = string.subspan(1..(string.len() + 1));
|
||||
|
||||
|
@ -205,7 +205,7 @@ impl FromMeta for DataSegment {
|
|||
}
|
||||
|
||||
impl FromMeta for RoutePath {
|
||||
fn from_meta(meta: MetaItem) -> Result<Self> {
|
||||
fn from_meta(meta: MetaItem<'_>) -> Result<Self> {
|
||||
let (origin, string) = (Origin::from_meta(meta)?, StringLit::from_meta(meta)?);
|
||||
let path_span = string.subspan(1..origin.0.path().len() + 1);
|
||||
let path = parse_segments::<Path>(origin.0.path(), path_span);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#![doc(html_favicon_url = "https://rocket.rs/v0.5/images/favicon.ico")]
|
||||
#![doc(html_logo_url = "https://rocket.rs/v0.5/images/logo-boxed.png")]
|
||||
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
//! # Rocket - Code Generation
|
||||
//!
|
||||
//! This crate implements the code generation portions of Rocket. This includes
|
||||
|
@ -58,10 +60,9 @@
|
|||
//! ```
|
||||
|
||||
#[macro_use] extern crate quote;
|
||||
extern crate devise;
|
||||
extern crate proc_macro;
|
||||
extern crate rocket_http as http;
|
||||
extern crate indexmap;
|
||||
|
||||
use rocket_http as http;
|
||||
|
||||
macro_rules! define {
|
||||
($val:path as $v:ident) => (#[allow(non_snake_case)] let $v = quote!($val););
|
||||
|
@ -97,7 +98,7 @@ mod bang;
|
|||
mod http_codegen;
|
||||
mod syn_ext;
|
||||
|
||||
use http::Method;
|
||||
use crate::http::Method;
|
||||
use proc_macro::TokenStream;
|
||||
crate use devise::proc_macro2;
|
||||
|
||||
|
@ -111,8 +112,8 @@ crate static ROCKET_PARAM_PREFIX: &str = "__rocket_param_";
|
|||
macro_rules! emit {
|
||||
($tokens:expr) => ({
|
||||
let tokens = $tokens;
|
||||
if ::std::env::var_os("ROCKET_CODEGEN_DEBUG").is_some() {
|
||||
::proc_macro::Span::call_site()
|
||||
if std::env::var_os("ROCKET_CODEGEN_DEBUG").is_some() {
|
||||
proc_macro::Span::call_site()
|
||||
.note("emitting Rocket code generation debug output")
|
||||
.note(tokens.to_string())
|
||||
.emit()
|
||||
|
|
|
@ -2,9 +2,9 @@ use std::ops::RangeBounds;
|
|||
|
||||
use proc_macro::{Span, Diagnostic, Literal};
|
||||
|
||||
pub type PResult<T> = ::std::result::Result<T, Diagnostic>;
|
||||
pub type PResult<T> = std::result::Result<T, Diagnostic>;
|
||||
|
||||
pub type DResult<T> = ::std::result::Result<T, Diagnostics>;
|
||||
pub type DResult<T> = std::result::Result<T, Diagnostics>;
|
||||
|
||||
// An experiment.
|
||||
pub struct Diagnostics(Vec<Diagnostic>);
|
||||
|
|
|
@ -103,7 +103,7 @@ fn base_conditions() {
|
|||
"checkbox=off", "textarea=", "select=a", "radio=c",
|
||||
].join("&");
|
||||
|
||||
let input: Option<FormInput> = strict(&form_string).ok();
|
||||
let input: Option<FormInput<'_>> = strict(&form_string).ok();
|
||||
assert_eq!(input, Some(FormInput {
|
||||
checkbox: false,
|
||||
number: 10,
|
||||
|
@ -114,26 +114,26 @@ fn base_conditions() {
|
|||
}));
|
||||
|
||||
// Argument not in string with default in form.
|
||||
let default: Option<DefaultInput> = strict("").ok();
|
||||
let default: Option<DefaultInput<'_>> = strict("").ok();
|
||||
assert_eq!(default, Some(DefaultInput {
|
||||
arg: None
|
||||
}));
|
||||
|
||||
// Ensure _method can be captured if desired.
|
||||
let manual: Option<ManualMethod> = strict("_method=put&done=true").ok();
|
||||
let manual: Option<ManualMethod<'_>> = strict("_method=put&done=true").ok();
|
||||
assert_eq!(manual, Some(ManualMethod {
|
||||
_method: Some("put".into()),
|
||||
done: true
|
||||
}));
|
||||
|
||||
let manual: Option<ManualMethod> = lenient("_method=put&done=true").ok();
|
||||
let manual: Option<ManualMethod<'_>> = lenient("_method=put&done=true").ok();
|
||||
assert_eq!(manual, Some(ManualMethod {
|
||||
_method: Some("put".into()),
|
||||
done: true
|
||||
}));
|
||||
|
||||
// And ignored when not present.
|
||||
let manual: Option<ManualMethod> = strict("done=true").ok();
|
||||
let manual: Option<ManualMethod<'_>> = strict("done=true").ok();
|
||||
assert_eq!(manual, Some(ManualMethod {
|
||||
_method: None,
|
||||
done: true
|
||||
|
@ -146,14 +146,14 @@ fn base_conditions() {
|
|||
}));
|
||||
|
||||
// Check that a `bool` value that isn't in the form is marked as `false`.
|
||||
let manual: Option<UnpresentCheckboxTwo> = strict("something=hello").ok();
|
||||
let manual: Option<UnpresentCheckboxTwo<'_>> = strict("something=hello").ok();
|
||||
assert_eq!(manual, Some(UnpresentCheckboxTwo {
|
||||
checkbox: false,
|
||||
something: "hello".into()
|
||||
}));
|
||||
|
||||
// Check that a structure with one field `v` parses correctly.
|
||||
let manual: Option<FieldNamedV> = strict("v=abc").ok();
|
||||
let manual: Option<FieldNamedV<'_>> = strict("v=abc").ok();
|
||||
assert_eq!(manual, Some(FieldNamedV {
|
||||
v: "abc".into()
|
||||
}));
|
||||
|
@ -163,33 +163,33 @@ fn base_conditions() {
|
|||
#[test]
|
||||
fn lenient_parsing() {
|
||||
// Check that a structure with one field `v` parses correctly (lenient).
|
||||
let manual: Option<FieldNamedV> = lenient("v=abc").ok();
|
||||
let manual: Option<FieldNamedV<'_>> = lenient("v=abc").ok();
|
||||
assert_eq!(manual, Some(FieldNamedV { v: "abc".into() }));
|
||||
|
||||
let manual: Option<FieldNamedV> = lenient("v=abc&a=123").ok();
|
||||
let manual: Option<FieldNamedV<'_>> = lenient("v=abc&a=123").ok();
|
||||
assert_eq!(manual, Some(FieldNamedV { v: "abc".into() }));
|
||||
|
||||
let manual: Option<FieldNamedV> = lenient("c=abcddef&v=abc&a=123").ok();
|
||||
let manual: Option<FieldNamedV<'_>> = lenient("c=abcddef&v=abc&a=123").ok();
|
||||
assert_eq!(manual, Some(FieldNamedV { v: "abc".into() }));
|
||||
|
||||
// Check default values (bool) with lenient parsing.
|
||||
let manual: Option<UnpresentCheckboxTwo> = lenient("something=hello").ok();
|
||||
let manual: Option<UnpresentCheckboxTwo<'_>> = lenient("something=hello").ok();
|
||||
assert_eq!(manual, Some(UnpresentCheckboxTwo {
|
||||
checkbox: false,
|
||||
something: "hello".into()
|
||||
}));
|
||||
|
||||
let manual: Option<UnpresentCheckboxTwo> = lenient("hi=hi&something=hello").ok();
|
||||
let manual: Option<UnpresentCheckboxTwo<'_>> = lenient("hi=hi&something=hello").ok();
|
||||
assert_eq!(manual, Some(UnpresentCheckboxTwo {
|
||||
checkbox: false,
|
||||
something: "hello".into()
|
||||
}));
|
||||
|
||||
// Check that a missing field doesn't parse, even leniently.
|
||||
let manual: Option<FieldNamedV> = lenient("a=abc").ok();
|
||||
let manual: Option<FieldNamedV<'_>> = lenient("a=abc").ok();
|
||||
assert!(manual.is_none());
|
||||
|
||||
let manual: Option<FieldNamedV> = lenient("_method=abc").ok();
|
||||
let manual: Option<FieldNamedV<'_>> = lenient("_method=abc").ok();
|
||||
assert!(manual.is_none());
|
||||
}
|
||||
|
||||
|
@ -257,19 +257,19 @@ fn generics() {
|
|||
"string=hello", "other=00128"
|
||||
].join("&");
|
||||
|
||||
let form: Option<YetOneMore<usize>> = strict(&form_string).ok();
|
||||
let form: Option<YetOneMore<'_, usize>> = strict(&form_string).ok();
|
||||
assert_eq!(form, Some(YetOneMore {
|
||||
string: "hello".into(),
|
||||
other: 128,
|
||||
}));
|
||||
|
||||
let form: Option<YetOneMore<u8>> = strict(&form_string).ok();
|
||||
let form: Option<YetOneMore<'_, u8>> = strict(&form_string).ok();
|
||||
assert_eq!(form, Some(YetOneMore {
|
||||
string: "hello".into(),
|
||||
other: 128,
|
||||
}));
|
||||
|
||||
let form: Option<YetOneMore<i8>> = strict(&form_string).ok();
|
||||
let form: Option<YetOneMore<'_, i8>> = strict(&form_string).ok();
|
||||
assert!(form.is_none());
|
||||
|
||||
let form_string = &[
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
extern crate rocket;
|
||||
|
||||
use rocket::request::FromFormValue;
|
||||
|
||||
macro_rules! assert_parse {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::local::Client;
|
||||
use rocket::response::Responder;
|
||||
use rocket::http::{Status, ContentType, Cookie};
|
||||
|
@ -14,12 +12,12 @@ pub enum Foo<'r> {
|
|||
#[response(status = 404, content_type = "html")]
|
||||
Third {
|
||||
responder: &'r str,
|
||||
ct: ::rocket::http::ContentType,
|
||||
ct: rocket::http::ContentType,
|
||||
},
|
||||
#[response(status = 105)]
|
||||
Fourth {
|
||||
string: &'r str,
|
||||
ct: ::rocket::http::ContentType,
|
||||
ct: rocket::http::ContentType,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ struct Simple(String);
|
|||
impl FromDataSimple for Simple {
|
||||
type Error = ();
|
||||
|
||||
fn from_data(_: &Request, data: Data) -> data::Outcome<Self, ()> {
|
||||
fn from_data(_: &Request<'_>, data: Data) -> data::Outcome<Self, ()> {
|
||||
let mut string = String::new();
|
||||
if let Err(_) = data.open().take(64).read_to_string(&mut string) {
|
||||
return Failure((Status::InternalServerError, ()));
|
||||
|
@ -33,7 +33,7 @@ impl FromDataSimple for Simple {
|
|||
}
|
||||
|
||||
#[post("/f", data = "<form>")]
|
||||
fn form(form: Form<Inner>) -> String { form.field.url_decode_lossy() }
|
||||
fn form(form: Form<Inner<'_>>) -> String { form.field.url_decode_lossy() }
|
||||
|
||||
#[post("/s", data = "<simple>")]
|
||||
fn simple(simple: Simple) -> String { simple.0 }
|
||||
|
|
|
@ -28,7 +28,7 @@ struct Simple(String);
|
|||
impl FromDataSimple for Simple {
|
||||
type Error = ();
|
||||
|
||||
fn from_data(_: &Request, data: Data) -> data::Outcome<Self, ()> {
|
||||
fn from_data(_: &Request<'_>, data: Data) -> data::Outcome<Self, ()> {
|
||||
use std::io::Read;
|
||||
let mut string = String::new();
|
||||
data.open().take(64).read_to_string(&mut string).unwrap();
|
||||
|
@ -41,7 +41,7 @@ fn post1(
|
|||
sky: usize,
|
||||
name: &RawStr,
|
||||
a: String,
|
||||
query: Form<Inner>,
|
||||
query: Form<Inner<'_>>,
|
||||
path: PathBuf,
|
||||
simple: Simple,
|
||||
) -> String {
|
||||
|
@ -58,7 +58,7 @@ fn post2(
|
|||
sky: usize,
|
||||
name: &RawStr,
|
||||
a: String,
|
||||
query: Form<Inner>,
|
||||
query: Form<Inner<'_>>,
|
||||
path: PathBuf,
|
||||
simple: Simple,
|
||||
) -> String {
|
||||
|
|
|
@ -52,13 +52,13 @@ fn simple4_flipped(name: String, id: i32) { }
|
|||
fn unused_param(used: i32, _unused: i32) { }
|
||||
|
||||
#[post("/<id>")]
|
||||
fn guard_1(cookies: Cookies, id: i32) { }
|
||||
fn guard_1(cookies: Cookies<'_>, id: i32) { }
|
||||
|
||||
#[post("/<id>/<name>")]
|
||||
fn guard_2(name: String, cookies: Cookies, id: i32) { }
|
||||
fn guard_2(name: String, cookies: Cookies<'_>, id: i32) { }
|
||||
|
||||
#[post("/a/<id>/hi/<name>/hey")]
|
||||
fn guard_3(id: i32, name: String, cookies: Cookies) { }
|
||||
fn guard_3(id: i32, name: String, cookies: Cookies<'_>) { }
|
||||
|
||||
#[post("/<id>", data = "<form>")]
|
||||
fn no_uri_display_okay(id: i32, form: Form<Second>) { }
|
||||
|
@ -70,7 +70,7 @@ fn complex<'r>(
|
|||
query: Form<User<'r>>,
|
||||
user: Form<User<'r>>,
|
||||
bar: &RawStr,
|
||||
cookies: Cookies
|
||||
cookies: Cookies<'_>
|
||||
) { }
|
||||
|
||||
#[post("/a/<path..>")]
|
||||
|
@ -80,7 +80,7 @@ fn segments(path: PathBuf) { }
|
|||
fn param_and_segments(path: PathBuf, id: usize) { }
|
||||
|
||||
#[post("/a/<id>/then/<path..>")]
|
||||
fn guarded_segments(cookies: Cookies, path: PathBuf, id: usize) { }
|
||||
fn guarded_segments(cookies: Cookies<'_>, path: PathBuf, id: usize) { }
|
||||
|
||||
macro assert_uri_eq($($uri:expr => $expected:expr,)+) {
|
||||
$(assert_eq!($uri, Origin::parse($expected).expect("valid origin URI"));)+
|
||||
|
@ -332,9 +332,9 @@ mod typed_uris {
|
|||
fn check_simple_scoped() {
|
||||
assert_uri_eq! {
|
||||
uri!(simple: id = 100) => "/typed_uris/100",
|
||||
uri!(::simple: id = 100) => "/100",
|
||||
uri!("/mount", ::simple: id = 100) => "/mount/100",
|
||||
uri!(::simple2: id = 100, name = "hello") => "/100/hello",
|
||||
uri!(crate::simple: id = 100) => "/100",
|
||||
uri!("/mount", crate::simple: id = 100) => "/mount/100",
|
||||
uri!(crate::simple2: id = 100, name = "hello") => "/100/hello",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ mod typed_uris {
|
|||
fn check_deep_scoped() {
|
||||
assert_uri_eq! {
|
||||
uri!(super::simple: id = 100) => "/typed_uris/100",
|
||||
uri!(::simple: id = 100) => "/100",
|
||||
uri!(crate::simple: id = 100) => "/100",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ fn optionals(
|
|||
foo: Option<usize>,
|
||||
bar: Result<String, &RawStr>,
|
||||
q1: Result<usize, &RawStr>,
|
||||
rest: Option<Form<Third>>
|
||||
rest: Option<Form<Third<'_>>>
|
||||
) { }
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -27,7 +27,7 @@ struct Thing3 {
|
|||
#[derive(Responder)]
|
||||
struct Thing4 {
|
||||
thing: String,
|
||||
other: ::rocket::http::ContentType,
|
||||
other: rocket::http::ContentType,
|
||||
then: String,
|
||||
//~^ ERROR Header
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use rocket::http::uri::{UriDisplay, Query, Path};
|
|||
|
||||
macro_rules! assert_uri_display_query {
|
||||
($v:expr, $s:expr) => (
|
||||
let uri_string = format!("{}", &$v as &UriDisplay<Query>);
|
||||
let uri_string = format!("{}", &$v as &dyn UriDisplay<Query>);
|
||||
assert_eq!(uri_string, $s);
|
||||
)
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ fn uri_display_bam() {
|
|||
|
||||
macro_rules! assert_uri_display_path {
|
||||
($v:expr, $s:expr) => (
|
||||
let uri_string = format!("{}", &$v as &UriDisplay<Path>);
|
||||
let uri_string = format!("{}", &$v as &dyn UriDisplay<Path>);
|
||||
assert_eq!(uri_string, $s);
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue