Why Clippy says this loop will never actually loop?

I think this is a Clippy error, because everything works as expected, but I can't stop guessing if there is a subtle error in my code:

pub async fn run(mut self) {
    tracing::info!("Redis host task started");
    'exit: loop {
        let mut evt_connection = self.get_redis_connection().await;
        loop {
            tokio::select! {
                // Process messages from OPTAs.
                Some(msg) = self.rx.recv() => {
                    match msg {
                        RedisHostMessage::Shutdown => {
                            tracing::info!("Redis host task stopped");
                            break 'exit;
                        }
                        // Other match arms that do stuff here, but no break or continue.
                    }
                }
                result = ops::wait_event(evt_connection.as_mut()) => {
                    match result {
                        // As above, not break or continue here.
                    }
                }
            }
        }
    }
}

async fn get_redis_connection(&self) -> Option<ConnectionManager> {
    match self.redis_client.get_connection_manager().await {
        Ok(connection) => Some(connection),
        Err(_) => {
            tracing::warn!("could not create connection to redis server");
            None
        }
    }
}

And the Clippy error:

error: this loop never actually loops
  --> services/opta-receiver/src/storage/redis.rs:29:9
   |
29 | /         'exit: loop {
30 | |             let mut evt_connection = self.get_redis_connection().await;
31 | |             loop {
32 | |                 tokio::select! {
...  |
56 | |         }
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.99.0/index.html#never_loop
   = note: `#[deny(clippy::never_loop)]` on by default

Ideas?

Clippy is telling you that the outer loop 'exit: loop { will only ever run once, because the only way out of the inner loop (loop { tokio::select!) is via break 'exit, which leaves both loops at once.

Either you need something that breaks you out of the inner loop (which will cause you to retry at let mut evt_connection), or you should move let mut evt_connection out of the loop, and remove the inner loop completely. Either of those will silence Clippy.

There’s only one way to break from the inner loop, and that one also breaks from the outer loop. Thus the outer loop never actually loops, only the inner loop does.

@farnz, @jdahlstrom thank you for the explanation but then I don't understand how my application works at all. The code correctly receives and process multiple messages via self.rx.recv()until it receives the shutdown message and breaks out of the loop. If the inner loop would execute only once how would that be possible? Note that I shortened the code but there are other match arms that do real work and don't break, as explained in the comment.

No, sorry, it is clear. It's the outer loop that's execute once. I had some code to recover from a broken connection and I needed 2 loops but I refactored and now the external one isn't needed anymore. :confused:

Thank you!