diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1e081e839a..0aa6a0197624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3263,6 +3263,7 @@ Released 2018-09-13 [`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum [`empty_line_after_outer_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr [`empty_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop +[`empty_structs_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_structs_with_brackets [`enum_clike_unportable_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_clike_unportable_variant [`enum_glob_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_glob_use [`enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names diff --git a/clippy_lints/src/empty_structs_with_brackets.rs b/clippy_lints/src/empty_structs_with_brackets.rs new file mode 100644 index 000000000000..fdeac8d82557 --- /dev/null +++ b/clippy_lints/src/empty_structs_with_brackets.rs @@ -0,0 +1,99 @@ +use clippy_utils::{diagnostics::span_lint_and_then, source::snippet_opt}; +use rustc_ast::ast::{Item, ItemKind, VariantData}; +use rustc_errors::Applicability; +use rustc_lexer::TokenKind; +use rustc_lint::{EarlyContext, EarlyLintPass}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::Span; + +declare_clippy_lint! { + /// ### What it does + /// Finds structs without fields (a so-called "empty struct") that are declared with brackets. + /// + /// ### Why is this bad? + /// Empty brackets after a struct declaration can be omitted. + /// + /// ### Example + /// ```rust + /// struct Cookie {} + /// ``` + /// Use instead: + /// ```rust + /// struct Cookie; + /// ``` + #[clippy::version = "1.62.0"] + pub EMPTY_STRUCTS_WITH_BRACKETS, + restriction, + "finds struct declarations with empty brackets" +} +declare_lint_pass!(EmptyStructsWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS]); + +impl EarlyLintPass for EmptyStructsWithBrackets { + fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { + let span_after_ident = item.span.with_lo(item.ident.span.hi()); + + if let ItemKind::Struct(var_data, _) = &item.kind + && has_brackets(var_data) + && has_no_fields(cx, var_data, span_after_ident) { + span_lint_and_then( + cx, + EMPTY_STRUCTS_WITH_BRACKETS, + span_after_ident, + "found empty brackets on struct declaration", + |diagnostic| { + diagnostic.span_suggestion_hidden( + span_after_ident, + "remove the brackets", + ";".to_string(), + Applicability::MachineApplicable); + }, + ); + } + } +} + +fn has_no_ident_token(braces_span_str: &str) -> bool { + !rustc_lexer::tokenize(braces_span_str).any(|t| t.kind == TokenKind::Ident) +} + +fn has_brackets(var_data: &VariantData) -> bool { + !matches!(var_data, VariantData::Unit(_)) +} + +fn has_no_fields(cx: &EarlyContext<'_>, var_data: &VariantData, braces_span: Span) -> bool { + if !var_data.fields().is_empty() { + return false; + } + + // there might still be field declarations hidden from the AST + // (conditionaly compiled code using #[cfg(..)]) + + let Some(braces_span_str) = snippet_opt(cx, braces_span) else { + return false; + }; + + has_no_ident_token(braces_span_str.as_ref()) +} + +#[cfg(test)] +mod unit_test { + use super::*; + + #[test] + fn test_has_no_ident_token() { + let input = "{ field: u8 }"; + assert!(!has_no_ident_token(input)); + + let input = "(u8, String);"; + assert!(!has_no_ident_token(input)); + + let input = " { + // test = 5 + } + "; + assert!(has_no_ident_token(input)); + + let input = " ();"; + assert!(has_no_ident_token(input)); + } +} diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index e3161795139d..bba3cae45f5e 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -129,6 +129,7 @@ store.register_lints(&[ duration_subsec::DURATION_SUBSEC, else_if_without_else::ELSE_IF_WITHOUT_ELSE, empty_enum::EMPTY_ENUM, + empty_structs_with_brackets::EMPTY_STRUCTS_WITH_BRACKETS, entry::MAP_ENTRY, enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, enum_variants::ENUM_VARIANT_NAMES, diff --git a/clippy_lints/src/lib.register_restriction.rs b/clippy_lints/src/lib.register_restriction.rs index 6ab139b2fb67..4802dd877e99 100644 --- a/clippy_lints/src/lib.register_restriction.rs +++ b/clippy_lints/src/lib.register_restriction.rs @@ -16,6 +16,7 @@ store.register_group(true, "clippy::restriction", Some("clippy_restriction"), ve LintId::of(default_union_representation::DEFAULT_UNION_REPRESENTATION), LintId::of(disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS), LintId::of(else_if_without_else::ELSE_IF_WITHOUT_ELSE), + LintId::of(empty_structs_with_brackets::EMPTY_STRUCTS_WITH_BRACKETS), LintId::of(exhaustive_items::EXHAUSTIVE_ENUMS), LintId::of(exhaustive_items::EXHAUSTIVE_STRUCTS), LintId::of(exit::EXIT), diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index c8b57956b1b6..3138ee9bce5c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -209,6 +209,7 @@ mod drop_forget_ref; mod duration_subsec; mod else_if_without_else; mod empty_enum; +mod empty_structs_with_brackets; mod entry; mod enum_clike; mod enum_variants; @@ -869,6 +870,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: }) }); store.register_early_pass(|| Box::new(crate_in_macro_def::CrateInMacroDef)); + store.register_early_pass(|| Box::new(empty_structs_with_brackets::EmptyStructsWithBrackets)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 09d671e11184..f8e1021af0ea 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -34,7 +34,7 @@ declare_clippy_lint! { /// /// ### Example /// ```rust - /// struct Foo {} + /// struct Foo; /// impl Foo { /// fn new() -> Foo { /// Foo {} @@ -43,7 +43,7 @@ declare_clippy_lint! { /// ``` /// could be /// ```rust - /// struct Foo {} + /// struct Foo; /// impl Foo { /// fn new() -> Self { /// Self {} diff --git a/tests/ui-toml/struct_excessive_bools/test.rs b/tests/ui-toml/struct_excessive_bools/test.rs index 242984680e16..32dd80246fab 100644 --- a/tests/ui-toml/struct_excessive_bools/test.rs +++ b/tests/ui-toml/struct_excessive_bools/test.rs @@ -4,6 +4,6 @@ struct S { a: bool, } -struct Foo {} +struct Foo; fn main() {} diff --git a/tests/ui/case_sensitive_file_extension_comparisons.rs b/tests/ui/case_sensitive_file_extension_comparisons.rs index 68719c2bc6d0..0d65071af15e 100644 --- a/tests/ui/case_sensitive_file_extension_comparisons.rs +++ b/tests/ui/case_sensitive_file_extension_comparisons.rs @@ -2,7 +2,7 @@ use std::string::String; -struct TestStruct {} +struct TestStruct; impl TestStruct { fn ends_with(self, arg: &str) {} diff --git a/tests/ui/crashes/ice-2774.rs b/tests/ui/crashes/ice-2774.rs index d44b0fae8200..88cfa1f923c0 100644 --- a/tests/ui/crashes/ice-2774.rs +++ b/tests/ui/crashes/ice-2774.rs @@ -8,7 +8,7 @@ pub struct Bar { } #[derive(Eq, PartialEq, Debug, Hash)] -pub struct Foo {} +pub struct Foo; #[allow(clippy::implicit_hasher)] // This should not cause a "cannot relate bound region" ICE. diff --git a/tests/ui/crashes/ice-6179.rs b/tests/ui/crashes/ice-6179.rs index 8d9a1af8ff11..4fe92d356c44 100644 --- a/tests/ui/crashes/ice-6179.rs +++ b/tests/ui/crashes/ice-6179.rs @@ -4,7 +4,7 @@ #![warn(clippy::use_self)] #![allow(dead_code)] -struct Foo {} +struct Foo; impl Foo { fn new() -> Self { diff --git a/tests/ui/crashes/ice-6792.rs b/tests/ui/crashes/ice-6792.rs index 0e2ab1a39b82..9cbafc716b50 100644 --- a/tests/ui/crashes/ice-6792.rs +++ b/tests/ui/crashes/ice-6792.rs @@ -7,7 +7,7 @@ trait Trait { fn broken() -> Self::Ty; } -struct Foo {} +struct Foo; impl Trait for Foo { type Ty = Foo; diff --git a/tests/ui/crashes/needless_lifetimes_impl_trait.rs b/tests/ui/crashes/needless_lifetimes_impl_trait.rs index 676564b2445d..376ff97ba603 100644 --- a/tests/ui/crashes/needless_lifetimes_impl_trait.rs +++ b/tests/ui/crashes/needless_lifetimes_impl_trait.rs @@ -3,7 +3,7 @@ trait Foo {} -struct Bar {} +struct Bar; struct Baz<'a> { bar: &'a Bar, diff --git a/tests/ui/crashes/regressions.rs b/tests/ui/crashes/regressions.rs index a41bcb33b446..6f9d98bbfe7f 100644 --- a/tests/ui/crashes/regressions.rs +++ b/tests/ui/crashes/regressions.rs @@ -6,6 +6,6 @@ pub fn foo(bar: *const u8) { // Regression test for https://github.com/rust-lang/rust-clippy/issues/4917 /// $DIR/empty_structs_with_brackets.rs:5:25 + | +LL | pub struct MyEmptyStruct {} // should trigger lint + | ^^^ + | + = note: `-D clippy::empty-structs-with-brackets` implied by `-D warnings` + = help: remove the brackets + +error: found empty brackets on struct declaration + --> $DIR/empty_structs_with_brackets.rs:6:26 + | +LL | struct MyEmptyTupleStruct(); // should trigger lint + | ^^^ + | + = help: remove the brackets + +error: aborting due to 2 previous errors + diff --git a/tests/ui/fn_params_excessive_bools.rs b/tests/ui/fn_params_excessive_bools.rs index 1442ee08e754..f805bcc9ba8a 100644 --- a/tests/ui/fn_params_excessive_bools.rs +++ b/tests/ui/fn_params_excessive_bools.rs @@ -20,7 +20,7 @@ fn h(_: bool, _: bool, _: bool) {} fn e(_: S, _: S, _: Box, _: Vec) {} fn t(_: S, _: S, _: Box, _: Vec, _: bool, _: bool, _: bool, _: bool) {} -struct S {} +struct S; trait Trait { fn f(_: bool, _: bool, _: bool, _: bool); fn g(_: bool, _: bool, _: bool, _: Vec); diff --git a/tests/ui/implicit_clone.rs b/tests/ui/implicit_clone.rs index 639fecb8927b..2549c9f32f90 100644 --- a/tests/ui/implicit_clone.rs +++ b/tests/ui/implicit_clone.rs @@ -30,7 +30,7 @@ where } #[derive(Copy, Clone)] -struct Kitten {} +struct Kitten; impl Kitten { // badly named method fn to_vec(self) -> Kitten { @@ -44,7 +44,7 @@ impl Borrow for Kitten { } } -struct BorrowedKitten {} +struct BorrowedKitten; impl ToOwned for BorrowedKitten { type Owned = Kitten; fn to_owned(&self) -> Kitten { diff --git a/tests/ui/iter_nth_zero.fixed b/tests/ui/iter_nth_zero.fixed index b54147c94d19..f23671c26e4c 100644 --- a/tests/ui/iter_nth_zero.fixed +++ b/tests/ui/iter_nth_zero.fixed @@ -3,7 +3,7 @@ #![warn(clippy::iter_nth_zero)] use std::collections::HashSet; -struct Foo {} +struct Foo; impl Foo { fn nth(&self, index: usize) -> usize { diff --git a/tests/ui/iter_nth_zero.rs b/tests/ui/iter_nth_zero.rs index b92c7d18adb4..7c968d498457 100644 --- a/tests/ui/iter_nth_zero.rs +++ b/tests/ui/iter_nth_zero.rs @@ -3,7 +3,7 @@ #![warn(clippy::iter_nth_zero)] use std::collections::HashSet; -struct Foo {} +struct Foo; impl Foo { fn nth(&self, index: usize) -> usize { diff --git a/tests/ui/large_types_passed_by_value.rs b/tests/ui/large_types_passed_by_value.rs index e4a2e9df4d7b..7601b5c66fa3 100644 --- a/tests/ui/large_types_passed_by_value.rs +++ b/tests/ui/large_types_passed_by_value.rs @@ -37,7 +37,7 @@ pub trait PubLargeTypeDevourer { fn devoure_array_in_public(&self, array: [u8; 6666]); } -struct S {} +struct S; impl LargeTypeDevourer for S { fn devoure_array(&self, array: [u8; 6666]) { todo!(); diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index e3561863c1e1..bb162adc9adb 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -88,7 +88,7 @@ mod no_lint_if_stmt_borrows { ret } - struct Bar {} + struct Bar; impl Bar { fn new() -> Self { diff --git a/tests/ui/let_underscore_must_use.rs b/tests/ui/let_underscore_must_use.rs index a842e872a37b..1edb77c748bf 100644 --- a/tests/ui/let_underscore_must_use.rs +++ b/tests/ui/let_underscore_must_use.rs @@ -26,7 +26,7 @@ fn h() -> u32 { 0 } -struct S {} +struct S; impl S { #[must_use] diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed index 136cc96be70c..b7e46a4a8ccc 100644 --- a/tests/ui/manual_async_fn.fixed +++ b/tests/ui/manual_async_fn.fixed @@ -38,7 +38,7 @@ async fn already_async() -> impl Future { async { 42 } } -struct S {} +struct S; impl S { async fn inh_fut() -> i32 { // NOTE: this code is here just to check that the indentation is correct in the suggested fix diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs index ddc453ffdb75..b05429da6622 100644 --- a/tests/ui/manual_async_fn.rs +++ b/tests/ui/manual_async_fn.rs @@ -52,7 +52,7 @@ async fn already_async() -> impl Future { async { 42 } } -struct S {} +struct S; impl S { fn inh_fut() -> impl Future { async { diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index 05d6c56f2aca..7d68978216c9 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -78,7 +78,7 @@ fn result_unwrap_or() { (Ok(1) as Result).unwrap_or(42); // method call case, suggestion must not surround Result expr `s.method()` with parentheses - struct S {} + struct S; impl S { fn method(self) -> Option { Some(42) diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 09f62c69b71d..b937fe6f977e 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -102,7 +102,7 @@ fn result_unwrap_or() { }; // method call case, suggestion must not surround Result expr `s.method()` with parentheses - struct S {} + struct S; impl S { fn method(self) -> Option { Some(42) diff --git a/tests/ui/map_unit_fn.rs b/tests/ui/map_unit_fn.rs index 9a74da4e3b8b..e7f07b50f3ab 100644 --- a/tests/ui/map_unit_fn.rs +++ b/tests/ui/map_unit_fn.rs @@ -1,5 +1,5 @@ #![allow(unused)] -struct Mappable {} +struct Mappable; impl Mappable { pub fn map(&self) {} diff --git a/tests/ui/min_rust_version_attr.rs b/tests/ui/min_rust_version_attr.rs index c5f221220ece..72e9bf9eb368 100644 --- a/tests/ui/min_rust_version_attr.rs +++ b/tests/ui/min_rust_version_attr.rs @@ -99,7 +99,7 @@ pub fn manual_range_contains() { } pub fn use_self() { - struct Foo {} + struct Foo; impl Foo { fn new() -> Foo { diff --git a/tests/ui/missing_inline.rs b/tests/ui/missing_inline.rs index b73b24b8e0a3..07f8e3888c99 100644 --- a/tests/ui/missing_inline.rs +++ b/tests/ui/missing_inline.rs @@ -7,8 +7,8 @@ type Typedef = String; pub type PubTypedef = String; -struct Foo {} // ok -pub struct PubFoo {} // ok +struct Foo; // ok +pub struct PubFoo; // ok enum FooE {} // ok pub enum PubFooE {} // ok @@ -63,4 +63,4 @@ impl PubFoo { // do not lint this since users cannot control the external code #[derive(Debug)] -pub struct S {} +pub struct S; diff --git a/tests/ui/module_name_repetitions.rs b/tests/ui/module_name_repetitions.rs index f5908cb5701f..ebaa77cc283e 100644 --- a/tests/ui/module_name_repetitions.rs +++ b/tests/ui/module_name_repetitions.rs @@ -7,7 +7,7 @@ mod foo { pub fn foo() {} pub fn foo_bar() {} pub fn bar_foo() {} - pub struct FooCake {} + pub struct FooCake; pub enum CakeFoo {} pub struct Foo7Bar; diff --git a/tests/ui/module_name_repetitions.stderr b/tests/ui/module_name_repetitions.stderr index bdd217a969c0..3f343a3e4301 100644 --- a/tests/ui/module_name_repetitions.stderr +++ b/tests/ui/module_name_repetitions.stderr @@ -15,8 +15,8 @@ LL | pub fn bar_foo() {} error: item name starts with its containing module's name --> $DIR/module_name_repetitions.rs:10:5 | -LL | pub struct FooCake {} - | ^^^^^^^^^^^^^^^^^^^^^ +LL | pub struct FooCake; + | ^^^^^^^^^^^^^^^^^^^ error: item name ends with its containing module's name --> $DIR/module_name_repetitions.rs:11:5 diff --git a/tests/ui/needless_arbitrary_self_type_unfixable.rs b/tests/ui/needless_arbitrary_self_type_unfixable.rs index ad0d694a2174..02b43cce2bd4 100644 --- a/tests/ui/needless_arbitrary_self_type_unfixable.rs +++ b/tests/ui/needless_arbitrary_self_type_unfixable.rs @@ -14,7 +14,7 @@ mod issue_6089 { fn test(self: &Self); } - struct S1 {} + struct S1; impl T1 for S1 { fn test(self: &Self) {} @@ -32,7 +32,7 @@ mod issue_6089 { fn call_with_mut_self(&mut self); } - struct S2 {} + struct S2; // The method's signature will be expanded to: // fn call_with_mut_self<'life0>(self: &'life0 mut Self) {} diff --git a/tests/ui/needless_lifetimes.rs b/tests/ui/needless_lifetimes.rs index f3eafe8e9279..1456204ca869 100644 --- a/tests/ui/needless_lifetimes.rs +++ b/tests/ui/needless_lifetimes.rs @@ -268,7 +268,7 @@ mod issue4291 { mod issue2944 { trait Foo {} - struct Bar {} + struct Bar; struct Baz<'a> { bar: &'a Bar, } diff --git a/tests/ui/no_effect.rs b/tests/ui/no_effect.rs index 5427c88faf34..7ece66a1ccb6 100644 --- a/tests/ui/no_effect.rs +++ b/tests/ui/no_effect.rs @@ -78,7 +78,7 @@ impl FnOnce<(&str,)> for GreetStruct2 { } } -struct GreetStruct3 {} +struct GreetStruct3; impl FnOnce<(&str,)> for GreetStruct3 { type Output = (); diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed index 27d4b795a5ee..6e0d5a87f680 100644 --- a/tests/ui/or_then_unwrap.fixed +++ b/tests/ui/or_then_unwrap.fixed @@ -3,7 +3,7 @@ #![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity)] -struct SomeStruct {} +struct SomeStruct; impl SomeStruct { fn or(self, _: Option) -> Self { self @@ -11,7 +11,7 @@ impl SomeStruct { fn unwrap(&self) {} } -struct SomeOtherStruct {} +struct SomeOtherStruct; impl SomeOtherStruct { fn or(self) -> Self { self diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs index 0dab5ae2f1c0..e406a71d46d0 100644 --- a/tests/ui/or_then_unwrap.rs +++ b/tests/ui/or_then_unwrap.rs @@ -3,7 +3,7 @@ #![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity)] -struct SomeStruct {} +struct SomeStruct; impl SomeStruct { fn or(self, _: Option) -> Self { self @@ -11,7 +11,7 @@ impl SomeStruct { fn unwrap(&self) {} } -struct SomeOtherStruct {} +struct SomeOtherStruct; impl SomeOtherStruct { fn or(self) -> Self { self diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index 03dd938a2339..814bbc7af713 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -112,7 +112,7 @@ mod issue_5644 { ) { } - struct S {} + struct S; impl S { fn allowed( #[allow(clippy::ptr_arg)] _v: &Vec, diff --git a/tests/ui/recursive_format_impl.rs b/tests/ui/recursive_format_impl.rs index 9241bf7ed740..f72fc77ab997 100644 --- a/tests/ui/recursive_format_impl.rs +++ b/tests/ui/recursive_format_impl.rs @@ -66,7 +66,7 @@ impl std::fmt::Display for D { // Check for use of self as Display, in Display impl // Triggers on direct use of self -struct G {} +struct G; impl std::fmt::Display for G { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -75,7 +75,7 @@ impl std::fmt::Display for G { } // Triggers on reference to self -struct H {} +struct H; impl std::fmt::Display for H { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -90,7 +90,7 @@ impl std::fmt::Debug for H { } // Triggers on multiple reference to self -struct H2 {} +struct H2; impl std::fmt::Display for H2 { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -99,7 +99,7 @@ impl std::fmt::Display for H2 { } // Doesn't trigger on correct deref -struct I {} +struct I; impl std::ops::Deref for I { type Target = str; @@ -122,7 +122,7 @@ impl std::fmt::Debug for I { } // Doesn't trigger on multiple correct deref -struct I2 {} +struct I2; impl std::ops::Deref for I2 { type Target = str; @@ -139,7 +139,7 @@ impl std::fmt::Display for I2 { } // Doesn't trigger on multiple correct deref -struct I3 {} +struct I3; impl std::ops::Deref for I3 { type Target = str; @@ -156,7 +156,7 @@ impl std::fmt::Display for I3 { } // Does trigger when deref resolves to self -struct J {} +struct J; impl std::ops::Deref for J { type Target = str; @@ -178,7 +178,7 @@ impl std::fmt::Debug for J { } } -struct J2 {} +struct J2; impl std::ops::Deref for J2 { type Target = str; @@ -194,7 +194,7 @@ impl std::fmt::Display for J2 { } } -struct J3 {} +struct J3; impl std::ops::Deref for J3 { type Target = str; @@ -210,7 +210,7 @@ impl std::fmt::Display for J3 { } } -struct J4 {} +struct J4; impl std::ops::Deref for J4 { type Target = str; @@ -227,7 +227,7 @@ impl std::fmt::Display for J4 { } // Doesn't trigger on Debug from Display -struct K {} +struct K; impl std::fmt::Debug for K { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { @@ -242,7 +242,7 @@ impl std::fmt::Display for K { } // Doesn't trigger on Display from Debug -struct K2 {} +struct K2; impl std::fmt::Debug for K2 { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { diff --git a/tests/ui/redundant_allocation.rs b/tests/ui/redundant_allocation.rs index 52fbc91e3255..80f94e5f3cbb 100644 --- a/tests/ui/redundant_allocation.rs +++ b/tests/ui/redundant_allocation.rs @@ -3,7 +3,7 @@ #![allow(clippy::blacklisted_name, unused_variables, dead_code)] #![allow(unused_imports)] -pub struct MyStruct {} +pub struct MyStruct; pub struct SubT { foo: T, diff --git a/tests/ui/redundant_allocation_fixable.fixed b/tests/ui/redundant_allocation_fixable.fixed index ef089b25f47f..e7ed84731c02 100644 --- a/tests/ui/redundant_allocation_fixable.fixed +++ b/tests/ui/redundant_allocation_fixable.fixed @@ -4,7 +4,7 @@ #![allow(clippy::blacklisted_name, unused_variables, dead_code)] #![allow(unused_imports)] -pub struct MyStruct {} +pub struct MyStruct; pub struct SubT { foo: T, diff --git a/tests/ui/redundant_allocation_fixable.rs b/tests/ui/redundant_allocation_fixable.rs index fefa87721d72..de763f98b5c8 100644 --- a/tests/ui/redundant_allocation_fixable.rs +++ b/tests/ui/redundant_allocation_fixable.rs @@ -4,7 +4,7 @@ #![allow(clippy::blacklisted_name, unused_variables, dead_code)] #![allow(unused_imports)] -pub struct MyStruct {} +pub struct MyStruct; pub struct SubT { foo: T, diff --git a/tests/ui/redundant_static_lifetimes.fixed b/tests/ui/redundant_static_lifetimes.fixed index 921249606ad2..acc8f1e25b6e 100644 --- a/tests/ui/redundant_static_lifetimes.fixed +++ b/tests/ui/redundant_static_lifetimes.fixed @@ -3,7 +3,7 @@ #![allow(unused)] #[derive(Debug)] -struct Foo {} +struct Foo; const VAR_ONE: &str = "Test constant #1"; // ERROR Consider removing 'static. diff --git a/tests/ui/redundant_static_lifetimes.rs b/tests/ui/redundant_static_lifetimes.rs index 4d4b249d076f..f2f0f78659c9 100644 --- a/tests/ui/redundant_static_lifetimes.rs +++ b/tests/ui/redundant_static_lifetimes.rs @@ -3,7 +3,7 @@ #![allow(unused)] #[derive(Debug)] -struct Foo {} +struct Foo; const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static. diff --git a/tests/ui/same_item_push.rs b/tests/ui/same_item_push.rs index 9d420ec672a2..99964f0de075 100644 --- a/tests/ui/same_item_push.rs +++ b/tests/ui/same_item_push.rs @@ -120,7 +120,7 @@ fn main() { } // Fix #5979 #[derive(Clone)] - struct S {} + struct S; trait T {} impl T for S {} diff --git a/tests/ui/trait_duplication_in_bounds.rs b/tests/ui/trait_duplication_in_bounds.rs index 21de19a26014..f5ca91143af2 100644 --- a/tests/ui/trait_duplication_in_bounds.rs +++ b/tests/ui/trait_duplication_in_bounds.rs @@ -62,7 +62,7 @@ trait BadTrait: Default + Clone { } #[derive(Default, Clone)] -struct Life {} +struct Life; impl T for Life { // this should not warn @@ -85,7 +85,7 @@ trait Iter: Iterator { } } -struct Foo {} +struct Foo; trait FooIter: Iterator { fn bar() diff --git a/tests/ui/unsafe_derive_deserialize.rs b/tests/ui/unsafe_derive_deserialize.rs index 690d705573d3..bafca91917aa 100644 --- a/tests/ui/unsafe_derive_deserialize.rs +++ b/tests/ui/unsafe_derive_deserialize.rs @@ -6,7 +6,7 @@ extern crate serde; use serde::Deserialize; #[derive(Deserialize)] -pub struct A {} +pub struct A; impl A { pub unsafe fn new(_a: i32, _b: i32) -> Self { Self {} @@ -14,13 +14,13 @@ impl A { } #[derive(Deserialize)] -pub struct B {} +pub struct B; impl B { pub unsafe fn unsafe_method(&self) {} } #[derive(Deserialize)] -pub struct C {} +pub struct C; impl C { pub fn unsafe_block(&self) { unsafe {} @@ -28,7 +28,7 @@ impl C { } #[derive(Deserialize)] -pub struct D {} +pub struct D; impl D { pub fn inner_unsafe_fn(&self) { unsafe fn inner() {} @@ -36,7 +36,7 @@ impl D { } // Does not derive `Deserialize`, should be ignored -pub struct E {} +pub struct E; impl E { pub unsafe fn new(_a: i32, _b: i32) -> Self { Self {} @@ -55,12 +55,12 @@ impl E { // Does not have methods using `unsafe`, should be ignored #[derive(Deserialize)] -pub struct F {} +pub struct F; // Check that we honor the `allow` attribute on the ADT #[allow(clippy::unsafe_derive_deserialize)] #[derive(Deserialize)] -pub struct G {} +pub struct G; impl G { pub fn unsafe_block(&self) { unsafe {} diff --git a/tests/ui/unsafe_removed_from_name.rs b/tests/ui/unsafe_removed_from_name.rs index a1f616733bd9..cde4e96d668c 100644 --- a/tests/ui/unsafe_removed_from_name.rs +++ b/tests/ui/unsafe_removed_from_name.rs @@ -14,8 +14,8 @@ use std::cell::UnsafeCell as Dangerunsafe; use std::cell::UnsafeCell as Bombsawayunsafe; mod mod_with_some_unsafe_things { - pub struct Safe {} - pub struct Unsafe {} + pub struct Safe; + pub struct Unsafe; } use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety; diff --git a/tests/ui/unused_self.rs b/tests/ui/unused_self.rs index 7a4bbdda1ab2..08bf58fec7c3 100644 --- a/tests/ui/unused_self.rs +++ b/tests/ui/unused_self.rs @@ -5,7 +5,7 @@ mod unused_self { use std::pin::Pin; use std::sync::{Arc, Mutex}; - struct A {} + struct A; impl A { fn unused_self_move(self) {} @@ -27,7 +27,7 @@ mod unused_self { } mod unused_self_allow { - struct A {} + struct A; impl A { // shouldn't trigger @@ -35,7 +35,7 @@ mod unused_self_allow { fn unused_self_move(self) {} } - struct B {} + struct B; // shouldn't trigger #[allow(clippy::unused_self)] @@ -43,7 +43,7 @@ mod unused_self_allow { fn unused_self_move(self) {} } - struct C {} + struct C; #[allow(clippy::unused_self)] impl C { @@ -120,7 +120,7 @@ mod used_self { mod not_applicable { use std::fmt; - struct A {} + struct A; impl fmt::Debug for A { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 9d216f56ae60..3e62ffe74fed 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -16,7 +16,7 @@ extern crate proc_macro_derive; fn main() {} mod use_self { - struct Foo {} + struct Foo; impl Foo { fn new() -> Self { @@ -35,7 +35,7 @@ mod use_self { } mod better { - struct Foo {} + struct Foo; impl Foo { fn new() -> Self { @@ -123,7 +123,7 @@ mod macros { }; } - struct Foo {} + struct Foo; impl Foo { use_self_expand!(); // Should not lint in local macros @@ -134,7 +134,7 @@ mod macros { } mod nesting { - struct Foo {} + struct Foo; impl Foo { fn foo() { #[allow(unused_imports)] @@ -209,7 +209,7 @@ mod issue3410 { #[allow(clippy::no_effect, path_statements)] mod rustfix { mod nested { - pub struct A {} + pub struct A; } impl nested::A { @@ -227,7 +227,7 @@ mod rustfix { } mod issue3567 { - struct TestStruct {} + struct TestStruct; impl TestStruct { fn from_something() -> Self { Self {} @@ -248,7 +248,7 @@ mod issue3567 { mod paths_created_by_lowering { use std::ops::Range; - struct S {} + struct S; impl S { const A: usize = 0; @@ -382,7 +382,7 @@ mod issue4305 { } mod lint_at_item_level { - struct Foo {} + struct Foo; #[allow(clippy::use_self)] impl Foo { @@ -400,7 +400,7 @@ mod lint_at_item_level { } mod lint_at_impl_item_level { - struct Foo {} + struct Foo; impl Foo { #[allow(clippy::use_self)] @@ -433,8 +433,8 @@ mod issue4734 { mod nested_paths { use std::convert::Into; mod submod { - pub struct B {} - pub struct C {} + pub struct B; + pub struct C; impl Into for B { fn into(self) -> C { diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 5f604fe25e41..da2faddee12a 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -16,7 +16,7 @@ extern crate proc_macro_derive; fn main() {} mod use_self { - struct Foo {} + struct Foo; impl Foo { fn new() -> Foo { @@ -35,7 +35,7 @@ mod use_self { } mod better { - struct Foo {} + struct Foo; impl Foo { fn new() -> Self { @@ -123,7 +123,7 @@ mod macros { }; } - struct Foo {} + struct Foo; impl Foo { use_self_expand!(); // Should not lint in local macros @@ -134,7 +134,7 @@ mod macros { } mod nesting { - struct Foo {} + struct Foo; impl Foo { fn foo() { #[allow(unused_imports)] @@ -209,7 +209,7 @@ mod issue3410 { #[allow(clippy::no_effect, path_statements)] mod rustfix { mod nested { - pub struct A {} + pub struct A; } impl nested::A { @@ -227,7 +227,7 @@ mod rustfix { } mod issue3567 { - struct TestStruct {} + struct TestStruct; impl TestStruct { fn from_something() -> Self { Self {} @@ -248,7 +248,7 @@ mod issue3567 { mod paths_created_by_lowering { use std::ops::Range; - struct S {} + struct S; impl S { const A: usize = 0; @@ -382,7 +382,7 @@ mod issue4305 { } mod lint_at_item_level { - struct Foo {} + struct Foo; #[allow(clippy::use_self)] impl Foo { @@ -400,7 +400,7 @@ mod lint_at_item_level { } mod lint_at_impl_item_level { - struct Foo {} + struct Foo; impl Foo { #[allow(clippy::use_self)] @@ -433,8 +433,8 @@ mod issue4734 { mod nested_paths { use std::convert::Into; mod submod { - pub struct B {} - pub struct C {} + pub struct B; + pub struct C; impl Into for B { fn into(self) -> C { diff --git a/tests/ui/useless_attribute.fixed b/tests/ui/useless_attribute.fixed index a5fcde768f18..ce58a80347b5 100644 --- a/tests/ui/useless_attribute.fixed +++ b/tests/ui/useless_attribute.fixed @@ -42,7 +42,7 @@ mod a { mod b { #[allow(dead_code)] #[allow(unreachable_pub)] - pub struct C {} + pub struct C; } #[allow(unreachable_pub)] diff --git a/tests/ui/useless_attribute.rs b/tests/ui/useless_attribute.rs index 0396d39e3d54..c82bb9ba07fd 100644 --- a/tests/ui/useless_attribute.rs +++ b/tests/ui/useless_attribute.rs @@ -42,7 +42,7 @@ mod a { mod b { #[allow(dead_code)] #[allow(unreachable_pub)] - pub struct C {} + pub struct C; } #[allow(unreachable_pub)]