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

C style comments are produced unescaped #1033

Open
chrysn opened this issue Nov 25, 2024 · 0 comments
Open

C style comments are produced unescaped #1033

chrysn opened this issue Nov 25, 2024 · 0 comments

Comments

@chrysn
Copy link

chrysn commented Nov 25, 2024

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.

chrysn added a commit to chrysn-pull-requests/edhoc-rs that referenced this issue Nov 25, 2024
chrysn added a commit to chrysn-pull-requests/edhoc-rs that referenced this issue Nov 25, 2024
chrysn added a commit to chrysn-pull-requests/edhoc-rs that referenced this issue Nov 25, 2024
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

1 participant