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

Bindgen produces #[doc = "foo\nbar"] doc comments instead of multiline doc comments #3073

Open
Manishearth opened this issue Jan 8, 2025 · 3 comments

Comments

@Manishearth
Copy link
Member

This behavior changed in f160d11

Bindgen used to produce doc comments like this:

extern "C" {
  #[doc = "foo"]
  #[doc = "bar"]
  fn baz();
}

but now these doc comments look like this:

extern "C" {
  #[doc = "foo\nbar"]
  fn baz();
}

which is much less readable. We have documentation on normalizing doc comments, but not everyone is using a nightly rustfmt. This change does not seem intentional but rather collateral damage in that feature, perhaps it's worth bringing the old behavior back.

@oberrich
Copy link

I think this is a sensible default as it removes unnecessary line noise.
Most people won't go through the trouble of parsing multiple doc tags in a real scenario, they'll use rustdoc or their IDE.
The normalized comments are definitely useful for a quick lookup by navigating to the definition, but I don't see this for #[doc] tags; they're not meant for humans.

@Manishearth
Copy link
Member Author

I don't really find this to be unnecessary line noise.

The #[doc] tags are produced by bindgen after parsing doc comments on the C++ side: they're taking comments meant for humans and turning them into this tag. #[doc = ""] isn't great, but having it linebroken is better than nothing.

@jschwe
Copy link
Contributor

jschwe commented Jan 15, 2025

FYI, you can use rustfmt (nightly) with the following configuration to normalize comments to the standard /// style:

unstable_features = true
normalize_comments = true
normalize_doc_attributes = true

Edit: Sorry, just noticed the OP already mentioned that.

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