Open
Description
Code
pub async fn get(client: &reqwest::Client, params: &[(&str, &str)]) -> String {
loop {
let response = client.get("https://example.com")
.query(params).send().await.unwrap();
if response.status().is_success() {
return response.text().await.unwrap();
}
assert!(response.status() == reqwest::StatusCode::TOO_MANY_REQUESTS);
}
unreachable!();
}
Current output
Compiling playground v0.0.1 (/playground)
warning: unreachable statement
--> src/lib.rs:10:5
|
2 | / loop {
3 | | let response = client.get("https://example.com")
4 | | .query(params).send().await.unwrap();
5 | | if response.status().is_success() {
... |
8 | | assert!(response.status() == reqwest::StatusCode::TOO_MANY_REQUESTS);
9 | | }
| |_____- any code following this expression is unreachable
10 | unreachable!();
| ^^^^^^^^^^^^^^ unreachable statement
|
= note: `#[warn(unreachable_code)]` on by default
= note: this warning originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: `playground` (lib) generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 1.11s
Desired output
There should be no warning
Rationale and extra context
Code above is based on my actual production code. The intention is this: continue issuing requests as long as we get TOO_MANY_REQUESTS. When we get SUCCESS, return from the function. I put unreachable!
to the end intentionally: to make sure that that line is actually unreachable. I. e. I want to get panic if I'm wrong.
In this particular example rustc can prove that that piece is unreachable and thus give me a warning. But I don't like it. I don't want to remove unreachable!
. It is present for a reason.
Here is even more reduced version: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e90f7dbeb04fd15ed2ae6354cb158fce (so that you can see that async and reqwest are not related here)
Other cases
No response
Anything else?
No response