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:
- caddr is bound via let as mutable:
let mut caddr = (addr as usize) + (dev.caps_ptr as usize)
. -
caddr
is then read, multiple times, irrespective of copying or cloning. -
caddr
is updated via+=
, which is equivalent tocaddr = 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.