Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate C-String literals c"example" instead of unsafe code #2996

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

nyurik
Copy link
Contributor

@nyurik nyurik commented Nov 28, 2024

When generate_cstr is enabled, and the target rust version is >= 1.77, generate c"..." literals instead of the unsafe from_bytes_with_nul_unchecked calls. Note that this requires 2021 edition, but since this is not on by default, and CStr support is relatively recent, i think it is ok to tie them together

Note that this also resolves the Clippy 1.83's manual_c_str_literals issue

Fixes #2994

@nyurik nyurik force-pushed the cstr-gen branch 5 times, most recently from 94480f7 to 195e222 Compare November 29, 2024 09:59
@nyurik nyurik mentioned this pull request Nov 29, 2024
When `generate_cstr` is enabled, and the target rust version is >= 1.77, generate `c"..."` literals instead of the unsafe `from_bytes_with_nul_unchecked` calls.
@nyurik nyurik changed the title Automatic support for C-String literals Generate C-String literals c"example" instead of unsafe code Nov 29, 2024
nyurik added a commit to nyurik/rust-bindgen that referenced this pull request Nov 29, 2024
While not used in this PR, this will allow different code generation depending on the language target, e.g. for rust-lang#2996

Introduce a new `--rust-edition` parameter with allowed values 2015, 2018, 2021, and 2024.
nyurik added a commit to nyurik/rust-bindgen that referenced this pull request Nov 29, 2024
While not used in this PR, this will allow different code generation depending on the language target, e.g. for rust-lang#2996

Introduce a new `--rust-edition` parameter with allowed values 2015, 2018, 2021, and 2024.
@emilio emilio added this pull request to the merge queue Nov 29, 2024
Merged via the queue into rust-lang:main with commit ee3efc8 Nov 29, 2024
28 checks passed
nyurik added a commit to nyurik/rust-bindgen that referenced this pull request Nov 29, 2024
While not used in this PR, this will allow different code generation depending on the language target, e.g. for rust-lang#2996

Introduce a new `--rust-edition` parameter with allowed values 2015, 2018, 2021, and 2024.
nyurik added a commit to nyurik/rust-bindgen that referenced this pull request Nov 29, 2024
While not used in this PR, this will allow different code generation depending on the language target, e.g. for rust-lang#2996

Introduce a new `--rust-edition` parameter with allowed values 2015, 2018, 2021, and 2024.
nyurik added a commit to nyurik/rust-bindgen that referenced this pull request Nov 29, 2024
While not used in this PR, this will allow different code generation depending on the language target, e.g. for rust-lang#2996

Introduce a new `--rust-edition` parameter with allowed values 2015, 2018, 2021, and 2024.
@nyurik nyurik deleted the cstr-gen branch November 29, 2024 18:14
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.

Handle the new clippy::manual_c_str_literals lint
2 participants