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
When I changed a signature of a function from returning a struct that implementing some trait Responder to impl Responder, the compiler panicked. The panic stack trace is at the end of the post.
#![feature(plugin, custom_derive, conservative_impl_trait)]#![plugin(rocket_codegen)]externcrate rocket;use rocket::State;use rocket::response::Responder;structSomeState;/// This is OK#[get("/one")]fntest_one() -> &'static str{"Hello world"}/// This panics#[get("/")]fntest_two(state:State<SomeState>) -> &'static str{"Hello world"}fnmain(){
rocket::ignite().mount("/",routes![test_one, test_two],).manage(SomeState).launch();}
Code that panics:
#![feature(plugin, custom_derive, conservative_impl_trait)]#![plugin(rocket_codegen)]externcrate rocket;use rocket::State;use rocket::response::Responder;structSomeState;/// This is OK#[get("/one")]fntest_one<'r>() -> implResponder<'r>{"Hello world"}/// This panics#[get("/")]fntest_two(state:State<SomeState>) -> implResponder{"Hello world"}fnmain(){
rocket::ignite().mount("/",routes![test_one, test_two],).manage(SomeState).launch();}
More information
Rocket.rs routes are any functions that returns something that implements the Responder trait. The codegen plugin will wire the routes up via wrapper functions.
Consider the snippet of cargo expand for the code above:
#[allow(unreachable_code)]fnrocket_route_fn_test_one<'_b>(__req:&'_b ::rocket::Request,__data:::rocket::Data,) -> ::rocket::handler::Outcome<'_b>{let responder = test_one();::rocket::handler::Outcome::from(__req, responder)}/// Rocket code generated static route information structure.#[allow(non_upper_case_globals)]#[rocket_route_info]pubstatic static_rocket_route_info_for_test_one:::rocket::StaticRouteInfo =
::rocket::StaticRouteInfo{method:::rocket::http::Method::Get,path:"/one",handler: rocket_route_fn_test_one,format:None,rank:None,};/// This is OK#[rocket_route(static_rocket_route_info_for_test_one)]fntest_one<'r>() -> implResponder<'r>{"Hello world"}
I suspect this might be because of the generated line ::rocket::handler::Outcome::from(__req, responder), which has this signature.
Apologies that I don't know any more of rustc's internals to offer any more information.
EDIT:
If I change the signature to fn test_two<'r>(state: State<'r, SomeState>) -> impl Responder<'r>, the code will compile.
This might be a duplicate of #39872. Please feel free to close this if they are the same.
When I changed a signature of a function from returning a struct that implementing some trait
Responder
toimpl Responder
, the compiler panicked. The panic stack trace is at the end of the post.Code that works:
Code that panics:
More information
Rocket.rs routes are any functions that returns something that implements the
Responder
trait. The codegen plugin will wire the routes up via wrapper functions.Consider the snippet of
cargo expand
for the code above:I suspect this might be because of the generated line
::rocket::handler::Outcome::from(__req, responder)
, which has this signature.Apologies that I don't know any more of rustc's internals to offer any more information.
EDIT:
If I change the signature to
fn test_two<'r>(state: State<'r, SomeState>) -> impl Responder<'r>
, the code will compile.This might be a duplicate of #39872. Please feel free to close this if they are the same.
Meta
rustc --version --verbose
:rustc 1.20.0-nightly (ae98ebf 2017-07-20)
binary: rustc
commit-hash: ae98ebf
commit-date: 2017-07-20
host: x86_64-unknown-linux-gnu
release: 1.20.0-nightly
LLVM version: 4.0
Backtrace:
The text was updated successfully, but these errors were encountered: