From be784a7845d7043e2f80dbb710d3ef4b96fee1d8 Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Wed, 12 Jun 2019 18:59:25 -0700 Subject: [PATCH] Migrate codegen to Rust 2018. --- core/codegen/Cargo.toml | 1 + core/codegen/build.rs | 3 -- core/codegen/src/attribute/catch.rs | 8 ++--- core/codegen/src/attribute/route.rs | 16 ++++----- core/codegen/src/attribute/segments.rs | 18 +++++----- core/codegen/src/bang/mod.rs | 6 ++-- core/codegen/src/bang/uri.rs | 22 ++++++------ core/codegen/src/bang/uri_parsing.rs | 14 ++++---- core/codegen/src/derive/from_form.rs | 4 +-- core/codegen/src/derive/responder.rs | 2 +- core/codegen/src/derive/uri_display.rs | 10 +++--- core/codegen/src/http_codegen.rs | 26 +++++++------- core/codegen/src/lib.rs | 13 +++---- core/codegen/src/proc_macro_ext.rs | 4 +-- core/codegen/tests/from_form.rs | 34 +++++++++---------- core/codegen/tests/from_form_value.rs | 2 -- core/codegen/tests/responder.rs | 6 ++-- core/codegen/tests/route-data.rs | 4 +-- core/codegen/tests/route.rs | 6 ++-- core/codegen/tests/typed-uris.rs | 20 +++++------ core/codegen/tests/ui-fail/responder-types.rs | 2 +- core/codegen/tests/uri_display.rs | 4 +-- 22 files changed, 110 insertions(+), 115 deletions(-) diff --git a/core/codegen/Cargo.toml b/core/codegen/Cargo.toml index a5a890556a..9384466ef3 100644 --- a/core/codegen/Cargo.toml +++ b/core/codegen/Cargo.toml @@ -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 diff --git a/core/codegen/build.rs b/core/codegen/build.rs index 1f5c8131c1..75e4a537de 100644 --- a/core/codegen/build.rs +++ b/core/codegen/build.rs @@ -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. diff --git a/core/codegen/src/attribute/catch.rs b/core/codegen/src/attribute/catch.rs index 9a32ca12d1..372620d955 100644 --- a/core/codegen/src/attribute/catch.rs +++ b/core/codegen/src/attribute/catch.rs @@ -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)] diff --git a/core/codegen/src/attribute/route.rs b/core/codegen/src/attribute/route.rs index 638ab0310f..7aa8d945a0 100644 --- a/core/codegen/src/attribute/route.rs +++ b/core/codegen/src/attribute/route.rs @@ -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 } fn incomplete_route( - method: ::http::Method, + method: crate::http::Method, args: TokenStream2, input: TokenStream ) -> Result { @@ -459,7 +459,7 @@ fn incomplete_route( codegen_route(parse_route(attribute, function)?) } -pub fn route_attribute>>( +pub fn route_attribute>>( method: M, args: TokenStream, input: TokenStream diff --git a/core/codegen/src/attribute/segments.rs b/core/codegen/src/attribute/segments.rs index 4d1bb43e52..716ea0949e 100644 --- a/core/codegen/src/attribute/segments.rs +++ b/core/codegen/src/attribute/segments.rs @@ -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(segment: RouteSegment

, span: Span) -> Segment { + fn from(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 { - >::parse_one(segment) + >::parse_one(segment) .map(|segment| { let mut seg = Segment::from(segment, span); seg.source = Source::Data; @@ -133,7 +133,7 @@ crate fn parse_segments( let mut segments = vec![]; let mut diags = Diagnostics::new(); - for result in >::parse_many(string) { + for result in >::parse_many(string) { if let Err((segment_string, error)) = result { diags.push(into_diagnostic(segment_string, string, span, &error)); if let Error::Trailing(..) = error { diff --git a/core/codegen/src/bang/mod.rs b/core/codegen/src/bang/mod.rs index a0a4eab485..a93785ce77 100644 --- a/core/codegen/src/bang/mod.rs +++ b/core/codegen/src/bang/mod.rs @@ -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; diff --git a/core/codegen/src/bang/uri.rs b/core/codegen/src/bang/uri.rs index ac890d66e6..8b0c7fc6c1 100644 --- a/core/codegen/src/bang/uri.rs +++ b/core/codegen/src/bang/uri.rs @@ -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, ident: &Ident, ty: &Type, expr: &Expr } fn explode_path<'a, I: Iterator>( - uri: &Origin, + uri: &Origin<'_>, bindings: &mut Vec, mut items: I ) -> TokenStream2 { @@ -132,7 +132,7 @@ fn explode_path<'a, I: Iterator>( } let uri_display = quote!(#uri_mod::UriDisplay<#uri_mod::Path>); - let dyn_exprs = >::parse(uri).map(|segment| { + let dyn_exprs = >::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>( } fn explode_query<'a, I: Iterator>( - uri: &Origin, + uri: &Origin<'_>, bindings: &mut Vec, mut items: I ) -> Option { @@ -162,7 +162,7 @@ fn explode_query<'a, I: Iterator>( let query_arg = quote!(#uri_mod::UriQueryArgument); let uri_display = quote!(#uri_mod::UriDisplay<#uri_mod::Query>); - let dyn_exprs = >::parse(uri)?.filter_map(|segment| { + let dyn_exprs = >::parse(uri)?.filter_map(|segment| { let segment = segment.expect("segment okay; prechecked on parse"); if segment.kind == Kind::Static { let string = &segment.string; diff --git a/core/codegen/src/bang/uri_parsing.rs b/core/codegen/src/bang/uri_parsing.rs index ddb765dead..ab6edf8be7 100644 --- a/core/codegen/src/bang/uri_parsing.rs +++ b/core/codegen/src/bang/uri_parsing.rs @@ -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 { + fn parse(input: ParseStream<'_>) -> parse::Result { if input.peek(Token![_]) { return Ok(ArgExpr::Ignored(input.parse::()?)); } @@ -89,7 +89,7 @@ impl Parse for ArgExpr { } impl Parse for Arg { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { let has_key = input.peek2(Token![=]); if has_key { let ident = input.parse::()?; @@ -109,7 +109,7 @@ fn err>(span: Span, s: S) -> parse::Result { impl Parse for UriParams { // Parses the mount point, if any, route identifier, and arguments. - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { 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 { + fn parse(input: ParseStream<'_>) -> parse::Result { let ident = input.parse::()?; input.parse::()?; let mut ty = input.parse::()?; @@ -186,7 +186,7 @@ impl Parse for FnArg { } impl Parse for InternalUriParams { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { let route_uri_str = input.parse::()?; input.parse::()?; @@ -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) => { diff --git a/core/codegen/src/derive/from_form.rs b/core/codegen/src/derive/from_form.rs index 27b84875ee..5a6835323e 100644 --- a/core/codegen/src/derive/from_form.rs +++ b/core/codegen/src/derive/from_form.rs @@ -23,7 +23,7 @@ fn is_valid_field_name(s: &str) -> bool { } impl FromMeta for FormField { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { 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")); } diff --git a/core/codegen/src/derive/responder.rs b/core/codegen/src/derive/responder.rs index e2c87a9cf4..4e181209d2 100644 --- a/core/codegen/src/derive/responder.rs +++ b/core/codegen/src/derive/responder.rs @@ -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 { diff --git a/core/codegen/src/derive/uri_display.rs b/core/codegen/src/derive/uri_display.rs index 4c59213365..aaf0fb9499 100644 --- a/core/codegen/src/derive/uri_display.rs +++ b/core/codegen/src/derive/uri_display.rs @@ -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)); } diff --git a/core/codegen/src/http_codegen.rs b/core/codegen/src/http_codegen.rs index 1d44508a8c..782394282c 100644 --- a/core/codegen/src/http_codegen.rs +++ b/core/codegen/src/http_codegen.rs @@ -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(crate Option); impl FromMeta for StringLit { - fn from_meta(meta: MetaItem) -> Result { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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 { + fn from_meta(meta: MetaItem<'_>) -> Result { 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::(origin.0.path(), path_span); diff --git a/core/codegen/src/lib.rs b/core/codegen/src/lib.rs index a8657877c6..e7fc207c6b 100644 --- a/core/codegen/src/lib.rs +++ b/core/codegen/src/lib.rs @@ -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() diff --git a/core/codegen/src/proc_macro_ext.rs b/core/codegen/src/proc_macro_ext.rs index 6d4e0b03b3..e084962eed 100644 --- a/core/codegen/src/proc_macro_ext.rs +++ b/core/codegen/src/proc_macro_ext.rs @@ -2,9 +2,9 @@ use std::ops::RangeBounds; use proc_macro::{Span, Diagnostic, Literal}; -pub type PResult = ::std::result::Result; +pub type PResult = std::result::Result; -pub type DResult = ::std::result::Result; +pub type DResult = std::result::Result; // An experiment. pub struct Diagnostics(Vec); diff --git a/core/codegen/tests/from_form.rs b/core/codegen/tests/from_form.rs index 72c7d156a9..0530e005af 100644 --- a/core/codegen/tests/from_form.rs +++ b/core/codegen/tests/from_form.rs @@ -103,7 +103,7 @@ fn base_conditions() { "checkbox=off", "textarea=", "select=a", "radio=c", ].join("&"); - let input: Option = strict(&form_string).ok(); + let input: Option> = 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 = strict("").ok(); + let default: Option> = strict("").ok(); assert_eq!(default, Some(DefaultInput { arg: None })); // Ensure _method can be captured if desired. - let manual: Option = strict("_method=put&done=true").ok(); + let manual: Option> = strict("_method=put&done=true").ok(); assert_eq!(manual, Some(ManualMethod { _method: Some("put".into()), done: true })); - let manual: Option = lenient("_method=put&done=true").ok(); + let manual: Option> = 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 = strict("done=true").ok(); + let manual: Option> = 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 = strict("something=hello").ok(); + let manual: Option> = 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 = strict("v=abc").ok(); + let manual: Option> = 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 = lenient("v=abc").ok(); + let manual: Option> = lenient("v=abc").ok(); assert_eq!(manual, Some(FieldNamedV { v: "abc".into() })); - let manual: Option = lenient("v=abc&a=123").ok(); + let manual: Option> = lenient("v=abc&a=123").ok(); assert_eq!(manual, Some(FieldNamedV { v: "abc".into() })); - let manual: Option = lenient("c=abcddef&v=abc&a=123").ok(); + let manual: Option> = 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 = lenient("something=hello").ok(); + let manual: Option> = lenient("something=hello").ok(); assert_eq!(manual, Some(UnpresentCheckboxTwo { checkbox: false, something: "hello".into() })); - let manual: Option = lenient("hi=hi&something=hello").ok(); + let manual: Option> = 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 = lenient("a=abc").ok(); + let manual: Option> = lenient("a=abc").ok(); assert!(manual.is_none()); - let manual: Option = lenient("_method=abc").ok(); + let manual: Option> = lenient("_method=abc").ok(); assert!(manual.is_none()); } @@ -257,19 +257,19 @@ fn generics() { "string=hello", "other=00128" ].join("&"); - let form: Option> = strict(&form_string).ok(); + let form: Option> = strict(&form_string).ok(); assert_eq!(form, Some(YetOneMore { string: "hello".into(), other: 128, })); - let form: Option> = strict(&form_string).ok(); + let form: Option> = strict(&form_string).ok(); assert_eq!(form, Some(YetOneMore { string: "hello".into(), other: 128, })); - let form: Option> = strict(&form_string).ok(); + let form: Option> = strict(&form_string).ok(); assert!(form.is_none()); let form_string = &[ diff --git a/core/codegen/tests/from_form_value.rs b/core/codegen/tests/from_form_value.rs index 0d81ad8a53..b21300a604 100644 --- a/core/codegen/tests/from_form_value.rs +++ b/core/codegen/tests/from_form_value.rs @@ -1,5 +1,3 @@ -extern crate rocket; - use rocket::request::FromFormValue; macro_rules! assert_parse { diff --git a/core/codegen/tests/responder.rs b/core/codegen/tests/responder.rs index f7c8233804..6c7d1d1ac2 100644 --- a/core/codegen/tests/responder.rs +++ b/core/codegen/tests/responder.rs @@ -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, }, } diff --git a/core/codegen/tests/route-data.rs b/core/codegen/tests/route-data.rs index 640e0ada3a..168de24b71 100644 --- a/core/codegen/tests/route-data.rs +++ b/core/codegen/tests/route-data.rs @@ -22,7 +22,7 @@ struct Simple(String); impl FromDataSimple for Simple { type Error = (); - fn from_data(_: &Request, data: Data) -> data::Outcome { + fn from_data(_: &Request<'_>, data: Data) -> data::Outcome { 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 = "

")] -fn form(form: Form) -> String { form.field.url_decode_lossy() } +fn form(form: Form>) -> String { form.field.url_decode_lossy() } #[post("/s", data = "")] fn simple(simple: Simple) -> String { simple.0 } diff --git a/core/codegen/tests/route.rs b/core/codegen/tests/route.rs index c418e23265..ecc554663e 100644 --- a/core/codegen/tests/route.rs +++ b/core/codegen/tests/route.rs @@ -28,7 +28,7 @@ struct Simple(String); impl FromDataSimple for Simple { type Error = (); - fn from_data(_: &Request, data: Data) -> data::Outcome { + fn from_data(_: &Request<'_>, data: Data) -> data::Outcome { 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, + query: Form>, path: PathBuf, simple: Simple, ) -> String { @@ -58,7 +58,7 @@ fn post2( sky: usize, name: &RawStr, a: String, - query: Form, + query: Form>, path: PathBuf, simple: Simple, ) -> String { diff --git a/core/codegen/tests/typed-uris.rs b/core/codegen/tests/typed-uris.rs index d1ab280ac8..28fac9a3b7 100644 --- a/core/codegen/tests/typed-uris.rs +++ b/core/codegen/tests/typed-uris.rs @@ -52,13 +52,13 @@ fn simple4_flipped(name: String, id: i32) { } fn unused_param(used: i32, _unused: i32) { } #[post("/")] -fn guard_1(cookies: Cookies, id: i32) { } +fn guard_1(cookies: Cookies<'_>, id: i32) { } #[post("//")] -fn guard_2(name: String, cookies: Cookies, id: i32) { } +fn guard_2(name: String, cookies: Cookies<'_>, id: i32) { } #[post("/a//hi//hey")] -fn guard_3(id: i32, name: String, cookies: Cookies) { } +fn guard_3(id: i32, name: String, cookies: Cookies<'_>) { } #[post("/", data = "")] fn no_uri_display_okay(id: i32, form: Form) { } @@ -70,7 +70,7 @@ fn complex<'r>( query: Form>, user: Form>, bar: &RawStr, - cookies: Cookies + cookies: Cookies<'_> ) { } #[post("/a/")] @@ -80,7 +80,7 @@ fn segments(path: PathBuf) { } fn param_and_segments(path: PathBuf, id: usize) { } #[post("/a//then/")] -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, bar: Result, q1: Result, - rest: Option> + rest: Option>> ) { } #[test] diff --git a/core/codegen/tests/ui-fail/responder-types.rs b/core/codegen/tests/ui-fail/responder-types.rs index c6eb14ddd4..14e73fda51 100644 --- a/core/codegen/tests/ui-fail/responder-types.rs +++ b/core/codegen/tests/ui-fail/responder-types.rs @@ -27,7 +27,7 @@ struct Thing3 { #[derive(Responder)] struct Thing4 { thing: String, - other: ::rocket::http::ContentType, + other: rocket::http::ContentType, then: String, //~^ ERROR Header } diff --git a/core/codegen/tests/uri_display.rs b/core/codegen/tests/uri_display.rs index f8a4627c98..fd233ef629 100644 --- a/core/codegen/tests/uri_display.rs +++ b/core/codegen/tests/uri_display.rs @@ -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); + let uri_string = format!("{}", &$v as &dyn UriDisplay); 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); + let uri_string = format!("{}", &$v as &dyn UriDisplay); assert_eq!(uri_string, $s); ) }