Reduce 'data' use on non-payload bearing methods error to warning.

Resolves #622.
This commit is contained in:
Sergio Benitez 2018-06-02 19:05:20 +02:00
parent 2f2e0b83fc
commit 74a5970c9d
3 changed files with 10 additions and 7 deletions

View File

@ -109,9 +109,11 @@ 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))
ecx.struct_span_warn(data_param.span, "`data` route parameter \
used with non-payload-supporting method")
.note(&format!("'{}' does not typically support payloads", method.node))
.note("the 'format' attribute parameter will match against \
the 'Accept' header")
.emit();
}
}

View File

@ -5,3 +5,5 @@ extern crate rocket;
#[get("/", data = "<something>")]
fn get(something: rocket::Data) -> &'static str { "hi" }
fn main() { }

View File

@ -1,10 +1,9 @@
error: `data` route parameters can only be used with payload supporting methods
warning: `data` route parameter used with non-payload-supporting method
--> $DIR/data-without-post.rs:6:12
|
6 | #[get("/", data = "<something>")]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: 'GET' does not support payloads
error: aborting due to previous error
= note: 'GET' does not typically support payloads
= note: the 'format' attribute parameter will match against the 'Accept' header