Skip to content

trailing_empty_array triggers inside of macro generated code #16754

@stefnotch

Description

@stefnotch

Summary

I am using Salsa along with Rust Analyzer's query-group-macro.

Lint Name

trailing_empty_array

Reproducer

I tried this code. Or at least that's a relatively minimal reproducer extracted from wgsl-analyzer:

[package]
name = "clippy-issue"
version = "0.1.0"
edition = "2024"

[dependencies]
query-group = { package = "query-group-macro", git = "https://github.com/rust-lang/rust-analyzer", rev = "a31e10a2fdc585e9d7ea0857cacfd322dd478070", version = "0.0.0" }
salsa = { version = "0.22.0", default-features = true, features = [
  "macros",
  "salsa_unstable"
] }
salsa-macros = "0.22.0"
// lib.rs
#![deny(clippy::trailing_empty_array)]
#![allow(clippy::drop_non_drop)]

#[salsa::input]
pub struct MyKey {
    pub value: u32,
}

#[derive(PartialEq, Eq, Hash, Clone, salsa_macros::Supertype)]
pub enum KeyWithoutDrop {
    Foo(MyKey),
}

#[query_group::query_group(DefDatabaseStorage)]
pub trait RootQueryDb: salsa::Database {
    #[salsa::invoke(parse)]
    fn parse(&self, key: MyKey) -> u32;

    #[salsa::invoke(query)]
    fn function_data(&self, key: KeyWithoutDrop) -> u32;
}

fn parse(database: &dyn RootQueryDb, key: MyKey) -> u32 {
    key.value(database)
}

#[allow(clippy::needless_pass_by_value)]
fn query(database: &dyn RootQueryDb, key: KeyWithoutDrop) -> u32 {
    match key {
        KeyWithoutDrop::Foo(editioned_file_id) => editioned_file_id.value(database),
    }
}

I saw this happen:

C:\git\graphics\clippy-issue> cargo clippy                                                                                                                                                               
    Checking clippy-issue v0.1.0 (C:\git\graphics\clippy-issue)
error: trailing zero-sized array in a struct which is not marked with a `repr` attribute
  --> src\lib.rs:14:1
   |
14 | #[query_group::query_group(DefDatabaseStorage)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider annotating `_::builder::Builder_` with `#[repr(C)]` or another `repr` attribute
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#trailing_empty_array
note: the lint level is defined here
  --> src\lib.rs:1:9
   |
 1 | #![deny(clippy::trailing_empty_array)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the macro `salsa::plumbing::setup_input_struct` which comes from the expansion of the attribute macro `salsa_macros::input` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `clippy-issue` (lib) due to 1 previous error

I expected to see no warnings. It's macro generated code, I don't know how I could possibly fix it.

Version

rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-pc-windows-msvc
release: 1.94.0
LLVM version: 21.1.8

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions