Annotate .unwrap()s

This commit is contained in:
Jonas Platte 2020-05-04 18:08:00 +02:00
parent fb265db5eb
commit 4211eb4497
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
2 changed files with 7 additions and 1 deletions

View File

@ -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)
}

View File

@ -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)
}