mirror of
https://github.com/rust-lang/rust.git
synced 2026-01-20 07:50:47 +00:00
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.
35 lines
799 B
Rust
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() {}
|