Modify lint unused_assignments/confusion on specifically what this means

I believe the unused_assignments lint is far too strict on the definition of "reading" an assigned variable. In programming, reading a variable is simply using it somewhere -- because that causes a memory read to occur. Therefore, the following code:

                            if read_word(addr as usize, STATUS).get_bit(4) {
                            info!("Device implements capabilities list, scanning");
                            let mut caddr = (addr as usize) + (dev.caps_ptr as usize);
                            loop {
                            if read_word(caddr, 0x0).get_bits(8 .. 16) == 0x0 {
                            break;
                            }
                            }
                            info!("Discovered capability ID {:X} at addr {:X}", read_word(caddr, 0x0).get_bits(0 .. 8), caddr);
                            caddr += read_word(caddr, 0x0).get_bits(8 .. 16) as usize;
                            }

Should qualify as a read:

  1. caddr is bound via let as mutable: let mut caddr = (addr as usize) + (dev.caps_ptr as usize).
  2. caddr is then read, multiple times, irrespective of copying or cloning.
  3. caddr is updated via +=, which is equivalent to caddr = caddr + .... This, then, also qualifies as a read.

I may be really confused and may be missing something, but last time I checked, a variable being "read" was any kind of memory access to that variable. Is there an explanation for this strict definitionf of "reading" a variable (and therefore causing rust to complain that this variable is never read, despite the fact that it is), or should this lint be altered concerning its definition of "reading" a variable? Because I'm honestly confused here and I don't know how to satisfy it without forcing an allowance, and I don't want to do that.

Update: Apologies; I just noticed a typo in my code and that explains a lot. Whoops! I feel stupid now. Lmao

1 Like