All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
@ 2026-08-26 14:56 Miguel Ojeda
  2026-08-27  1:36 ` Alexandre Courbot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Miguel Ojeda @ 2026-08-26 14:56 UTC (permalink / raw)
  To: Jocelyn Falempe, Javier Martinez Canillas, Miguel Ojeda
  Cc: dri-devel, rust-for-linux, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, stable

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.

Cc: stable@vger.kernel.org # Needed in 6.18.y and later.
Link: https://github.com/rust-lang/rust-clippy/issues/16631 [1]
Link: https://github.com/rust-lang/rust-clippy/pull/16634 [2]
Assisted-by: LLM
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
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(-)

diff --git a/drivers/gpu/drm/drm_panic_qr.rs b/drivers/gpu/drm/drm_panic_qr.rs
index ac27e86c601c..4d7eb75a3afc 100644
--- a/drivers/gpu/drm/drm_panic_qr.rs
+++ b/drivers/gpu/drm/drm_panic_qr.rs
@@ -407,8 +407,8 @@ fn push(&mut self, data: u64, len: usize) {
         for i in (0..self.len).rev() {
             self.decimals[i + len] = self.decimals[i];
         }
-        for i in 0..len {
-            self.decimals[i] = (chunk % 10) as u8;
+        for decimal in &mut self.decimals[..len] {
+            *decimal = (chunk % 10) as u8;
             chunk = div10(chunk);
         }
         self.len += len;

base-commit: 45c13f3f9e3bb15fd89ff2864c6f627a3b4b4229
--
2.55.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
  2026-08-26 14:56 [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0 Miguel Ojeda
@ 2026-08-27  1:36 ` Alexandre Courbot
  2026-08-31 17:54 ` Miguel Ojeda
  2026-09-03 22:55 ` Miguel Ojeda
  2 siblings, 0 replies; 5+ messages in thread
From: Alexandre Courbot @ 2026-08-27  1:36 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Jocelyn Falempe, Javier Martinez Canillas, dri-devel,
	rust-for-linux, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Onur Özkan, stable

On Wed Aug 26, 2026 at 11:56 PM JST, Miguel Ojeda wrote:
> 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.
>
> Cc: stable@vger.kernel.org # Needed in 6.18.y and later.
> Link: https://github.com/rust-lang/rust-clippy/issues/16631 [1]
> Link: https://github.com/rust-lang/rust-clippy/pull/16634 [2]
> Assisted-by: LLM
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
  2026-08-26 14:56 [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0 Miguel Ojeda
  2026-08-27  1:36 ` Alexandre Courbot
@ 2026-08-31 17:54 ` Miguel Ojeda
  2026-09-03 22:08   ` Jocelyn Falempe
  2026-09-03 22:55 ` Miguel Ojeda
  2 siblings, 1 reply; 5+ messages in thread
From: Miguel Ojeda @ 2026-08-31 17:54 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Jocelyn Falempe, Javier Martinez Canillas, dri-devel,
	rust-for-linux, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, stable

On Wed, Aug 26, 2026 at 4:56 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> 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.
>
> Cc: stable@vger.kernel.org # Needed in 6.18.y and later.
> Link: https://github.com/rust-lang/rust-clippy/issues/16631 [1]
> Link: https://github.com/rust-lang/rust-clippy/pull/16634 [2]
> Assisted-by: LLM
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
> ---
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
  2026-08-31 17:54 ` Miguel Ojeda
@ 2026-09-03 22:08   ` Jocelyn Falempe
  0 siblings, 0 replies; 5+ messages in thread
From: Jocelyn Falempe @ 2026-09-03 22:08 UTC (permalink / raw)
  To: Miguel Ojeda, Miguel Ojeda
  Cc: Javier Martinez Canillas, dri-devel, rust-for-linux, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan, stable

On 31/08/2026 19:54, Miguel Ojeda wrote:
> On Wed, Aug 26, 2026 at 4:56 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>>
>> 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.
>>
>> Cc: stable@vger.kernel.org # Needed in 6.18.y and later.
>> Link: https://github.com/rust-lang/rust-clippy/issues/16631 [1]
>> Link: https://github.com/rust-lang/rust-clippy/pull/16634 [2]
>> Assisted-by: LLM
>> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
>> ---
>> 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.

Sorry for replying late.
That looks good to me, and you can take this patch in the rust-fixes tree.

Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
> 
> Thanks!
> 
> Cheers,
> Miguel
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0
  2026-08-26 14:56 [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0 Miguel Ojeda
  2026-08-27  1:36 ` Alexandre Courbot
  2026-08-31 17:54 ` Miguel Ojeda
@ 2026-09-03 22:55 ` Miguel Ojeda
  2 siblings, 0 replies; 5+ messages in thread
From: Miguel Ojeda @ 2026-09-03 22:55 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Jocelyn Falempe, Javier Martinez Canillas, dri-devel,
	rust-for-linux, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, stable

On Wed, Aug 26, 2026 at 4:56 PM Miguel Ojeda <ojeda@kernel.org> wrote:
>
> 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.
>
> Cc: stable@vger.kernel.org # Needed in 6.18.y and later.
> Link: https://github.com/rust-lang/rust-clippy/issues/16631 [1]
> Link: https://github.com/rust-lang/rust-clippy/pull/16634 [2]
> Assisted-by: LLM
> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Applied to `rust-fixes` -- thanks everyone!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-03 22:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-26 14:56 [PATCH] drm/panic: clean new `clippy::needless_range_loop` lint for Rust 1.100.0 Miguel Ojeda
2026-08-27  1:36 ` Alexandre Courbot
2026-08-31 17:54 ` Miguel Ojeda
2026-09-03 22:08   ` Jocelyn Falempe
2026-09-03 22:55 ` Miguel Ojeda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.