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 c283906
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions clippy_lints/src/pub_underscore_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ declare_clippy_lint! {
/// struct FileHandle {
/// _descriptor: usize,
/// }
/// // OR
/// struct FileHandle {
/// pub descriptor: usize,
/// }
/// ```
#[clippy::version = "1.74.0"]
pub PUB_UNDERSCORE_FIELDS,
Expand All @@ -38,16 +42,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 c283906

Please sign in to comment.