-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile causes warnings about macros #399
Comments
Same here, related to rust-lang/rust#39216 |
This appears to be causing four tests to fail during cargo test. |
This seems to be only a problem when using the middleware macro. Implementing the Middleware trait bypasses this issue. |
The problem arises in the middleware macro (in
expands to (via cargo expand):
The compiler warning is on the call to the restrict method, which is |
So I was trying to build the
Expanded, it becomes:
I realised what's probably happening:
If you change your expanded code to something like: #[macro_use] extern crate nickel;
use nickel::{Nickel, HttpRouter, FormBody};
use std::collections::HashMap;
fn main() {
let mut server = Nickel::new();
server.get("/", {
use nickel::{MiddlewareResult, Responder, Response, Request};
#[inline(always)]
fn restrict<'mw, D, R: Responder<D>>(
r: R,
res: Response<'mw, D>,
) -> MiddlewareResult<'mw, D> {
res.send(r)
}
#[inline(always)]
fn restrict_closure<F, D>(f: F) -> F
where
F: for<'r, 'mw, 'conn> Fn(&'r mut Request<'mw, 'conn, D>, Response<'mw, D>)
-> MiddlewareResult<'mw, D>
+ Send
+ Sync,
{
f
}
restrict_closure(move |_, res| {
restrict::<_, ()>(
{
let mut data = HashMap::new();
data.insert("title", "Contact");
return res.render("examples/form_data/views/contact.html", &data);
},
res,
)
})
});
server.post("/confirmation", {
use nickel::{MiddlewareResult, Responder, Response, Request};
#[inline(always)]
fn restrict<'mw, D, R: Responder<D>>(
r: R,
res: Response<'mw, D>,
) -> MiddlewareResult<'mw, D> {
res.send(r)
}
#[inline(always)]
fn restrict_closure<F, D>(f: F) -> F
where
F: for<'r, 'mw, 'conn> Fn(&'r mut Request<'mw, 'conn, D>, Response<'mw, D>)
-> MiddlewareResult<'mw, D>
+ Send
+ Sync,
{
f
}
restrict_closure(move |req, res| {
restrict::<_, ()>(
{
let form_data = {
match req.form_body() {
::std::result::Result::Ok(val) => val,
::std::result::Result::Err(e) => return Err(From::from((res, e))),
}
};
println!("{:?}", form_data);
let mut data = HashMap::new();
data.insert("title", "Confirmation");
data.insert(
"firstname",
form_data.get("firstname").unwrap_or("First name?"),
);
data.insert(
"lastname",
form_data.get("lastname").unwrap_or("Last name?"),
);
data.insert("phone", form_data.get("phone").unwrap_or("Phone?"));
data.insert("email", form_data.get("email").unwrap_or("Email?"));
return res.render("examples/form_data/views/confirmation.html", &data);
},
res,
)
})
});
server.listen("0.0.0.0:8080").unwrap();
} it builds. The change was to explicitly state the type parameter P.S.: I thought the |
The unidiomatic Unfortunately adding the type signature to the macro is breaking the use cases without the return. |
I am starting to understand. The I think the |
I am not seeing a way to fix this without breaking existing code. Since the migration to hyper 0.11.a in #402 is going to change the API anyway, I plan on addressing this as part of the eventual nickel 0.11. |
Fix the examples that were returning MiddlewareResults in the middlware! macro. A couple could be changed to return a Responder, but most needed to be reimplemented as seperate functions. Updated the middleware! macro documentaion to note the limitations from issues nickel-org#399 and nickel-org#389.
Fix the examples that were returning MiddlewareResults in the middlware! macro. A couple could be changed to return a Responder, but most needed to be reimplemented as seperate functions. Updated the middleware! macro documentaion to note the limitations from issues nickel-org#399 and nickel-org#389. Disable ssl testing in travis, which was broken in commit 8d5a7d0. Issue nickel-org#415 to track our SSL plan.
PR #414 addresses this issue partially, in that it fixes currently breaking examples and documents the macro's limitations. |
fix(examples): Fix examples triggering issue #399
Fix the examples that were returning MiddlewareResults in the middlware! macro. A couple could be changed to return a Responder, but most needed to be reimplemented as seperate functions. Updated the middleware! macro documentaion to note the limitations from issues nickel-org#399 and nickel-org#389. Disable ssl testing in travis, which was broken in commit 8d5a7d0. Issue nickel-org#415 to track our SSL plan.
Compiling my project results in a bunch of warnings:
This happens with
router!
as well. My code is very similar to the examples on http://nickel.rs, I'm not sure if I'm doing something wrong.The text was updated successfully, but these errors were encountered: