rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Wrap unsafe function's bodies in unsafe blocks

Open pvdrz opened this issue 3 years ago • 1 comments

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~~

pvdrz avatar Sep 06 '22 21:09 pvdrz

:umbrella: The latest upstream changes (presumably 8b29355ca0ce54e941d398ef9a605e9b5c0f20ae) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Sep 10 '22 01:09 bors-servo

:umbrella: The latest upstream changes (presumably 4b006da21bd7a6701c8e7f658085569830207c9c) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Sep 23 '22 07:09 bors-servo

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

pvdrz avatar Sep 23 '22 17:09 pvdrz

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).

ojeda avatar Sep 23 '22 20:09 ojeda

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

pvdrz avatar Sep 23 '22 20:09 pvdrz

:umbrella: The latest upstream changes (presumably #2282) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Sep 27 '22 19:09 bors-servo

@emilio you approved this PR but from your comments it is not clear to me that you want this actually merged.

pvdrz avatar Oct 04 '22 21:10 pvdrz

:umbrella: The latest upstream changes (presumably #2284) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Oct 05 '22 01:10 bors-servo

:umbrella: The latest upstream changes (presumably 9c32b460481903d90c6ac5df277bfa853a0558d8) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Nov 02 '22 20:11 bors-servo

:umbrella: The latest upstream changes (presumably bae6170907dd27a1e854236e2cc7b4f637220977) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Nov 04 '22 18:11 bors-servo

@pvdrz you've been on a roll recently! Thanks for pushing through so many tickets I've been subscribed to!

lopopolo avatar Nov 04 '22 22:11 lopopolo

Unfortunately, this broke building with -Dwarnings on rustc < 1.65.

glandium avatar Nov 17 '22 05:11 glandium

Unfortunately, this broke building with -Dwarnings on rustc < 1.65.

Do you have any reduced case so we can add it to the tests?

pvdrz avatar Nov 17 '22 14:11 pvdrz

Any of the test files that were touched in e8ffb42ab66405ac56d04494a30e54b584f2d4dd shows the warning with rustc < 1.65.

glandium avatar Nov 17 '22 20:11 glandium

https://github.com/rust-lang/rust-bindgen/pull/2354 should fix this

pvdrz avatar Nov 18 '22 15:11 pvdrz