Skip to content

Commit

Permalink
responding to feedback, inline msg, update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkMyCar committed Oct 11, 2023
1 parent da69c5e commit 3d16f47
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions clippy_lints/src/pub_underscore_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ declare_clippy_lint! {
/// ```
/// Use instead:
/// ```rust
/// struct FileHandle {
/// struct FileHandle_Foo {
/// _descriptor: usize,
/// }
///
/// // OR
///
/// struct FileHandle_Bar {
/// pub descriptor: usize,
/// }
/// ```
#[clippy::version = "1.74.0"]
pub PUB_UNDERSCORE_FIELDS,
Expand All @@ -38,16 +44,15 @@ impl EarlyLintPass for PubUnderscoreFields {
return;
};

let msg = "field marked as public but also inferred as unused because it's prefixed with `_`";
for field in st.fields().iter() {
for field in st.fields() {
if let Some(ident) = field.ident.as_ref()
&& ident.as_str().starts_with('_')
&& !matches!(field.vis.kind, VisibilityKind::Inherited) {
span_lint_and_help(
cx,
PUB_UNDERSCORE_FIELDS,
field.vis.span.to(ident.span),
msg,
"field marked as public but also inferred as unused because it's prefixed with `_`",
None,
"consider removing the underscore, or making the field private",
);
Expand Down

0 comments on commit 3d16f47

Please sign in to comment.