From 4211eb4497cb5368c53c70841e4a0d0989a26574 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 4 May 2020 18:08:00 +0200 Subject: [PATCH] Annotate .unwrap()s --- ruma-api-macros/src/api.rs | 4 ++++ src/lib.rs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ruma-api-macros/src/api.rs b/ruma-api-macros/src/api.rs index bb2d6b8f..876b5ed5 100644 --- a/ruma-api-macros/src/api.rs +++ b/ruma-api-macros/src/api.rs @@ -440,6 +440,8 @@ impl ToTokens for Api { *http_request.uri_mut() = ruma_api::exports::http::uri::Builder::new() .path_and_query(path_and_query.as_str()) .build() + // The only way this can fail is if the path given in the API definition is + // invalid. It is okay to panic in that case. .unwrap(); { #add_headers_to_request } @@ -460,6 +462,8 @@ impl ToTokens for Api { .header(ruma_api::exports::http::header::CONTENT_TYPE, "application/json") #serialize_response_headers .body(#body) + // Since we require header names to come from the `http::header` module, + // this cannot fail. .unwrap(); Ok(response) } diff --git a/src/lib.rs b/src/lib.rs index ed681e3f..2259ba1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,7 +315,9 @@ mod tests { .method(metadata.method) .uri(path) .body(serde_json::to_vec(&request_body)?) - .expect("http request building to succeed"); + // this cannot fail because we don't give user-supplied data to any of the + // builder methods + .unwrap(); Ok(http_request) }