From 642b411d0443ae21f1fb31f9180c9ede85e381c6 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Sun, 24 May 2020 18:16:09 +0100 Subject: [PATCH] Remove fix for #12 I don't believe this is necessary in newer nightlies. It also causes its own warnings (#27). --- rocket-okapi-codegen/Cargo.toml | 2 +- rocket-okapi-codegen/src/lib.rs | 38 +-------------------------------- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/rocket-okapi-codegen/Cargo.toml b/rocket-okapi-codegen/Cargo.toml index be9a8c7..c365b33 100644 --- a/rocket-okapi-codegen/Cargo.toml +++ b/rocket-okapi-codegen/Cargo.toml @@ -14,6 +14,6 @@ proc-macro = true [dependencies] rocket_http = { git = "https://github.com/SergioBenitez/Rocket.git", branch = "async" } darling = "0.10" -syn = { version = "1.0", features = ["fold"] } +syn = "1.0" proc-macro2 = "1.0" quote = "1.0" diff --git a/rocket-okapi-codegen/src/lib.rs b/rocket-okapi-codegen/src/lib.rs index 4789bbb..b28d3ba 100644 --- a/rocket-okapi-codegen/src/lib.rs +++ b/rocket-okapi-codegen/src/lib.rs @@ -9,8 +9,7 @@ mod openapi_attr; mod routes_with_openapi; use proc_macro::TokenStream; -use syn::fold::{self, Fold}; -use syn::{token::Paren, GenericArgument, Ident, Type, TypeParen}; +use syn::Ident; /// A proc macro to be used in tandem with one of `Rocket`'s endpoint macros. It requires that all /// of the arguments of the route implement one of the traits in `rocket_okapi::request`, and that @@ -28,8 +27,6 @@ use syn::{token::Paren, GenericArgument, Ident, Type, TypeParen}; /// ``` #[proc_macro_attribute] pub fn openapi(args: TokenStream, mut input: TokenStream) -> TokenStream { - input = preserve_span_information(input); - // We don't need to modify/replace the input TokenStream, // we just need to append to it. input.extend(openapi_attr::parse(args, input.clone())); @@ -44,39 +41,6 @@ pub fn routes_with_openapi(input: TokenStream) -> TokenStream { routes_with_openapi::parse(input) } -fn preserve_span_information(input: TokenStream) -> TokenStream { - // Outputting the input unmodified would cause its span information to be - // lost when being consumed by other macros. But parsing it in then quoting - // it back out causes span information to be preserved. - // See https://github.com/GREsau/okapi/issues/12 - // and https://github.com/rust-lang/rust/issues/43081 - let parsed_input: syn::Item = syn::parse(input).unwrap(); - - // Nested generics cause span bugs - we can work around this by wrapping all - // generic type parameters in parentheses. - // https://github.com/rust-lang/rust/pull/48258 - let parsed_input = GenericTypeVisitor.fold_item(parsed_input); - - quote!(#parsed_input).into() -} - -struct GenericTypeVisitor; - -impl Fold for GenericTypeVisitor { - fn fold_generic_argument(&mut self, mut node: GenericArgument) -> GenericArgument { - node = fold::fold_generic_argument(self, node); - - if let GenericArgument::Type(ty) = node { - node = GenericArgument::Type(Type::Paren(TypeParen { - paren_token: Paren::default(), - elem: Box::new(ty), - })); - } - - node - } -} - fn get_add_operation_fn_name(route_fn_name: &Ident) -> Ident { Ident::new( &format!("okapi_add_operation_for_{}_", route_fn_name),