Skip to content
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

Weird codegen error with route #182

Closed
lilyball opened this issue Feb 9, 2017 · 3 comments
Closed

Weird codegen error with route #182

lilyball opened this issue Feb 9, 2017 · 3 comments
Labels
no bug The reported bug was confirmed nonexistent

Comments

@lilyball
Copy link

lilyball commented Feb 9, 2017

I'm getting a really weird error from one of my routes. The route itself looks like

#[post("/foo/<id>/edit", data="<form>")]
fn post_edit_foo(id: i32, form: Form<FooForm>, pool: State<Pool>)
        -> Result<Flash<Redirect>,Failure> {}

But when I try to compile it, I get 2 identical errors that look like

error[E0308]: mismatched types
   --> src/main.rs:118:1
    |
118 | #[post("/foo/<id>/edit", data="<form>")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &str, found struct `std::string::String`
    |
    = note: expected type `&str`
               found type `std::string::String`
    = help: here are some functions which might fulfill your needs:
            - .as_str()
            - .trim()
            - .trim_left()
            - .trim_right()
    = note: this error originates in a macro outside of the current crate

Since the error is in the generated code, I have no idea what's actually going wrong or how to fix it. I tried writing a sample app to reproduce this without any luck.

Any idea what's going wrong? Or any suggestions on how to debug this?

This is with rocket 0.2.0.

@SergioBenitez
Copy link
Member

Are you sure it's not in the body of your handler? As indicated in the documentation, you can set ROCKET_CODEGEN_DEBUG=1 during compilation to see the generated code.

@lilyball
Copy link
Author

lilyball commented Feb 9, 2017

Ah hah, the error was in my code! I assumed it couldn't be, because the error specifically indicated it came from a macro. I didn't realize rocket_codegen effectively rewrites my function in a way that breaks compiler errors. Is there no way to preserve the span info so the compiler error works just fine?

Also, I've already seen plenty of errors that pointed into my handlers just fine, so I'm pretty confused as to why this particular error didn't. The root cause of the error was Redirect::to(format!("/foo/{}", id)).

@SergioBenitez
Copy link
Member

I imagine it has something to do with the format! macro. I'd report this to Rust; it's an interesting case. Anyway, looks like the issue here is resolved. Closing it out.

@SergioBenitez SergioBenitez added the no bug The reported bug was confirmed nonexistent label Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no bug The reported bug was confirmed nonexistent
Projects
None yet
Development

No branches or pull requests

2 participants