Skip to content

Commit 3c5dcf3

Browse files
committed
Improve 'use instead' section of lint doc
1 parent d0e1e4c commit 3c5dcf3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

clippy_lints/src/field_scoped_visibility_modifiers.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ declare_clippy_lint! {
2828
/// ```no_run
2929
/// pub mod public_module {
3030
/// struct MyStruct {
31-
/// pub first_field: bool,
32-
/// pub second_field: bool
31+
/// first_field: bool,
32+
/// second_field: bool
33+
/// }
34+
/// impl MyStruct {
35+
/// pub(crate) fn get_first_field(&self) -> bool {
36+
/// self.first_field
37+
/// }
38+
/// pub(super) fn get_second_field(&self) -> bool {
39+
/// self.second_field
40+
/// }
3341
/// }
3442
/// }
3543
/// ```
@@ -60,7 +68,7 @@ impl EarlyLintPass for FieldScopedVisibilityModifiers {
6068
field.vis.span,
6169
"scoped visibility modifier on a field",
6270
None,
63-
"consider making the field either public or private",
71+
"consider making the field private and adding a scoped visibility method to read it",
6472
);
6573
}
6674
}

tests/ui/field_scoped_visibility_modifiers.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: scoped visibility modifier on a field
44
LL | pub(crate) pub_crate_field: bool,
55
| ^^^^^^^^^^
66
|
7-
= help: consider making the field either public or private
7+
= help: consider making the field private and adding a scoped visibility method to read it
88
= note: `-D clippy::field-scoped-visibility-modifiers` implied by `-D warnings`
99
= help: to override `-D warnings` add `#[allow(clippy::field_scoped_visibility_modifiers)]`
1010

@@ -14,15 +14,15 @@ error: scoped visibility modifier on a field
1414
LL | pub(in crate::pub_module) pub_in_path_field: bool,
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1616
|
17-
= help: consider making the field either public or private
17+
= help: consider making the field private and adding a scoped visibility method to read it
1818

1919
error: scoped visibility modifier on a field
2020
--> tests/ui/field_scoped_visibility_modifiers.rs:11:9
2121
|
2222
LL | pub(super) pub_super_field: bool,
2323
| ^^^^^^^^^^
2424
|
25-
= help: consider making the field either public or private
25+
= help: consider making the field private and adding a scoped visibility method to read it
2626

2727
error: aborting due to 3 previous errors
2828

0 commit comments

Comments
 (0)