Skip to content
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

missing documentation for an associated function Builder #283

Closed
SupperZum opened this issue Mar 24, 2023 · 3 comments
Closed

missing documentation for an associated function Builder #283

SupperZum opened this issue Mar 24, 2023 · 3 comments

Comments

@SupperZum
Copy link

I don't know how to remove this Warning. Please tell me how to remove it.

warning: missing documentation for an associated function
--> crate\lt\src\lib.rs:30:32
|
30 | #[ derive( Debug, Deserialize, Builder, Clone, Default ) ]
| ^^^^^^^
|
note: the lint level is defined here
--> crate\lt\src\lib.rs:3:11
|
3 | #![ warn( missing_docs ) ]
| ^^^^^^^^^^^^
= note: this warning originates in the derive macro Builder (in Nightly builds, run with -Z macro-backtrace for more info)

@TedDriggs
Copy link
Collaborator

If you run cargo doc on your crate and look at the builder, do you see documentation on the struct or its methods?

You may need to add something like...

#[derive(Builder)]
#[builder_struct_attr(allow(missing_docs))]
struct Yours {}

@sowbug
Copy link

sowbug commented Jul 28, 2023

That exact solution didn't work in my case.

I ended up with code like this in my cargo expand output:

        #[allow(clippy::all)]
        #[allow(dead_code)]
        impl OrchestratorBuilder {
            /// My rustdoc comment for the title() method
            #[allow(unused_mut)]
            pub fn title(&mut self, value: Option<String>) -> &mut Self {
                ...
            }
            #[allow(unused_mut)]
            pub fn field_that_I_think_was_causing_the_problem(
                &mut self,
                value: ...,
            ) -> &mut Self {
                ...

This might be because I'm using #[builder(setter(skip))] on the struct, and #[builder(setter)] on the field that's acting up. Otherwise it seems like this problem would affect many users of this crate.

A few observations:

  1. Putting #[builder_struct_attr(allow(missing_docs))] on the struct doesn't cause the Builder's impls to carry the attr, but it does produce it for the Builder struct.
  2. I guessed that there was a #[builder_field_attr(allow(missing_docs))], and I tried putting it on field_that_I_think_was_causing_the_problem, but the generated Builder code didn't get the attr.
  3. The Builder generator appears to copy any rustdoc for a field to its corresponding Builder setter. That's why title doesn't generate the missing-doc warning.

Based on Observation #3, I put a placeholder rustdoc on field_that_I_think_was_causing_the_problem in the original struct. The warning immediately went away, and indeed the generated Builder impl included a copy of my placeholder rustdoc.

TL;DR: if you're getting this warning, put /// any rustdoc on your struct fields, and it'll get propagated to the Builder setters, which will fix the issue.

sowbug added a commit to sowbug/groove that referenced this issue Jul 28, 2023
@SupperZum
Copy link
Author

My problem was that the structure fields were not documented, when I documented the structure fields, the warning disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants