rust-bindgen
rust-bindgen copied to clipboard
Wrap unsafe function's bodies in unsafe blocks
This PR adds a new option --unsafe-blocks which wraps all the bodies of generated unsafe functions in unsafe blocks.
Fixes: #2063 ~~Blocked by: #2265~~
:umbrella: The latest upstream changes (presumably 8b29355ca0ce54e941d398ef9a605e9b5c0f20ae) made this pull request unmergeable. Please resolve the merge conflicts.
:umbrella: The latest upstream changes (presumably 4b006da21bd7a6701c8e7f658085569830207c9c) made this pull request unmergeable. Please resolve the merge conflicts.
I implemented this because I thought you agreed to it :grimacing:
That being said, I think it is not unheard of bindgen having features that could be fixed by one liners or --raw-lines here and there.
cc @ojeda just because they requested the feature and might want to give their opinion
It is definitely not critical, but it allows a project to call the compiler with a global -Funsafe_op_in_unsafe_fn flag, for instance.
Moreover, considering that the language is evolving towards not implying unsafe blocks in unsafe fns (the current plan seems to be that Edition 2024 warns-by-default), it seems like a good idea to make bindgen ready to generate idiomatic code (and do so by default when targeting the future edition when that arrives).
I think it'd be good to move all these post-processing operations to their own file since putting it in lib.rs feels a bit odd and creates a lot of rightward drift. But that can be a follow-up I suppose.
@emilio check #2282
:umbrella: The latest upstream changes (presumably #2282) made this pull request unmergeable. Please resolve the merge conflicts.
@emilio you approved this PR but from your comments it is not clear to me that you want this actually merged.
:umbrella: The latest upstream changes (presumably #2284) made this pull request unmergeable. Please resolve the merge conflicts.
:umbrella: The latest upstream changes (presumably 9c32b460481903d90c6ac5df277bfa853a0558d8) made this pull request unmergeable. Please resolve the merge conflicts.
:umbrella: The latest upstream changes (presumably bae6170907dd27a1e854236e2cc7b4f637220977) made this pull request unmergeable. Please resolve the merge conflicts.
@pvdrz you've been on a roll recently! Thanks for pushing through so many tickets I've been subscribed to!
Unfortunately, this broke building with -Dwarnings on rustc < 1.65.
Unfortunately, this broke building with -Dwarnings on rustc < 1.65.
Do you have any reduced case so we can add it to the tests?
Any of the test files that were touched in e8ffb42ab66405ac56d04494a30e54b584f2d4dd shows the warning with rustc < 1.65.
https://github.com/rust-lang/rust-bindgen/pull/2354 should fix this