rust/tests/ui/empty_structs_with_brackets.fixed
Samuel Tardieu 4de5b2757d empty_struct_with_brackets: do not lint macro code
Do not attempt to fetch a snippet from expansion. Without this change,
the inside of macros could[*] be shown as the source of the problem.

[*] Due to the way the source code is processed and reparsed in this
macro, the declarative macro has to be located outside the current
source file for the bug to appear. Otherwise, the macro call itself
will be (mis)identified as a potential `struct` field definition and the
lint will not trigger.
2025-05-05 23:19:59 +02:00

35 lines
799 B
Rust

#![warn(clippy::empty_structs_with_brackets)]
#![allow(dead_code)]
pub struct MyEmptyStruct; // should trigger lint
//~^ empty_structs_with_brackets
struct MyEmptyTupleStruct; // should trigger lint
//~^ empty_structs_with_brackets
// should not trigger lint
struct MyCfgStruct {
#[cfg(feature = "thisisneverenabled")]
field: u8,
}
// should not trigger lint
struct MyCfgTupleStruct(#[cfg(feature = "thisisneverenabled")] u8);
// should not trigger lint
struct MyStruct {
field: u8,
}
struct MyTupleStruct(usize, String); // should not trigger lint
struct MySingleTupleStruct(usize); // should not trigger lint
struct MyUnitLikeStruct; // should not trigger lint
macro_rules! empty_struct {
($s:ident) => {
struct $s {}
};
}
empty_struct!(FromMacro);
fn main() {}