Fix unsafe_op_in_unsafe_fn warning for unsafe operations in generated module #1473
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix unsafe_op_in_unsafe_fn warning for unsafe operations in generated module
This PR adds #[allow(unsafe_op_in_unsafe_fn)] attributes to autocxx-generated unsafe functions to suppress warnings that would appear when using Rust 2024 edition.
Background
Rust 2024 edition introduces the stabilized unsafe_op_in_unsafe_fn lint (Edition Guide), which requires unsafe operations inside unsafe functions to be explicitly wrapped in unsafe blocks.
While this is a valuable safety improvement for hand-written code (as described in RFC #2585), it creates unnecessary noise for generated FFI bindings like those produced by autocxx.
Example of warnings
Without this fix, code generated by autocxx produces warnings like:
Changes
This PR modifies the code generation templates to add the #[allow(unsafe_op_in_unsafe_fn)] attribute to generated unsafe functions. I think this is appropriate because: