You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently writing a library arc-reactor, due to time constraints, i abandoned it for a while. But now i'm trying to pick up where i left off, and there are some errors i don't understand. I use proc-macros in the project for code generation.
#[proc_macro_attribute]pubfnservice(_attribute:TokenStream,function:TokenStream) -> TokenStream{let item = syn::parse(function).expect("Well, that didn't work. Must be a syntax error.");letItemFn{
ident,
block,
decl,
..
} = match item {Item::Fn(item) => item,
_ => panic!("#[service]: Whoops!, try again. This time, with a function."),};let block = block.stmts.iter();let inputs = decl.inputs.into_tokens();let output = quote!{struct #ident;
implArcServicefor #ident {fn call(&self, #inputs) -> Box<Future<Item = Response, Error = Error>> {Box::new(
async_block!{
#(
#block
)*
})}}};println!("{}", &output)
output.into()}
to be used as
#[service]fnRequestHandler(request:Request,res:Response){let url = request.map.get::<Params>().unwrap();let body = format!("Hello {}", url["username"]);let res = res
.with_status(StatusCode::Ok).with_body(body);Ok(res)}
which should generate
structRequestHandler;implArcServiceforRequestHandler{fncall(&self,request:Request,res:Response) -> Box<Future<Item= Response,Error=Error>>{Box::new(async_block!{let url = request.map.get::<Params>().unwra ();
let body = format!("Hello {}" , url["username"]);
let res = res.with_status (StatusCode :: Ok)
.with_body(body);
Ok(res)})}}
which it actually does, but when i compile it i get, these
~/Projects/async-server on redesign [!?]
➜ cargo run ⏎ redesign ✱ ◼
Compiling async-server v0.1.0 (file:///home/seunlanlege/Projects/async-server)
struct RequestHandler ; impl ArcService for RequestHandler {
fn call ( & self , request : Request , res : Response ) -> Box < Future < Item
= Response , Error = Error >> {
Box :: new (
async_block ! {
let url = request . map . get :: < Params > ( ) . unwrap ( ) ;let body =
format ! ( "Hello {}" , url [ "username" ] ) ;let res = res . with_status (
StatusCode :: Ok ) . with_body ( body ) ; Ok ( res ) } ) } }
error: cannot find macro `async_block!`in this scope
--> src/main.rs:51:1
|
51 |#[service]| ^^^^^^^^^^
error[E0405]: cannot find trait `ArcService`in this scope
--> src/main.rs:51:1
|
51 |#[service]| ^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
|
24 | use ArcProto::service::ArcService;|
error[E0412]: cannot find type`Future`in this scope
--> src/main.rs:51:1
|
51 |#[service]| ^^^^^^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
24 | use futures::Future;|
24 | use futures::future::Future;|
24 | use futures::prelude::Future;|
error[E0412]: cannot find type`Response`in this scope
--> src/main.rs:51:1
|
51 |#[service]| ^^^^^^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
24 | use ArcCore::response::Response;|
24 | use hyper::Response;|
24 | use hyper::client::Response;|
24 | use hyper::server::Response;|
error[E0412]: cannot find type`Error`in this scope
--> src/main.rs:51:1
|
51 |#[service]| ^^^^^^^^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
24 | use hyper::Error;|
24 | use hyper::error::Error;|
24 | use std::error::Error;|
24 | use std::fmt::Error;|
and 1 other candidates
error: aborting due to 5 previous errors
error: Could not compile `async-server`.
To learn more, run the command again with --verbose.
all the missiing deps rustc is complaining about are all imported
#![feature(proc_macro,box_syntax,generators,)]#![allow(non_camel_case_types)]#![allow(non_snake_case)]#![allow(dead_code)]externcrate anymap;externcrate impl_service;externcrate num_cpus;externcrate tokio_core;externcrate route_recognizer as recognizer;externcrate futures_await as futures;externcrate hyper;modArcRouting;modArcCore;#[macro_use]modArcProto;use recognizer::Params;use impl_service::{service, middleware};use hyper::{Error,StatusCode};use futures::future::Future;use futures::prelude::{async_block};
I really don't know how to debug this, the code used to work. and now it no longer doesn't.
The text was updated successfully, but these errors were encountered:
seunlanlege
changed the title
rustc can no longer resolve my imports inside quote.
rustc can no longer resolve my imports inside quote!{}.
Jan 8, 2018
I believe this has to do with whether certain tokens are resolved at the "call site" or at the "def site". Tokens that resolve at the call site resolve to things that are in scope in the code where the macro is called i.e. the code containing #[service] in your case. This is the default (well, the only possible) behavior for macros 1.1-style string based procedural macros. Tokens that resolve at the def site may only resolve to things brought into scope by the generated code such as by doing extern crate or use. This is the new default behavior for all tokens originating from quote!.
I'm currently writing a library arc-reactor, due to time constraints, i abandoned it for a while. But now i'm trying to pick up where i left off, and there are some errors i don't understand. I use
proc-macros
in the project for code generation.cargo.toml
to be used as
which should generate
which it actually does, but when i compile it i get, these
all the missiing deps
rustc
is complaining about are all importedI really don't know how to debug this, the code used to work. and now it no longer doesn't.
The text was updated successfully, but these errors were encountered: