Disallow use of data parameter with non-payload methods.

This commit is contained in:
Sergio Benitez 2016-10-25 16:42:10 +02:00
parent fb67681adc
commit 25d55b4b0f
4 changed files with 25 additions and 3 deletions

View File

@ -104,6 +104,16 @@ impl RouteParams {
}
}
// Sanity check: `data` should only be used with payload methods.
if let Some(ref data_param) = data {
if !method.node.supports_payload() {
ecx.struct_span_err(data_param.span, "`data` route parameters \
can only be used with payload supporting methods")
.note(&format!("'{}' does not support payloads", method.node))
.emit();
}
}
RouteParams {
method: method,
path: path,

View File

@ -0,0 +1,12 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
use rocket::Data;
#[get("/", data = "<something>")]
//~^ ERROR payload supporting methods
fn get(something: Data) -> &'static str { "hi" }
fn main() { }

View File

@ -7,7 +7,7 @@ fn get(other: &str) -> &'static str { "hi" } //~ ERROR isn't in the function
#[get("/a?<r>")] //~ ERROR 'r' is declared
fn get1() -> &'static str { "hi" } //~ ERROR isn't in the function
#[get("/a", data = "<test>")] //~ ERROR 'test' is declared
fn get2() -> &'static str { "hi" } //~ ERROR isn't in the function
#[post("/a", data = "<test>")] //~ ERROR 'test' is declared
fn post() -> &'static str { "hi" } //~ ERROR isn't in the function
fn main() { }

View File

@ -7,9 +7,9 @@ use http::hyper::{header, FreshHyperResponse, StatusCode};
use outcome::{self, IntoOutcome};
use outcome::Outcome::*;
/// Type alias for the `Outcome` of a `Responder`.
pub type Outcome<'a> = outcome::Outcome<(), (), (StatusCode, FreshHyperResponse<'a>)>;
impl<'a, T, E> IntoOutcome<(), (), (StatusCode, FreshHyperResponse<'a>)> for Result<T, E> {
fn into_outcome(self) -> Outcome<'a> {
match self {