Skip to content

Generated docstrings shouldn't result in doctests #359

@Sushisource

Description

@Sushisource

Currently, writing something like

#[derive(bon::Builder)]
pub struct MyOptions {
    /// My comments
    #[builder(default = some_complex_expression]
    pub field: Foo,
}

Can end up generating code that includes a doctest like:

```rust,ignore
some_complex_expression
-``` (can't close this block, breaks GH markdown)

Seemingly, only if the expression is long enough that it would get auto-formatted to be multiple lines.

The ignore would normally be sufficient to solve this, but, I have some tests that are ignored by default but run in CI. That makes these "examples" run as doctests, and fail, since they don't return (). (Or might fail for any number of reasons, like un-imported items.)

This is a bit annoying to fix since rust-lang/rust#63193 exists and is sort of the root of the problem here, there are some workarounds listed in there. Another reasonable solution would be an option that can be set to simply omit the default value, or force it to use one line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions