diff --git a/core/codegen/Cargo.toml b/core/codegen/Cargo.toml index 55e9a29a..942bc6be 100644 --- a/core/codegen/Cargo.toml +++ b/core/codegen/Cargo.toml @@ -17,8 +17,10 @@ proc-macro = true [dependencies] indexmap = "1.0" quote = "1.0" -rocket_http = { version = "0.5.0-dev", path = "../http/" } +syn = { version = "1.0.72", features = ["full", "visit", "visit-mut", "extra-traits"] } +proc-macro2 = "1.0.27" devise = { git = "https://github.com/SergioBenitez/Devise.git", rev = "df00b5" } +rocket_http = { version = "0.5.0-dev", path = "../http/" } unicode-xid = "0.2" glob = "0.3" diff --git a/core/codegen/src/attribute/catch/mod.rs b/core/codegen/src/attribute/catch/mod.rs index 5c41412f..f504f1bf 100644 --- a/core/codegen/src/attribute/catch/mod.rs +++ b/core/codegen/src/attribute/catch/mod.rs @@ -1,10 +1,10 @@ mod parse; use devise::ext::SpanDiagnosticExt; -use devise::{syn, Spanned, Result}; +use devise::{Spanned, Result}; +use proc_macro2::{TokenStream, Span}; use crate::http_codegen::Optional; -use crate::proc_macro2::{TokenStream, Span}; use crate::syn_ext::ReturnTypeExt; use crate::exports::*; diff --git a/core/codegen/src/attribute/catch/parse.rs b/core/codegen/src/attribute/catch/parse.rs index 6ce31178..34125c9c 100644 --- a/core/codegen/src/attribute/catch/parse.rs +++ b/core/codegen/src/attribute/catch/parse.rs @@ -1,8 +1,8 @@ use devise::ext::SpanDiagnosticExt; -use devise::{syn, MetaItem, Spanned, Result, FromMeta, Diagnostic}; +use devise::{MetaItem, Spanned, Result, FromMeta, Diagnostic}; +use proc_macro2::TokenStream; use crate::{http, http_codegen}; -use crate::proc_macro2::TokenStream; /// This structure represents the parsed `catch` attribute and associated items. pub struct Attribute { diff --git a/core/codegen/src/attribute/entry/launch.rs b/core/codegen/src/attribute/entry/launch.rs index c754a73a..09a40160 100644 --- a/core/codegen/src/attribute/entry/launch.rs +++ b/core/codegen/src/attribute/entry/launch.rs @@ -1,8 +1,8 @@ use super::EntryAttr; -use devise::{syn, Spanned, Result}; +use devise::{Spanned, Result}; use devise::ext::SpanDiagnosticExt; -use devise::proc_macro2::{TokenStream, Span}; +use proc_macro2::{TokenStream, Span}; /// `#[rocket::launch]`: generates a `main` function that calls the attributed /// function to generate a `Rocket` instance. Then calls `.launch()` on the diff --git a/core/codegen/src/attribute/entry/main.rs b/core/codegen/src/attribute/entry/main.rs index e83261e6..52287b56 100644 --- a/core/codegen/src/attribute/entry/main.rs +++ b/core/codegen/src/attribute/entry/main.rs @@ -1,8 +1,8 @@ use super::EntryAttr; -use devise::{syn, Spanned, Result}; +use devise::{Spanned, Result}; use devise::ext::SpanDiagnosticExt; -use devise::proc_macro2::{TokenStream, Span}; +use proc_macro2::{TokenStream, Span}; /// `#[rocket::async_main]`: calls the attributed fn inside `rocket::async_main` pub struct Main; diff --git a/core/codegen/src/attribute/entry/mod.rs b/core/codegen/src/attribute/entry/mod.rs index 0698ed83..38947777 100644 --- a/core/codegen/src/attribute/entry/mod.rs +++ b/core/codegen/src/attribute/entry/mod.rs @@ -2,9 +2,9 @@ mod main; mod launch; mod test; -use devise::{syn, Diagnostic, Spanned, Result}; +use devise::{Diagnostic, Spanned, Result}; use devise::ext::SpanDiagnosticExt; -use devise::proc_macro2::{TokenStream, Span}; +use proc_macro2::{TokenStream, Span}; // Common trait implemented by `async` entry generating attributes. trait EntryAttr { diff --git a/core/codegen/src/attribute/entry/test.rs b/core/codegen/src/attribute/entry/test.rs index 5804748d..8c197719 100644 --- a/core/codegen/src/attribute/entry/test.rs +++ b/core/codegen/src/attribute/entry/test.rs @@ -1,7 +1,7 @@ use super::EntryAttr; -use devise::{syn, Spanned, Result}; -use devise::proc_macro2::TokenStream; +use devise::{Spanned, Result}; +use proc_macro2::TokenStream; /// `#[rocket::async_test]`: calls the attributed fn inside `rocket::async_test` pub struct Test; diff --git a/core/codegen/src/attribute/param/guard.rs b/core/codegen/src/attribute/param/guard.rs index 53396320..c972e6eb 100644 --- a/core/codegen/src/attribute/param/guard.rs +++ b/core/codegen/src/attribute/param/guard.rs @@ -1,13 +1,12 @@ use std::hash::{Hash, Hasher}; -use devise::{syn, FromMeta, MetaItem, Result}; +use devise::{FromMeta, MetaItem, Result}; +use proc_macro2::Span; use crate::name::Name; -use crate::proc_macro2::Span; use crate::proc_macro_ext::StringLit; use crate::http::uri; - impl Dynamic { pub fn is_wild(&self) -> bool { self.value == "_" diff --git a/core/codegen/src/attribute/param/mod.rs b/core/codegen/src/attribute/param/mod.rs index 39442f4f..94e2c17e 100644 --- a/core/codegen/src/attribute/param/mod.rs +++ b/core/codegen/src/attribute/param/mod.rs @@ -3,7 +3,6 @@ mod parse; use std::ops::Deref; use std::hash::Hash; -use crate::syn; use crate::name::Name; #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/core/codegen/src/attribute/param/parse.rs b/core/codegen/src/attribute/param/parse.rs index 54eba8c4..e542cd41 100644 --- a/core/codegen/src/attribute/param/parse.rs +++ b/core/codegen/src/attribute/param/parse.rs @@ -1,9 +1,9 @@ use unicode_xid::UnicodeXID; use devise::{Diagnostic, ext::SpanDiagnosticExt}; +use proc_macro2::Span; use crate::name::Name; use crate::proc_macro_ext::StringLit; -use crate::proc_macro2::Span; use crate::attribute::param::{Parameter, Dynamic}; use crate::http::uri::fmt::{Part, Kind, Path}; diff --git a/core/codegen/src/attribute/route/mod.rs b/core/codegen/src/attribute/route/mod.rs index a24a2c43..5fae0b2a 100644 --- a/core/codegen/src/attribute/route/mod.rs +++ b/core/codegen/src/attribute/route/mod.rs @@ -2,11 +2,10 @@ mod parse; use std::hash::Hash; -use proc_macro2::{TokenStream, Span}; use devise::{Spanned, SpanWrapped, Result, FromMeta, Diagnostic}; use devise::ext::TypeExt as _; +use proc_macro2::{TokenStream, Span}; -use crate::{proc_macro2, syn}; use crate::proc_macro_ext::StringLit; use crate::syn_ext::{IdentExt, TypeExt as _}; use crate::http_codegen::{Method, Optional}; diff --git a/core/codegen/src/attribute/route/parse.rs b/core/codegen/src/attribute/route/parse.rs index fadf7428..98d2191f 100644 --- a/core/codegen/src/attribute/route/parse.rs +++ b/core/codegen/src/attribute/route/parse.rs @@ -1,14 +1,13 @@ -use devise::{syn, Spanned, SpanWrapped, Result, FromMeta}; +use devise::{Spanned, SpanWrapped, Result, FromMeta}; use devise::ext::{SpanDiagnosticExt, TypeExt}; use indexmap::{IndexSet, IndexMap}; +use proc_macro2::Span; use crate::proc_macro_ext::Diagnostics; use crate::http_codegen::{Method, MediaType}; use crate::attribute::param::{Parameter, Dynamic, Guard}; use crate::syn_ext::FnArgExt; - use crate::name::Name; -use crate::proc_macro2::Span; use crate::http::ext::IntoOwned; use crate::http::uri::{Origin, fmt}; diff --git a/core/codegen/src/bang/export.rs b/core/codegen/src/bang/export.rs index b48dd483..5004d17a 100644 --- a/core/codegen/src/bang/export.rs +++ b/core/codegen/src/bang/export.rs @@ -2,8 +2,7 @@ use std::hash::Hash; use devise::Spanned; use devise::ext::SpanDiagnosticExt; -use devise::proc_macro2::{TokenStream, TokenTree, Punct}; -use devise::syn; +use proc_macro2::{TokenStream, TokenTree, Punct}; use crate::syn_ext::IdentExt; diff --git a/core/codegen/src/bang/mod.rs b/core/codegen/src/bang/mod.rs index 7dc7e35c..627ea338 100644 --- a/core/codegen/src/bang/mod.rs +++ b/core/codegen/src/bang/mod.rs @@ -1,8 +1,7 @@ use devise::Result; - -use crate::syn::{Path, punctuated::Punctuated, parse::Parser, Token}; -use crate::proc_macro2::TokenStream; -use crate::syn::spanned::Spanned; +use syn::{Path, punctuated::Punctuated, parse::Parser, Token}; +use syn::spanned::Spanned; +use proc_macro2::TokenStream; mod uri; mod uri_parsing; diff --git a/core/codegen/src/bang/test_guide.rs b/core/codegen/src/bang/test_guide.rs index ad2a609e..8de5b160 100644 --- a/core/codegen/src/bang/test_guide.rs +++ b/core/codegen/src/bang/test_guide.rs @@ -1,9 +1,9 @@ use std::path::Path; use std::error::Error; +use syn::{self, Ident, LitStr}; use devise::ext::SpanDiagnosticExt; -use devise::syn::{self, Ident, LitStr}; -use devise::proc_macro2::TokenStream; +use proc_macro2::TokenStream; pub fn _macro(input: proc_macro::TokenStream) -> devise::Result { let root_glob = syn::parse::(input.into())?; diff --git a/core/codegen/src/bang/uri.rs b/core/codegen/src/bang/uri.rs index a128679a..c8715fc1 100644 --- a/core/codegen/src/bang/uri.rs +++ b/core/codegen/src/bang/uri.rs @@ -1,14 +1,13 @@ use std::fmt::Display; -use devise::{syn, Result}; -use devise::ext::{SpanDiagnosticExt, quote_respanned}; +use devise::{Result, ext::{SpanDiagnosticExt, quote_respanned}}; +use syn::{Expr, Ident, Type, spanned::Spanned}; +use proc_macro2::TokenStream; use crate::http::uri::fmt; use crate::http_codegen::Optional; -use crate::syn::{Expr, Ident, Type, spanned::Spanned}; use crate::syn_ext::IdentExt; use crate::bang::uri_parsing::*; -use crate::proc_macro2::TokenStream; use crate::attribute::param::Parameter; use crate::exports::*; use crate::URI_MACRO_PREFIX; diff --git a/core/codegen/src/bang/uri_parsing.rs b/core/codegen/src/bang/uri_parsing.rs index 88debbe0..3dd3d11e 100644 --- a/core/codegen/src/bang/uri_parsing.rs +++ b/core/codegen/src/bang/uri_parsing.rs @@ -3,15 +3,14 @@ use std::ops::Deref; use indexmap::IndexMap; use devise::{Spanned, ext::TypeExt}; use quote::{ToTokens, TokenStreamExt}; +use syn::{Expr, Ident, LitStr, Path, Token, Type}; +use syn::parse::{self, Parse, ParseStream, Parser}; +use syn::punctuated::Punctuated; +use proc_macro2::{TokenStream, TokenTree, Span}; use rocket_http::uri::{Error, Reference}; -use crate::{http_codegen, syn::{self, Expr, Ident, LitStr, Path, Token, Type}}; -use crate::syn::parse::{self, Parse, ParseStream, Parser}; -use crate::syn::punctuated::Punctuated; - use crate::http::uri::{Uri, Origin, Absolute, fmt}; use crate::http::ext::IntoOwned; -use crate::proc_macro2::{TokenStream, TokenTree, Span}; use crate::proc_macro_ext::StringLit; use crate::attribute::param::{Parameter, Dynamic}; use crate::name::Name; @@ -549,7 +548,7 @@ impl Deref for UriLit { impl ToTokens for UriLit { fn to_tokens(&self, t: &mut TokenStream) { - use http_codegen::*; + use crate::http_codegen::*; let (uri, span) = (&self.0, self.1); match uri { diff --git a/core/codegen/src/derive/form_field.rs b/core/codegen/src/derive/form_field.rs index 3a701427..75a9bb64 100644 --- a/core/codegen/src/derive/form_field.rs +++ b/core/codegen/src/derive/form_field.rs @@ -2,8 +2,8 @@ use devise::{*, ext::{TypeExt, SpanDiagnosticExt}}; use syn::visit_mut::VisitMut; use syn::visit::Visit; +use proc_macro2::{TokenStream, TokenTree, Span}; -use crate::proc_macro2::{TokenStream, TokenTree, Span}; use crate::syn_ext::IdentExt; use crate::name::Name; diff --git a/core/codegen/src/derive/from_form.rs b/core/codegen/src/derive/from_form.rs index 0834a38a..c334fd5d 100644 --- a/core/codegen/src/derive/from_form.rs +++ b/core/codegen/src/derive/from_form.rs @@ -1,7 +1,7 @@ use devise::{*, ext::{TypeExt, SpanDiagnosticExt, GenericsExt, Split2, quote_respanned}}; +use proc_macro2::TokenStream; use crate::exports::*; -use crate::proc_macro2::TokenStream; use crate::derive::form_field::{*, FieldName::*}; // F: fn(field_ty: Ty, field_context: Expr) diff --git a/core/codegen/src/derive/from_form_field.rs b/core/codegen/src/derive/from_form_field.rs index 5fc5e4d6..a2bcba4e 100644 --- a/core/codegen/src/derive/from_form_field.rs +++ b/core/codegen/src/derive/from_form_field.rs @@ -1,7 +1,7 @@ use devise::{*, ext::SpanDiagnosticExt}; +use proc_macro2::TokenStream; use crate::exports::*; -use crate::proc_macro2::TokenStream; use crate::derive::form_field::{VariantExt, first_duplicate}; pub fn derive_from_form_field(input: proc_macro::TokenStream) -> TokenStream { diff --git a/core/codegen/src/derive/responder.rs b/core/codegen/src/derive/responder.rs index 06d74150..d5b3a01d 100644 --- a/core/codegen/src/derive/responder.rs +++ b/core/codegen/src/derive/responder.rs @@ -1,8 +1,8 @@ use quote::ToTokens; use devise::{*, ext::{TypeExt, SpanDiagnosticExt}}; +use proc_macro2::TokenStream; use crate::exports::*; -use crate::proc_macro2::TokenStream; use crate::http_codegen::{ContentType, Status}; #[derive(Debug, Default, FromMeta)] diff --git a/core/codegen/src/derive/uri_display.rs b/core/codegen/src/derive/uri_display.rs index 671b54dc..7dbe5e28 100644 --- a/core/codegen/src/derive/uri_display.rs +++ b/core/codegen/src/derive/uri_display.rs @@ -1,9 +1,8 @@ - +use proc_macro2::TokenStream; use devise::{*, ext::SpanDiagnosticExt}; use crate::exports::*; use crate::derive::form_field::{FieldExt, VariantExt}; -use crate::proc_macro2::TokenStream; use crate::http::uri::fmt; const NO_EMPTY_FIELDS: &str = "fieldless structs are not supported"; diff --git a/core/codegen/src/exports.rs b/core/codegen/src/exports.rs index 4aa292fb..d6c1f4d9 100644 --- a/core/codegen/src/exports.rs +++ b/core/codegen/src/exports.rs @@ -1,6 +1,5 @@ -use crate::syn; -use crate::proc_macro2::{Span, TokenStream}; -use crate::quote::{ToTokens, TokenStreamExt}; +use proc_macro2::{Span, TokenStream}; +use quote::{ToTokens, TokenStreamExt}; #[derive(Debug, Copy, Clone)] pub struct StaticPath(pub Option, pub &'static str); diff --git a/core/codegen/src/http_codegen.rs b/core/codegen/src/http_codegen.rs index adb3a6c3..28418f59 100644 --- a/core/codegen/src/http_codegen.rs +++ b/core/codegen/src/http_codegen.rs @@ -1,8 +1,8 @@ use quote::ToTokens; use devise::{FromMeta, MetaItem, Result, ext::{Split2, PathExt, SpanDiagnosticExt}}; +use proc_macro2::{TokenStream, Span}; use crate::http; -use crate::proc_macro2::{TokenStream, Span}; #[derive(Debug)] pub struct ContentType(pub http::ContentType); diff --git a/core/codegen/src/lib.rs b/core/codegen/src/lib.rs index f55e2ed5..10d70a92 100644 --- a/core/codegen/src/lib.rs +++ b/core/codegen/src/lib.rs @@ -70,7 +70,6 @@ mod name; use crate::http::Method; use proc_macro::TokenStream; -use devise::{proc_macro2, syn}; static URI_MACRO_PREFIX: &str = "rocket_uri_macro_"; static ROCKET_IDENT_PREFIX: &str = "__rocket_"; diff --git a/core/codegen/src/name.rs b/core/codegen/src/name.rs index c478df01..d4902429 100644 --- a/core/codegen/src/name.rs +++ b/core/codegen/src/name.rs @@ -1,6 +1,7 @@ -use crate::syn::{self, Ident, ext::IdentExt}; use crate::http::uncased::UncasedStr; -use crate::proc_macro2::Span; + +use syn::{self, Ident, ext::IdentExt}; +use proc_macro2::{Span, TokenStream}; /// A "name" read by codegen, which may or may not be an identifier. A `Name` is /// typically constructed indirectly via FromMeta, or From or directly @@ -55,7 +56,7 @@ impl devise::FromMeta for Name { } impl quote::ToTokens for Name { - fn to_tokens(&self, tokens: &mut devise::proc_macro2::TokenStream) { + fn to_tokens(&self, tokens: &mut TokenStream) { syn::LitStr::new(self.as_str(), self.span()).to_tokens(tokens) } } diff --git a/core/codegen/src/proc_macro_ext.rs b/core/codegen/src/proc_macro_ext.rs index 32c13365..f5d4f85b 100644 --- a/core/codegen/src/proc_macro_ext.rs +++ b/core/codegen/src/proc_macro_ext.rs @@ -1,8 +1,7 @@ use std::ops::RangeBounds; use devise::Diagnostic; - -use crate::proc_macro2::{Span, Literal}; +use proc_macro2::{Span, Literal}; // An experiment. pub struct Diagnostics(Vec); @@ -70,9 +69,9 @@ impl StringLit { } } -impl crate::syn::parse::Parse for StringLit { - fn parse(input: devise::syn::parse::ParseStream<'_>) -> devise::syn::Result { - let lit = input.parse::()?; +impl syn::parse::Parse for StringLit { + fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result { + let lit = input.parse::()?; Ok(StringLit::new(lit.value(), lit.span())) } } diff --git a/core/codegen/src/syn_ext.rs b/core/codegen/src/syn_ext.rs index 5e700cd2..41265581 100644 --- a/core/codegen/src/syn_ext.rs +++ b/core/codegen/src/syn_ext.rs @@ -3,8 +3,8 @@ use std::ops::Deref; use std::hash::{Hash, Hasher}; -use crate::syn::{self, Ident, ext::IdentExt as _, visit::Visit}; -use crate::proc_macro2::Span; +use syn::{self, Ident, ext::IdentExt as _, visit::Visit}; +use proc_macro2::{Span, TokenStream}; pub trait IdentExt { fn prepend(&self, string: &str) -> syn::Ident; @@ -19,7 +19,7 @@ pub trait ReturnTypeExt { } pub trait TokenStreamExt { - fn respanned(&self, span: crate::proc_macro2::Span) -> Self; + fn respanned(&self, span: Span) -> Self; } pub trait FnArgExt { @@ -91,8 +91,8 @@ impl ReturnTypeExt for syn::ReturnType { } } -impl TokenStreamExt for crate::proc_macro2::TokenStream { - fn respanned(&self, span: crate::proc_macro2::Span) -> Self { +impl TokenStreamExt for TokenStream { + fn respanned(&self, span: Span) -> Self { self.clone().into_iter().map(|mut token| { token.set_span(span); token