Skip to content

C style comments are produced unescaped #1033

@chrysn

Description

@chrysn

If there is a C style comment inside a Rust comment, that's fine for Rust but produces broken C:

/// ```rust
/// let short_kid = IdCred::from_encoded_value(&hex!("17" /* 23 */)).unwrap();
/// ```

becomes

/**
 * ```rust
 * let short_kid = IdCred::from_encoded_value(&hex!("17" /* 23 */)).unwrap();
 * ```
 */

for which the GitHub syntax highlighter does a good job of highlighting (hah!) the problem.

It would be convenient if cbindgen 'defused' those somehow. A candidate is changing every /* to ⁄* which is a different but similar Unicode symbol, and which is not a pretty but a practical solution; another is changing the whole comment to C++ style comments (/// in this case to trigger doxygen). A very fancy fix would be to extract all inline comments and put them at the end of the line (there's probably a reason they're inline, but then again, what do without C nested comments). A minimal fix to the "it produces unexpected and broken code" would also be to err out from the translation step (not a full fix, but still an improvement).

I have no clear preference how to fix this – I'll work around this by moving the comments to end-of-line C++ style comments, but given this whole issue might confuse users or even be used in an underhand code project, I hope cbindgen could fix it.

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