Skip to content

confusing clippy suggestion for zero_repeat_side_effects #14681

@glorv

Description

@glorv

Summary

zero_repeat_side_effects's suggestion is confusing

Reproducer

I tried this code:

fn foo<T>(_s: &[Option<T>]) {}

fn main() {
    foo(&[Some(0i64); 0]);
}

I expected to see this happen:

Instead, this happened:

warning: function or method calls as the initial value in zero-sized array initializers may cause side effects
 --> src/main.rs:4:10
  |
4 |     foo(&[Some(0i64); 0]);
  |          ^^^^^^^^^^^^^^^ help: consider using: `{ Some(0i64); [] as [std::option::Option<i64>; 0] }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#zero_repeat_side_effects
  = note: `#[warn(clippy::zero_repeat_side_effects)]` on by default

If only passed &[] then type T cannot be determined.

But I don't get what { Some(0i64); [] as [std::option::Option<i64>; 0] } refers to, maybe [] as [std::option::Option<i64>; 0]?

Version

rustc 1.88.0-nightly (934880f58 2025-04-09)
binary: rustc
commit-hash: 934880f586f6ac1f952c7090e2a943fcd7775e7b
commit-date: 2025-04-09
host: aarch64-apple-darwin
release: 1.88.0-nightly
LLVM version: 20.1.2

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions