Skip to content

Add support for marking functions as safe - #3456

Open
DanielEScherzer wants to merge 1 commit into
rust-lang:mainfrom
DanielEScherzer:safe_fn_override
Open

Add support for marking functions as safe#3456
DanielEScherzer wants to merge 1 commit into
rust-lang:mainfrom
DanielEScherzer:safe_fn_override

Conversation

@DanielEScherzer

@DanielEScherzer DanielEScherzer commented Sep 6, 2026

Copy link
Copy Markdown

In the same way that Builder::allowlist_function() and the command line
--allowlist-function option permit marking some function as to-be-generated,
the new Builder::safe_function() method and --safe-functions option allow
marking functions as safe.

Fixes #3443

@emilio emilio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any strong reason you need the callback machinery?

I think something more akin to the allowlisted_functions set would be better (it would also make it work on the CLI trivially), wdyt?

View changes since this review

@DanielEScherzer

Copy link
Copy Markdown
Author

Is there any strong reason you need the callback machinery?

I think something more akin to the allowlisted_functions set would be better (it would also make it work on the CLI trivially), wdyt?

View changes since this review

I guess that works too, I'll rework this

@DanielEScherzer DanielEScherzer changed the title Add ParseCallbacks method to mark functions as safe Add support for marking functions as safe Sep 6, 2026
In the same way that `Builder::allowlist_function()` and the command line
`--allowlist-function` option permit marking some function as to-be-generated,
the new `Builder::safe_function()` method and `--safe-functions` option allow
marking functions as safe.

Fixes rust-lang#3443

@emilio emilio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me with the tweak below.

View changes since this review

Comment thread bindgen/ir/function.rs
})
});

let is_safe = context.options().safe_functions.matches(&name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't need to check it this early.

Comment thread bindgen/codegen/mod.rs
.unsafe_extern_blocks
.then(|| quote!(unsafe));

let mark_fn_safe = if self.is_safe() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we could do:

let mark_fn_safe = ctx.options().safe_functions.matches(ident).then(|| quote!(safe));

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.

Feature request: option to mark function as safe

2 participants