diff --git a/core/codegen/tests/route-ranking.rs b/core/codegen/tests/route-ranking.rs index e6952d44..40aaec33 100644 --- a/core/codegen/tests/route-ranking.rs +++ b/core/codegen/tests/route-ranking.rs @@ -26,16 +26,13 @@ async fn test_ranking() { let mut response = client.get("/0").dispatch().await; assert_eq!(response.body_string().await.unwrap(), "0"); - let request = client.get(format!("/{}", 1 << 8)); - let mut response = request.dispatch().await; + let mut response = client.get(format!("/{}", 1 << 8)).dispatch().await; assert_eq!(response.body_string().await.unwrap(), "1"); - let request = client.get(format!("/{}", 1 << 16)); - let mut response = request.dispatch().await; + let mut response = client.get(format!("/{}", 1 << 16)).dispatch().await; assert_eq!(response.body_string().await.unwrap(), "2"); - let request = client.get(format!("/{}", 1u64 << 32)); - let mut response = request.dispatch().await; + let mut response = client.get(format!("/{}", 1u64 << 32)).dispatch().await; assert_eq!(response.body_string().await.unwrap(), "3"); } diff --git a/core/codegen/tests/route.rs b/core/codegen/tests/route.rs index 0cd6d9d7..d72c1fdc 100644 --- a/core/codegen/tests/route.rs +++ b/core/codegen/tests/route.rs @@ -102,28 +102,26 @@ async fn test_full_route() { let response = client.post(&uri).body(simple).dispatch().await; assert_eq!(response.status(), Status::NotFound); - let request = client.post(format!("/1{}", uri)).body(simple); - let response = request.dispatch().await; + let response = client.post(format!("/1{}", uri)).body(simple).dispatch().await; assert_eq!(response.status(), Status::NotFound); - let request = client + let mut response = client .post(format!("/1{}", uri)) .header(ContentType::JSON) - .body(simple); - let mut response = request.dispatch().await; + .body(simple) + .dispatch().await; assert_eq!(response.body_string().await.unwrap(), format!("({}, {}, {}, {}, {}, {}) ({})", sky, name, "A A", "inside", path, simple, expected_uri)); - let request = client.post(format!("/2{}", uri)).body(simple); - let response = request.dispatch().await; + let response = client.post(format!("/2{}", uri)).body(simple).dispatch().await; assert_eq!(response.status(), Status::NotFound); - let request = client + let mut response = client .post(format!("/2{}", uri)) .header(ContentType::JSON) - .body(simple); - let mut response = request.dispatch().await; + .body(simple) + .dispatch().await; assert_eq!(response.body_string().await.unwrap(), format!("({}, {}, {}, {}, {}, {}) ({})", sky, name, "A A", "inside", path, simple, expected_uri)); diff --git a/core/lib/build.rs b/core/lib/build.rs index e03676c2..0d575016 100644 --- a/core/lib/build.rs +++ b/core/lib/build.rs @@ -3,8 +3,9 @@ use yansi::{Paint, Color::{Red, Yellow, Blue}}; // Specifies the minimum nightly version needed to compile Rocket. -const MIN_DATE: &'static str = "2019-08-20"; -const MIN_VERSION: &'static str = "1.39.0-nightly"; + +const MIN_DATE: &'static str = "2019-11-24"; +const MIN_VERSION: &'static str = "1.41.0-nightly"; macro_rules! err { ($version:expr, $date:expr, $msg:expr) => ( diff --git a/core/lib/src/data/data.rs b/core/lib/src/data/data.rs index 5749e487..b996510c 100644 --- a/core/lib/src/data/data.rs +++ b/core/lib/src/data/data.rs @@ -171,8 +171,7 @@ impl Data { pub fn stream_to_file + Send + Unpin + 'static>(self, path: P) -> impl Future> { Box::pin(async move { let mut file = tokio::fs::File::create(path).await?; - let streaming = self.stream_to(&mut file); - streaming.await + self.stream_to(&mut file).await }) } diff --git a/core/lib/src/local/request.rs b/core/lib/src/local/request.rs index cfed21e0..02cbf4d3 100644 --- a/core/lib/src/local/request.rs +++ b/core/lib/src/local/request.rs @@ -348,8 +348,7 @@ impl<'c> LocalRequest<'c> { #[inline(always)] pub async fn dispatch(mut self) -> LocalResponse<'c> { let r = self.long_lived_request(); - let dispatching = LocalRequest::_dispatch(self.client, r, self.request, &self.uri, self.data); - dispatching.await + LocalRequest::_dispatch(self.client, r, self.request, &self.uri, self.data).await } /// Dispatches the request, returning the response. diff --git a/core/lib/tests/form_value_decoding-issue-82.rs b/core/lib/tests/form_value_decoding-issue-82.rs index 265ca7f1..b9305109 100644 --- a/core/lib/tests/form_value_decoding-issue-82.rs +++ b/core/lib/tests/form_value_decoding-issue-82.rs @@ -22,10 +22,10 @@ mod tests { async fn check_decoding(raw: &str, decoded: &str) { let client = Client::new(rocket::ignite().mount("/", routes![bug])).unwrap(); - let request = client.post("/") + let mut response = client.post("/") .header(ContentType::Form) - .body(format!("form_data={}", raw)); - let mut response = request.dispatch().await; + .body(format!("form_data={}", raw)) + .dispatch().await; assert_eq!(response.status(), Status::Ok); assert_eq!(Some(decoded.to_string()), response.body_string().await); diff --git a/core/lib/tests/segments-issues-41-86.rs b/core/lib/tests/segments-issues-41-86.rs index c9bbbbce..dac00ef3 100644 --- a/core/lib/tests/segments-issues-41-86.rs +++ b/core/lib/tests/segments-issues-41-86.rs @@ -47,8 +47,7 @@ mod tests { "/static", "/point/static"] { let path = "this/is/the/path/we/want"; - let request = client.get(format!("{}/{}", prefix, path)); - let mut response = request.dispatch().await; + let mut response = client.get(format!("{}/{}", prefix, path)).dispatch().await; assert_eq!(response.body_string().await, Some(path.into())); } } diff --git a/core/lib/tests/strict_and_lenient_forms.rs b/core/lib/tests/strict_and_lenient_forms.rs index dbc0a155..e027fa83 100644 --- a/core/lib/tests/strict_and_lenient_forms.rs +++ b/core/lib/tests/strict_and_lenient_forms.rs @@ -34,18 +34,18 @@ mod strict_and_lenient_forms_tests { #[rocket::async_test] async fn test_strict_form() { let client = client(); - let request = client.post("/strict") + let mut response = client.post("/strict") .header(ContentType::Form) - .body(format!("field={}", FIELD_VALUE)); - let mut response = request.dispatch().await; + .body(format!("field={}", FIELD_VALUE)) + .dispatch().await; assert_eq!(response.status(), Status::Ok); assert_eq!(response.body_string().await, Some(FIELD_VALUE.into())); - let request = client.post("/strict") + let response = client.post("/strict") .header(ContentType::Form) - .body(format!("field={}&extra=whoops", FIELD_VALUE)); - let response = request.dispatch().await; + .body(format!("field={}&extra=whoops", FIELD_VALUE)) + .dispatch().await; assert_eq!(response.status(), Status::UnprocessableEntity); } @@ -53,18 +53,18 @@ mod strict_and_lenient_forms_tests { #[rocket::async_test] async fn test_lenient_form() { let client = client(); - let request = client.post("/lenient") + let mut response = client.post("/lenient") .header(ContentType::Form) - .body(format!("field={}", FIELD_VALUE)); - let mut response = request.dispatch().await; + .body(format!("field={}", FIELD_VALUE)) + .dispatch().await; assert_eq!(response.status(), Status::Ok); assert_eq!(response.body_string().await, Some(FIELD_VALUE.into())); - let request = client.post("/lenient") + let mut response = client.post("/lenient") .header(ContentType::Form) - .body(format!("field={}&extra=whoops", FIELD_VALUE)); - let mut response = request.dispatch().await; + .body(format!("field={}&extra=whoops", FIELD_VALUE)) + .dispatch().await; assert_eq!(response.status(), Status::Ok); assert_eq!(response.body_string().await, Some(FIELD_VALUE.into())); diff --git a/core/lib/tests/uri-percent-encoding-issue-808.rs b/core/lib/tests/uri-percent-encoding-issue-808.rs index 076b544f..e1f4586a 100644 --- a/core/lib/tests/uri-percent-encoding-issue-808.rs +++ b/core/lib/tests/uri-percent-encoding-issue-808.rs @@ -52,8 +52,7 @@ mod tests { async fn uri_percent_encoding_get() { let client = Client::new(rocket()).unwrap(); let name = Uri::percent_encode(NAME); - let request = client.get(format!("/hello/{}", name)); - let mut response = request.dispatch().await; + let mut response = client.get(format!("/hello/{}", name)).dispatch().await; assert_eq!(response.status(), Status::Ok); assert_eq!(response.body_string().await.unwrap(), format!("Hello, {}!", NAME)); } diff --git a/examples/errors/src/tests.rs b/examples/errors/src/tests.rs index bfe1aa7f..b30ca28d 100644 --- a/examples/errors/src/tests.rs +++ b/examples/errors/src/tests.rs @@ -7,8 +7,7 @@ async fn test(uri: &str, status: Status, body: String) { .register(catchers![super::not_found]); let client = Client::new(rocket).unwrap(); - let request = client.get(uri); - let mut response = request.dispatch().await; + let mut response = client.get(uri).dispatch().await; assert_eq!(response.status(), status); assert_eq!(response.body_string().await, Some(body)); } @@ -17,8 +16,7 @@ async fn test(uri: &str, status: Status, body: String) { async fn test_hello() { let (name, age) = ("Arthur", 42); let uri = format!("/hello/{}/{}", name, age); - let expected = format!("Hello, {} year old named {}!", age, name); - test(&uri, Status::Ok, expected).await; + test(&uri, Status::Ok, format!("Hello, {} year old named {}!", age, name)).await; } #[rocket::async_test] diff --git a/examples/hello_person/src/tests.rs b/examples/hello_person/src/tests.rs index 0438626c..02a32ffa 100644 --- a/examples/hello_person/src/tests.rs +++ b/examples/hello_person/src/tests.rs @@ -18,9 +18,8 @@ async fn test_404(uri: &'static str) { #[rocket::async_test] async fn test_hello() { for &(name, age) in &[("Mike", 22), ("Michael", 80), ("A", 0), ("a", 127)] { - let uri = format!("/hello/{}/{}", name, age); - let expected = format!("Hello, {} year old named {}!", age, name); - test(uri, expected).await; + test(format!("/hello/{}/{}", name, age), + format!("Hello, {} year old named {}!", age, name)).await; } } @@ -34,7 +33,6 @@ async fn test_failing_hello() { #[rocket::async_test] async fn test_hi() { for name in &["Mike", "A", "123", "hi", "c"] { - let uri = format!("/hello/{}", name); - test(uri, name.to_string()).await; + test(format!("/hello/{}", name), name.to_string()).await; } } diff --git a/examples/manual_routes/src/main.rs b/examples/manual_routes/src/main.rs index bff7c115..31c1c209 100644 --- a/examples/manual_routes/src/main.rs +++ b/examples/manual_routes/src/main.rs @@ -52,8 +52,7 @@ fn upload<'r>(req: &'r Request, data: Data) -> HandlerFuture<'r> { let file = File::create(env::temp_dir().join("upload.txt")).await; if let Ok(file) = file { if let Ok(n) = data.stream_to(file).await { - let response = format!("OK: {} bytes uploaded.", n); - return Outcome::from(req, response).await; + return Outcome::from(req, format!("OK: {} bytes uploaded.", n)).await; } println!(" => Failed copying."); @@ -94,8 +93,7 @@ impl Handler for CustomHandler { .or_forward(data); let id = try_outcome!(id_outcome); - let response = format!("{} - {}", self_data, id); - Outcome::from(req, response).await + Outcome::from(req, format!("{} - {}", self_data, id)).await }) } } diff --git a/examples/manual_routes/src/tests.rs b/examples/manual_routes/src/tests.rs index 548146d1..77af31a8 100644 --- a/examples/manual_routes/src/tests.rs +++ b/examples/manual_routes/src/tests.rs @@ -5,8 +5,7 @@ use rocket::http::{ContentType, Status}; fn test(uri: &str, content_type: ContentType, status: Status, body: String) { rocket::async_test(async move { let client = Client::new(rocket()).unwrap(); - let request = client.get(uri).header(content_type); - let mut response = request.dispatch().await; + let mut response = client.get(uri).header(content_type).dispatch().await; assert_eq!(response.status(), status); assert_eq!(response.body_string().await, Some(body)); }) diff --git a/examples/pastebin/src/tests.rs b/examples/pastebin/src/tests.rs index 675faa40..a51025f5 100644 --- a/examples/pastebin/src/tests.rs +++ b/examples/pastebin/src/tests.rs @@ -25,8 +25,7 @@ async fn upload_paste(client: &Client, body: &str) -> String { } async fn download_paste(client: &Client, id: &str) -> String { - let request = client.get(format!("/{}", id)); - let mut response = request.dispatch().await; + let mut response = client.get(format!("/{}", id)).dispatch().await; assert_eq!(response.status(), Status::Ok); response.body_string().await.unwrap() } diff --git a/examples/query_params/src/tests.rs b/examples/query_params/src/tests.rs index c8594bee..5d5bf362 100644 --- a/examples/query_params/src/tests.rs +++ b/examples/query_params/src/tests.rs @@ -5,9 +5,8 @@ use rocket::http::Status; macro_rules! run_test { ($query:expr, |$response:ident| $body:expr) => ({ let client = Client::new(rocket()).unwrap(); - let request = client.get(format!("/hello{}", $query)); #[allow(unused_mut)] - let mut $response = request.dispatch().await; + let mut $response = client.get(format!("/hello{}", $query)).dispatch().await; $body }) } diff --git a/examples/ranking/src/tests.rs b/examples/ranking/src/tests.rs index b9605dde..79f18d08 100644 --- a/examples/ranking/src/tests.rs +++ b/examples/ranking/src/tests.rs @@ -3,16 +3,15 @@ use rocket::local::Client; async fn test(uri: String, expected: String) { let rocket = rocket::ignite().mount("/", routes![super::hello, super::hi]); let client = Client::new(rocket).unwrap(); - let mut response = client.get(uri).dispatch().await; + let mut response = client.get(&uri).dispatch().await; assert_eq!(response.body_string().await, Some(expected)); } #[rocket::async_test] async fn test_hello() { for &(name, age) in &[("Mike", 22), ("Michael", 80), ("A", 0), ("a", 127)] { - let uri = format!("/hello/{}/{}", name, age); - let expected = format!("Hello, {} year old named {}!", age, name); - test(uri, expected).await; + test(format!("/hello/{}/{}", name, age), + format!("Hello, {} year old named {}!", age, name)).await; } } @@ -20,15 +19,13 @@ async fn test_hello() { async fn test_failing_hello_hi() { // Invalid integers. for &(name, age) in &[("Mike", 1000), ("Michael", 128), ("A", -800), ("a", -200)] { - let uri = format!("/hello/{}/{}", name, age); - let expected = format!("Hi {}! Your age ({}) is kind of funky.", name, age); - test(uri, expected).await; + test(format!("/hello/{}/{}", name, age), + format!("Hi {}! Your age ({}) is kind of funky.", name, age)).await; } // Non-integers. for &(name, age) in &[("Mike", "!"), ("Michael", "hi"), ("A", "blah"), ("a", "0-1")] { - let uri = format!("/hello/{}/{}", name, age); - let expected = format!("Hi {}! Your age ({}) is kind of funky.", name, age); - test(uri, expected).await; + test(format!("/hello/{}/{}", name, age), + format!("Hi {}! Your age ({}) is kind of funky.", name, age)).await; } } diff --git a/examples/session/src/tests.rs b/examples/session/src/tests.rs index d32430a7..12a2d69b 100644 --- a/examples/session/src/tests.rs +++ b/examples/session/src/tests.rs @@ -14,10 +14,10 @@ fn user_id_cookie(response: &Response<'_>) -> Option> { } async fn login(client: &Client, user: &str, pass: &str) -> Option> { - let request = client.post("/login") + let response = client.post("/login") .header(ContentType::Form) - .body(format!("username={}&password={}", user, pass)); - let response = request.dispatch().await; + .body(format!("username={}&password={}", user, pass)) + .dispatch().await; user_id_cookie(&response) } diff --git a/examples/todo/src/tests.rs b/examples/todo/src/tests.rs index 0e6a3fe2..56d5f5b3 100644 --- a/examples/todo/src/tests.rs +++ b/examples/todo/src/tests.rs @@ -49,8 +49,7 @@ fn test_insertion_deletion() { // Issue a request to delete the task. let id = new_tasks[0].id.unwrap(); - let request = client.delete(format!("/todo/{}", id)); - request.dispatch().await; + client.delete(format!("/todo/{}", id)).dispatch().await; // Ensure it's gone. let final_tasks = Task::all(&conn).unwrap(); @@ -74,13 +73,11 @@ fn test_toggle() { assert_eq!(task.completed, false); // Issue a request to toggle the task; ensure it is completed. - let request = client.put(format!("/todo/{}", task.id.unwrap())); - request.dispatch().await; + client.put(format!("/todo/{}", task.id.unwrap())).dispatch().await; assert_eq!(Task::all(&conn).unwrap()[0].completed, true); // Issue a request to toggle the task; ensure it's not completed again. - let request = client.put(format!("/todo/{}", task.id.unwrap())); - request.dispatch().await; + client.put(format!("/todo/{}", task.id.unwrap())).dispatch().await; assert_eq!(Task::all(&conn).unwrap()[0].completed, false); }) } @@ -97,10 +94,10 @@ fn test_many_insertions() { for i in 0..ITER { // Issue a request to insert a new task with a random description. let desc: String = thread_rng().sample_iter(&Alphanumeric).take(12).collect(); - let request = client.post("/todo") + client.post("/todo") .header(ContentType::Form) - .body(format!("description={}", desc)); - request.dispatch().await; + .body(format!("description={}", desc)) + .dispatch().await; // Record the description we choose for this iteration. descs.insert(0, desc);