diff --git a/clippy_lints/src/field_scoped_visibility_modifiers.rs b/clippy_lints/src/field_scoped_visibility_modifiers.rs index 49773909f380..3e29b2a959aa 100644 --- a/clippy_lints/src/field_scoped_visibility_modifiers.rs +++ b/clippy_lints/src/field_scoped_visibility_modifiers.rs @@ -28,8 +28,16 @@ declare_clippy_lint! { /// ```no_run /// pub mod public_module { /// struct MyStruct { - /// pub first_field: bool, - /// pub second_field: bool + /// first_field: bool, + /// second_field: bool + /// } + /// impl MyStruct { + /// pub(crate) fn get_first_field(&self) -> bool { + /// self.first_field + /// } + /// pub(super) fn get_second_field(&self) -> bool { + /// self.second_field + /// } /// } /// } /// ``` @@ -60,7 +68,7 @@ impl EarlyLintPass for FieldScopedVisibilityModifiers { field.vis.span, "scoped visibility modifier on a field", None, - "consider making the field either public or private", + "consider making the field private and adding a scoped visibility method to read it", ); } } diff --git a/tests/ui/field_scoped_visibility_modifiers.stderr b/tests/ui/field_scoped_visibility_modifiers.stderr index cab829e92a7f..629548fba4fb 100644 --- a/tests/ui/field_scoped_visibility_modifiers.stderr +++ b/tests/ui/field_scoped_visibility_modifiers.stderr @@ -4,7 +4,7 @@ error: scoped visibility modifier on a field LL | pub(crate) pub_crate_field: bool, | ^^^^^^^^^^ | - = help: consider making the field either public or private + = help: consider making the field private and adding a scoped visibility method to read it = note: `-D clippy::field-scoped-visibility-modifiers` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::field_scoped_visibility_modifiers)]` @@ -14,7 +14,7 @@ error: scoped visibility modifier on a field LL | pub(in crate::pub_module) pub_in_path_field: bool, | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider making the field either public or private + = help: consider making the field private and adding a scoped visibility method to read it error: scoped visibility modifier on a field --> tests/ui/field_scoped_visibility_modifiers.rs:11:9 @@ -22,7 +22,7 @@ error: scoped visibility modifier on a field LL | pub(super) pub_super_field: bool, | ^^^^^^^^^^ | - = help: consider making the field either public or private + = help: consider making the field private and adding a scoped visibility method to read it error: aborting due to 3 previous errors