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

Compiler error with Vec<&str> argument: "error: implementation of FromForm is not general enough" #1834

Closed
jakubdabek opened this issue Aug 19, 2021 · 1 comment
Labels
bug Deviation from the specification or expected behavior upstream An unresolvable issue: an upstream dependency bug

Comments

@jakubdabek
Copy link
Contributor

Compiler and crate version:

  • nightly-x86_64-unknown-linux-gnu rustc 1.56.0-nightly (30a0a9b69 2021-08-17)
  • rocket master#786db9b8

Here's some example code:

use rocket::{get, routes};

#[rocket::main]
async fn main() {
    rocket::build()
        .mount("/", routes![foo_str, foo_string, foo_vec_string, foo_vec_str])
        .launch()
        .await
        .unwrap();
}

#[get("/foo_str?<queries>")]
async fn foo_str(queries: &str) {
    todo!("{:?}", queries)
}
#[get("/foo_string?<queries>")]
async fn foo_string(queries: String) {
    todo!("{:?}", queries)
}
#[get("/foo_vec_string?<queries>")]
async fn foo_vec_string(queries: Vec<String>) {
    todo!("{:?}", queries)
}
#[get("/foo_vec_str?<queries>")]
async fn foo_vec_str(queries: Vec<&str>) {
    todo!("{:?}", queries)
}

The compiler doesn't like this code:

error: implementation of `FromForm` is not general enough
  --> src/bin/main-report.rs:24:1
   |
24 | #[get("/foo_vec_str?<queries>")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FromForm` is not general enough
   |
   = note: `&'0 str` must implement `FromForm<'1>`, for any two lifetimes `'0` and `'1`...
   = note: ...but it actually implements `FromForm<'2>`, for some specific lifetime `'2`
   = note: this error originates in the attribute macro `get` (in Nightly builds, run with -Z macro-backtrace for more info)

Only the last one cannot be compiled, and the error message is maximally unhelpful.

@jakubdabek jakubdabek added the triage A bug report being investigated label Aug 19, 2021
@jakubdabek
Copy link
Contributor Author

I've tracked the issue down to a rustc issue (rust-lang/rust#69663) and managed to apply a workaround (rust-lang/rust#57478 (comment)) on that example expanded with cargo-expand and compiled manually. I can try to make a PR to change the code generation for the route macros so that the error doesn't show up.

@SergioBenitez SergioBenitez added bug Deviation from the specification or expected behavior upstream An unresolvable issue: an upstream dependency bug and removed triage A bug report being investigated labels Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Deviation from the specification or expected behavior upstream An unresolvable issue: an upstream dependency bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants