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

rustfmt does not refuse to format function parameters with doc comments and formats them wrong #5014

Closed
Maxpxt opened this issue Oct 1, 2021 · 1 comment

Comments

@Maxpxt
Copy link

Maxpxt commented Oct 1, 2021

Description

Doc comments are not allowed in function parameters, so rustfmt should either refuse to format code that has them or format them as if they were normal comments. Instead, rustfmt incorrectly formats the code by merging the parameter into the doc comment or sometimes removing the doc comment.

To Reproduce

For example, rustfmt formats

fn foo(
    /// This is `bar`.
    bar: bool,
) {
}

into

fn foo(/// This is `bar`. bar: bool
) {
}

and formats

fn foo(
    /// This is `bar`.
    bar: bool,
    /// This has a long name.
    veeeeeeeeeeery_long_paramater_name_to_force_multiline_parameter_list: bool,
) {
}

into

fn foo(
    /// This is `bar`. bar: bool,
    veeeeeeeeeeery_long_paramater_name_to_force_multiline_parameter_list: bool,
) {
}

Meta

  • rustfmt version: rustfmt 1.4.37-nightly (aa7aca3 2021-09-30)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt?: via rust-analyzer in vscode, but this was tested with rustfmt too
@calebcartwright
Copy link
Member

Closing as a duplicate of #4936

In general, while in many cases rustfmt can still format around invalid code, one should not expect rustfmt to be able to handle all cases of invalid syntax, as that way lies madness.

We did opt to go ahead and support this particular use case, but that was primarily because there seemed to be a plan for making this potential valid with macros.

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

No branches or pull requests

2 participants