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

Support `unsafe_op_in_unsafe_fn`

Open ojeda opened this issue 4 years ago • 3 comments

Projects wishing to use unsafe_op_in_unsafe_fn can allow the warning when importing the bindings.

However, it would be ideal if bindgen would offer a way (e.g. command-line flag) to generate bindings with unsafe blocks inside unsafe fns as needed.

That way, projects can forbid it globally, and those that just deny it do not need to write the allow themselves.

ojeda avatar Jun 03 '21 23:06 ojeda

Seems pretty reasonable.

emilio avatar Jun 06 '21 12:06 emilio

I think that this could be a good feature but if bindgen able to yield safe fns where it's just wrapping unsafe { ... }, we should consider adding granular support. This could be some kind of metadata file that's got key's of name of the functions and values of dictionary with Unsafe: Y/N and Mutating: Y/N.

As discussed over in https://github.com/madsmtm/objc2/issues/85#issuecomment-1236222148, it'd be somewhat similar to Swift's apinotes.

Anyway, should I write an issue describing this?

simlay avatar Sep 09 '22 23:09 simlay

Anyway, should I write an issue describing this?

I think this would be better because as far as I understand this issue only is about wrapping bodies of unsafe functions in unsafe blocks so the unsafe_op_in_unsafe_fn warning won't trigger if it's enabled. This doesn't affect in any way safe functions with unsafe blocks inside.

pvdrz avatar Sep 10 '22 01:09 pvdrz

Thanks for this @pvdrz!

ojeda avatar Nov 05 '22 02:11 ojeda