drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
Subsystems (4)
Miguel Ojeda
maintainerPATCH 1/1 drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
Starting with Rust 1.100.0 (expected 2026-11-12), Clippy warns:
warning: the loop variable `i` is only used to index `self.decimals`
--> drivers/gpu/drm/drm_panic_qr.rs:410:18
|
410 | for i in 0..len {
| ^^^^^^
|
note: for this index operation
--> drivers/gpu/drm/drm_panic_qr.rs:411:13
|
411 | self.decimals[i] = (chunk % 10) as u8;
| ^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#needless_range_loop
= note: `-W clippy::needless-range-loop` implied by `-W clippy::all`
= help: to override `-W clippy::all` add `#[allow(clippy::needless_range_loop)]`
help: consider using an iterator
|
410 - for i in 0..len {
410 + for <item> in self.decimals.iter_mut().take(len) {
|The lint did not trigger here before because it could not handle arrays behind a field access such as self.decimals -- Clippy was improved to catch those cases [1][2].
Thus clean the warning by iterating over a slice rather than using take() so that an out-of-range len still triggers the same bounds check as the indexed loop.
---
One may want to keep the loop in a shape similar to e.g. the one above, though.
drivers/gpu/drm/drm_panic_qr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_panic_qr.rs +2 -2
@@ -407,8 +407,8 @@ fn push(&mut self, data: u64, len: usize) {for iin (0 ..self.len).rev () { self.decimals[i + len] = self.decimals[i]; } -for iin 0 ..len { - self.decimals[i] = (chunk %10 )as u8 ; +for decimalin &mut self.decimals[..len] { + *decimal = (chunk %10 )as u8 ; chunk =div10 (chunk); } self.len += len;
base-commit: 45c13f3f9e3bb15fd89ff2864c6f627a3b4b4229 --
2.55.0
Quoted 30 lines · Miguel Ojeda
Starting with Rust 1.100.0 (expected 2026-11-12), Clippy warns:
warning: the loop variable `i` is only used to index `self.decimals` --> drivers/gpu/drm/drm_panic_qr.rs:410:18 | 410 | for i in 0..len { | ^^^^^^ | note: for this index operation --> drivers/gpu/drm/drm_panic_qr.rs:411:13 | 411 | self.decimals[i] = (chunk % 10) as u8; | ^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#needless_range_loop = note: `-W clippy::needless-range-loop` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | 410 - for i in 0..len { 410 + for <item> in self.decimals.iter_mut().take(len) { |The lint did not trigger here before because it could not handle arrays behind a field access such as
self.decimals-- Clippy was improved to catch those cases [1][2].Thus clean the warning by iterating over a slice rather than using
take()so that an out-of-rangelenstill triggers the same bounds check as the indexed loop.
Quoted 5 lines
Cc [email protected] # Needed in 6.18.y and later.Assisted-by LLMSigned-off-by Miguel Ojeda <[email protected]>
Quoted 31 lines · Miguel Ojeda
Starting with Rust 1.100.0 (expected 2026-11-12), Clippy warns:
warning: the loop variable `i` is only used to index `self.decimals` --> drivers/gpu/drm/drm_panic_qr.rs:410:18 | 410 | for i in 0..len { | ^^^^^^ | note: for this index operation --> drivers/gpu/drm/drm_panic_qr.rs:411:13 | 411 | self.decimals[i] = (chunk % 10) as u8; | ^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#needless_range_loop = note: `-W clippy::needless-range-loop` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | 410 - for i in 0..len { 410 + for <item> in self.decimals.iter_mut().take(len) { |The lint did not trigger here before because it could not handle arrays behind a field access such as
self.decimals-- Clippy was improved to catch those cases [1][2].Thus clean the warning by iterating over a slice rather than using
take()so that an out-of-rangelenstill triggers the same bounds check as the indexed loop.
Quoted 8 lines
Cc [email protected] # Needed in 6.18.y and later.Assisted-by LLMSigned-off-by Miguel Ojeda <[email protected]>---
One may want to keep the loop in a shape similar to e.g. the one above, though.
Jocelyn: I will likely send another rust-fixes PR during this cycle, so I can put this one there if you agree with it.
Thanks!
Cheers,
Miguel
Jocelyn Falempe
Reviewed-byQuoted 41 lines · Miguel Ojeda
Quoted 31 lines · Miguel Ojeda
Starting with Rust 1.100.0 (expected 2026-11-12), Clippy warns:
warning: the loop variable `i` is only used to index `self.decimals` --> drivers/gpu/drm/drm_panic_qr.rs:410:18 | 410 | for i in 0..len { | ^^^^^^ | note: for this index operation --> drivers/gpu/drm/drm_panic_qr.rs:411:13 | 411 | self.decimals[i] = (chunk % 10) as u8; | ^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#needless_range_loop = note: `-W clippy::needless-range-loop` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | 410 - for i in 0..len { 410 + for <item> in self.decimals.iter_mut().take(len) { |The lint did not trigger here before because it could not handle arrays behind a field access such as
self.decimals-- Clippy was improved to catch those cases [1][2].Thus clean the warning by iterating over a slice rather than using
take()so that an out-of-rangelenstill triggers the same bounds check as the indexed loop.Quoted 8 lines
Cc [email protected] # Needed in 6.18.y and later.Assisted-by LLMSigned-off-by Miguel Ojeda <[email protected]>---
One may want to keep the loop in a shape similar to e.g. the one above, though.
Quoted 2 lines
Jocelyn: I will likely send another rust-fixes PR during this cycle, so I can put this one there if you agree with it.
Sorry for replying late.
That looks good to me, and you can take this patch in the rust-fixes tree.
Quoted 6 lines
Thanks!
Cheers,
Miguel
Miguel Ojeda
AppliedQuoted 31 lines · Miguel Ojeda
Starting with Rust 1.100.0 (expected 2026-11-12), Clippy warns:
warning: the loop variable `i` is only used to index `self.decimals` --> drivers/gpu/drm/drm_panic_qr.rs:410:18 | 410 | for i in 0..len { | ^^^^^^ | note: for this index operation --> drivers/gpu/drm/drm_panic_qr.rs:411:13 | 411 | self.decimals[i] = (chunk % 10) as u8; | ^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#needless_range_loop = note: `-W clippy::needless-range-loop` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::needless_range_loop)]` help: consider using an iterator | 410 - for i in 0..len { 410 + for <item> in self.decimals.iter_mut().take(len) { |The lint did not trigger here before because it could not handle arrays behind a field access such as
self.decimals-- Clippy was improved to catch those cases [1][2].Thus clean the warning by iterating over a slice rather than using
take()so that an out-of-rangelenstill triggers the same bounds check as the indexed loop.
Quoted 5 lines
Cc [email protected] # Needed in 6.18.y and later.Assisted-by LLMSigned-off-by Miguel Ojeda <[email protected]>
Applied to rust-fixes -- thanks everyone!
Cheers,
Miguel