Rocket/core/codegen/tests/ui-fail/route-warnings.rs
Sergio Benitez 4c6562cd29 Drop 'Data' after sending a response, not before.
This allows responses to be sent to the client even when data is only
partially read, significantly improving the experience for the client
from one with a "connection closed" error to one with a proper response.
The consequence is a lifetime in 'Data'.

Though other non-lifetime-introducing solutions exist, the introduction
of a lifetime to 'Data' is a longstanding desire as it prevents
smuggling 'Data' into a longer-lived context. Use of 'Data' in that
context was unspecified with various runtime consequences. The addition
of a lifetime bound by the request prevents this error statically.

In summary, the changes are:
  * Clients receive responses even when data isn't fully read.
  * 'Data' becomes 'Data<'r>'. 'FromData' changes accordingly.
  * Route 'Outcome's are strictly tied to the request lifetime.

Tangentially, the invalid length form field validation error message has
improved to format length in byte units if it exceeds 1024.
2021-06-08 13:26:16 -07:00

27 lines
528 B
Rust

// must-compile-successfully
#[macro_use] extern crate rocket;
// Check for unknown media types.
#[get("/", format = "application/x-custom")]
fn f0() {}
#[get("/", format = "x-custom/plain")]
fn f1() {}
#[get("/", format = "x-custom/x-custom")]
fn f2() {}
// Check if a data argument is used with a usually non-payload bearing method.
#[get("/", data = "<_foo>")]
fn g0(_foo: rocket::Data<'_>) {}
#[head("/", data = "<_foo>")]
fn g1(_foo: rocket::Data<'_>) {}
fn main() {
compile_error!("checking for warnings!")
}