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

bug: wrap_comments mangles reference-style links #5095

Closed
domodwyer opened this issue Nov 19, 2021 · 1 comment · Fixed by #5096
Closed

bug: wrap_comments mangles reference-style links #5095

domodwyer opened this issue Nov 19, 2021 · 1 comment · Fixed by #5096
Labels
a-comments only-with-option requires a non-default option value to reproduce

Comments

@domodwyer
Copy link
Contributor

rustfmt with wrap_comments enabled is mangling reference-style intra-doc links by line wrapping them.

A comment like this:

/// Check out [my other struct] ([`Bananas`]) and [the method it has].
///
/// [my other struct]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::f_long_name::Apples
/// [`Bananas`]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
/// [the method it has]: a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::fantastic()
pub struct A;

Is wrapped into:

/// Check out [my other struct] ([`Bananas`]) and [the method it has].
///
/// [my other struct]:
/// a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::
/// f_long_name::Apples [`Bananas`]:
/// a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::
/// fantastic() [the method it has]:
/// a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::Bananas::
/// fantastic()
pub struct A;

I would have expected rustfmt to leave the reference links alone, the wrapped comment makes cargo doc unhappy.

cargo doc output
doctest % cargo doc
 Documenting doctest v0.1.0 (/Users/dom/Desktop/doctest)
warning: unresolved link to `Bananas`
  --> src/lib.rs:20:36
   |
20 | /// Check out [my other struct] ([`Bananas`]) and [the method it has].
   |                                    ^^^^^^^ no item named `Bananas` in scope
   |
   = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
   = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

warning: unresolved link to `a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::`
  --> src/lib.rs:23:5
   |
23 | /// a_long_name::b_long_name::c_long_name::d_long_name::e_long_name::
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no item named `` in module `e_long_name`

warning: unresolved link to `Bananas`
  --> src/lib.rs:24:27
   |
24 | /// f_long_name::Apples [`Bananas`]:
   |                           ^^^^^^^ no item named `Bananas` in scope
   |
   = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

warning: `doctest` (lib doc) generated 3 warnings
@ytmimi ytmimi added a-comments only-with-option requires a non-default option value to reproduce labels Nov 20, 2021
@ytmimi
Copy link
Contributor

ytmimi commented Nov 20, 2021

Thanks for submitting the issue and for working on the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants