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

Query string and struct with single field named v -> Error: expected &str, found enum std::option::Option #265

Closed
rofrol opened this issue Apr 17, 2017 · 3 comments
Labels
accepted An accepted request or suggestion bug Deviation from the specification or expected behavior

Comments

@rofrol
Copy link
Contributor

rofrol commented Apr 17, 2017

  1. The version of Rocket you're using. Ensure it's the latest, if possible.
    0.2.5
  2. A brief description of the bug that includes:
    * The nature of the bug.
    * When the bug occurs.
    When struct has one and only one field named v.
    * What you expected vs. what actually happened.
    It compiles vs error.
  3. How you discovered the bug. Short test cases are especially useful.

Code:

#![feature(plugin, custom_derive)]
#![plugin(rocket_codegen)]

extern crate rocket;

#[macro_use]
extern crate rocket_contrib;

use rocket_contrib::{JSON, Value};

#[derive(FromForm)]
struct Person<'r> {
    v: &'r str,
}

#[get("/file?<person>")]
fn styles_with_query(person: Person) -> String {
    format!("Hello {}!", person.v)
}

#[error(404)]
fn not_found() -> JSON<Value> {
    JSON(json!({
        "status": "error",
        "reason": "Resource was not found."
    }))
}

fn main() {
    rocket::ignite()
        .mount("/", routes![styles_with_query])
        .catch(errors![not_found])
        .launch();
}

Running:

$ rustup install nightly-2017-04-16
$ rustup override set nightly-2017-04-16
$ cargo build
   Compiling bug v0.1.0 (file:https:///C:/projects/rust/rocket-bug)
error[E0308]: match arms have incompatible types
  --> src\main.rs:11:10
   |
11 | #[derive(FromForm)]
   |          ^^^^^^^^ expected &str, found enum `std::option::Option`
   |
   = note: expected type `&str`
              found type `std::option::Option<_>`
note: match arm with an incompatible type
  --> src\main.rs:11:10
   |
11 | #[derive(FromForm)]
   |          ^^^^^^^^

error: aborting due to previous error

error: Could not compile `rocket-bug`.

To learn more, run the command again with --verbose.
  1. Ideas, if any, about what Rocket is doing incorrectly.
    It works if field has any other name than v.
@SergioBenitez SergioBenitez added accepted An accepted request or suggestion bug Deviation from the specification or expected behavior labels Apr 17, 2017
@SergioBenitez
Copy link
Member

Confirmed! Fix is incoming.

@SergioBenitez
Copy link
Member

The fix is in v0.2.6.

@rofrol
Copy link
Contributor Author

rofrol commented Apr 18, 2017

Maybe there should be specific error message in error catalog when someone somehow encounters this: "Don't use __v, __e, __k for field name" etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted An accepted request or suggestion bug Deviation from the specification or expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants