rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

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

Open Manishearth opened this issue 10 months ago • 4 comments

This behavior changed in https://github.com/rust-lang/rust-bindgen/commit/f160d11d56007fe1b1125d04f0cb31af0b18fc6e

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.

Manishearth avatar Jan 08 '25 23:01 Manishearth

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.

rich-ayr avatar Jan 11 '25 17:01 rich-ayr

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.

Manishearth avatar Jan 13 '25 21:01 Manishearth

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.

jschwe avatar Jan 15 '25 10:01 jschwe

cc @pvdrz

emilio avatar Feb 01 '25 20:02 emilio