[pbs-devel] [PATCH proxmox 4/6] schema: de: don't use while where we don't loop

Maximiliano Sandoval m.sandoval at proxmox.com
Wed Feb 28 12:39:18 CET 2024


This code does not loop if-let is the correct pattern.

Fixes the clippy error:

    error: this loop never actually loops
       --> proxmox-schema/src/de/mod.rs:424:9
        |
    424 | /         while let Some(el_range) = next_str_entry(&self.input, &mut self.at, self.has_null) {
    425 | |             if let Some(max) = self.schema.max_length {
    426 | |                 if self.count == max {
    427 | |                     return Err(Error::msg("too many elements"));
    ...   |
    438 | |                 .map(Some);
    439 | |         }
        | |_________^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
        = note: `#[deny(clippy::never_loop)]` on by default

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 proxmox-schema/src/de/mod.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs
index 75b500e5..09ccfeb3 100644
--- a/proxmox-schema/src/de/mod.rs
+++ b/proxmox-schema/src/de/mod.rs
@@ -421,7 +421,7 @@ impl<'de, 'i, 's> de::SeqAccess<'de> for SeqAccess<'de, 'i, 's> {
             return Ok(None);
         }
 
-        while let Some(el_range) = next_str_entry(&self.input, &mut self.at, self.has_null) {
+        if let Some(el_range) = next_str_entry(&self.input, &mut self.at, self.has_null) {
             if let Some(max) = self.schema.max_length {
                 if self.count == max {
                     return Err(Error::msg("too many elements"));
-- 
2.39.2





More information about the pbs-devel mailing list