-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add allow_unused config to missing_docs_in_private_items #14453
base: master
Are you sure you want to change the base?
add allow_unused config to missing_docs_in_private_items #14453
Conversation
add allow_unused config to missing_docs_in_private_items for underscored field
// Skip checking if the field starts with underscore and allow_unused is enabled | ||
if self.allow_unused && sf.ident.as_str().starts_with('_') { | ||
self.prev_span = Some(sf.span); | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can group if
conditions and keep only one exit point, this should be clearer since self.prev_span
must be adjusted in all paths before leaving:
fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) {
if !sf.is_positional()
&& !(self.allow_unused && sf.ident.as_str().starts_with('_'))
&& !is_from_proc_macro(cx, sf)
{
let attrs = cx.tcx.hir_attrs(sf.hir_id);
self.check_missing_docs_attrs(cx, sf.def_id, attrs, sf.span, "a", "struct field");
}
self.prev_span = Some(sf.span);
}
@@ -723,6 +723,16 @@ Minimum chars an ident can have, anything below or equal to this will be linted. | |||
* [`min_ident_chars`](https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars) | |||
|
|||
|
|||
## `missing-docs-allow-unused` | |||
Whether to allow fields starting with underscore to skip documentation requirements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: shouldn't it be "with underscores" or "with an underscore"? (repeated in other places)
_field1: i32, // This should not trigger a warning | ||
_field2: i32, // This should not trigger a warning | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add the following test to ensure that a documented unused field does not trigger a warning, and that the documentation is not applied to the next field (which should be documented) either?
struct Test3 {
//~^ missing_docs_in_private_items
/// This field is documented although this is not mandatory
_unused: i32, // This should not trigger a warning because it starts with underscore
field3: i32, //~ missing_docs_in_private_items
}
Taking this one since I've reviewed it already. |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
fixes #14413
add allow_unused config to missing_docs_in_private_items for underscored field
changelog: [
missing_docs_in_private_items
]: add allow_unused config to missing_docs_in_private_items for underscored fieldExplaination (quoted from the issue's author): When writing structures that must adhere to a specific format (such as memory mapped I/O structures) there are inevitably fields that are "reserved" by specifications and thus need no documentation. In cases where private docs are preferred but reserved fields need no explanation, having to #[allow/expect] this lint removes the ability to check for otherwise used fields' documentation.