Skip to content

empty_struct_with_brackets: do not lint code coming from macro expansion #14623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_lints/src/empty_with_brackets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ declare_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM
impl EarlyLintPass for EmptyWithBrackets {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if let ItemKind::Struct(ident, var_data, _) = &item.kind
&& !item.span.from_expansion()
&& has_brackets(var_data)
&& let span_after_ident = item.span.with_lo(ident.span.hi())
&& has_no_fields(cx, var_data, span_after_ident)
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/empty_structs_with_brackets.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ 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() {}
8 changes: 8 additions & 0 deletions tests/ui/empty_structs_with_brackets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ 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() {}