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

Redirection to a route which takes a vector parameter results in an error #2750

Closed
4 tasks done
Unei95 opened this issue Mar 13, 2024 · 1 comment
Closed
4 tasks done
Labels
deficiency Something doesn't work as well as it could

Comments

@Unei95
Copy link

Unei95 commented Mar 13, 2024

Rocket Version

0.5.0

Operating System

NixOS 23.11

Rust Toolchain Version

rustc 1.76.0

What happened?

Redirecting to a route which takes a vector parameter throws the following error:

error[E0277]: the trait bound `Vec<i32>: FromUriParam<rocket::http::uri::fmt::Query, _>` is not satisfied
  --> src/main.rs:18:31
   |
18 |     Redirect::to(uri!(test(1, numbers)))
   |                               ^^^^^^^ the trait `FromUriParam<rocket::http::uri::fmt::Query, _>` is not implemented for `Vec<i32>`
   |
   = help: the following other types implement trait `FromUriParam<P, T>`:
             <bool as FromUriParam<P, bool>>
             <bool as FromUriParam<P, &'x bool>>
             <bool as FromUriParam<P, &'x mut bool>>
             <isize as FromUriParam<P, isize>>
             <isize as FromUriParam<P, &'x isize>>
             <isize as FromUriParam<P, &'x mut isize>>
             <i8 as FromUriParam<P, i8>>
             <i8 as FromUriParam<P, &'x i8>>
           and 149 others
   = note: this error originates in the macro `rocket::rocket_internal_uri` which comes from the expansion of the macro `uri` (in Nightly builds, run with -Z macro-backtrace for more info)

According to the Documentation one should only implement the trait FromUriParam if you intend to provide arguments which differ from the parameters in the given function.

After seeking help in the Matrix room I was asked to open an issue regarding this.

Test Case

use rocket::{response::Redirect, Build, Rocket};

#[macro_use] extern crate rocket;

#[get("/get?<values>")]
fn get(values: Vec<i32>) -> String {
    "hello from get-endpoint.".into()
}

#[get("/redirect")]
fn redirect() -> Redirect {
    let values: Vec<i32> = vec!(1,2,3);
    Redirect::to(uri!(get(values)))
}

#[launch]
fn rocket() -> Rocket<Build> {
    rocket::build().mount("/", routes![get, redirect])
}

#[cfg(test)]
mod test {
    use super::rocket;
    use rocket::local::blocking::Client;
    use rocket::http::Status;

    #[test]
    fn hello_world() {
        let client = Client::tracked(rocket()).expect("valid rocket instance");
        let mut response = client.get(uri!(super::redirect)).dispatch();
        assert_eq!(response.status(), Status::SeeOther);
    }
}

Log Output

ROCKET_LOG_LEVEL=debug cargo test
   Compiling rocket-test v0.1.0 (/tmp/rocket-test)
error[E0277]: the trait bound `Vec<i32>: FromUriParam<rocket::http::uri::fmt::Query, _>` is not satisfied
  --> src/main.rs:13:27
   |
13 |     Redirect::to(uri!(get(values)))
   |                           ^^^^^^ the trait `FromUriParam<rocket::http::uri::fmt::Query, _>` is not implemented for `Vec<i32>`
   |
   = help: the following other types implement trait `FromUriParam<P, T>`:
             <bool as FromUriParam<P, bool>>
             <bool as FromUriParam<P, &'x bool>>
             <bool as FromUriParam<P, &'x mut bool>>
             <isize as FromUriParam<P, isize>>
             <isize as FromUriParam<P, &'x isize>>
             <isize as FromUriParam<P, &'x mut isize>>
             <i8 as FromUriParam<P, i8>>
             <i8 as FromUriParam<P, &'x i8>>
           and 149 others
   = note: this error originates in the macro `rocket::rocket_internal_uri` which comes from the expansion of the macro `uri` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rocket-test` (bin "rocket-test" test) due to previous error

Additional Context

No response

System Checks

  • My bug report relates to functionality.
  • I have tested against the latest Rocket release or a recent git commit.
  • I have tested against the latest stable rustc toolchain.
  • I was unable to find this issue previously reported.
@Unei95 Unei95 added the triage A bug report being investigated label Mar 13, 2024
@SergioBenitez SergioBenitez added deficiency Something doesn't work as well as it could and removed triage A bug report being investigated labels Mar 14, 2024
@SergioBenitez
Copy link
Member

Looks like we're missing some impls here. Work on an improvement now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deficiency Something doesn't work as well as it could
Projects
None yet
Development

No branches or pull requests

2 participants