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

Friendlier message when cxx::CxxString is used in a #[cxx::bridge]. #1414

Merged

Conversation

anforowicz
Copy link
Contributor

One gotcha that sometimes trips new users of cxx is that cxx::CxxString works outside of cxx::bridge, but not within.
This PR tries to improve this by providing a custom error message in this scenario.

Notes:

  • I think that any custom error message is a minor improvement over the status quo (with a generic "unsupported type" error message). Additional improvements may be possible, but it's probably okay to do them incrementally later, in separate PRs.
    • Feel free to tweak the error message as needed. I wasn't sure if it's okay to call cxx:: a "qualifier" but it seems okay (FWIW paths containing :: are called "qualified paths" in Rust reference).
    • Ideally the error message would also provide a hint (i.e. a fix suggestion) that enables automating removal of cxx::. Unfortunately, I wasn't able to figure out how to do it. It seems that syn::Error doesn't support fix hints. And it seems that compiler folks say that annotate_snippets may be one option, but adopting this in cxx seems like a potentially bigger work item?
  • FWIW an alternative fix here would be to accept both cxx::CxxString and CxxString. I think that having a single spelling is somewhat more desirable (for grepping, etc.), but I am open to implementing the alternative fix.

/cc @zetafunction, @adetaylor

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit 18689a1 into dtolnay:master Dec 17, 2024
16 checks passed
@anforowicz anforowicz deleted the cxx-qualifier-friendly-error-message branch December 18, 2024 02:02
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

Successfully merging this pull request may close these issues.

2 participants